C#C
C#3y ago
SWEETPONY

✅ How to sum datetimeoffset and timespan?

I have following structure:
[JsonProperty( PropertyName = "timestamp" )]    
[JsonRequired]                                  
public DateTimeOffset Timestamp { get; set; }   
                                                
[JsonProperty( PropertyName = "ttl" )]          
public TimeSpan? Ttl { get; set; }              
                                                
[JsonProperty( PropertyName = "expires_at" )]   
public DateTime ExpiresAt { get; set; }         

I would like to get expiration time by sum timestamp and ttl

I tried this:
[JsonProperty( PropertyName = "expires_at" )]
    public DateTime ExpiresAt => Ttl.HasValue
        ? DateTime.Now.Add( Ttl.Value )
        : DateTime.MaxValue;

but it's not correct
Was this page helpful?