Class TimeSpanExtensions
Inherited Members
Namespace: Couchbase.Utils
Assembly: Couchbase.NetClient.dll
Syntax
public static class TimeSpanExtensions
Methods
| Edit this page View SourceGetSeconds(TimeSpan)
Declaration
public static uint GetSeconds(this TimeSpan timeSpan)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeSpan | The timespan. |
Returns
| Type | Description |
|---|---|
| uint | An uint that is the total number of seconds in the TimeSpan. |
RemainingTtl(DateTimeOffset)
Converts an absolute expiry DateTimeOffset back to the remaining TimeSpan relative to now. Returns a minimum of 1 second to avoid passing 0 to the server, which would mean "never expire".
Declaration
public static TimeSpan RemainingTtl(this DateTimeOffset absoluteExpiry)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | absoluteExpiry | The absolute expiry time. |
Returns
| Type | Description |
|---|---|
| TimeSpan | The remaining TTL as a TimeSpan, minimum 1 second. |
ToEpochTtl(TimeSpan)
Converts a relative TimeSpan duration to an absolute DateTimeOffset representing when the TTL should expire. Used by transactions to capture the expiry time at staging, so the TTL clock starts from staging rather than unstaging.
Declaration
public static DateTimeOffset ToEpochTtl(this TimeSpan duration)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | duration | The relative TTL duration. |
Returns
| Type | Description |
|---|---|
| DateTimeOffset | An absolute DateTimeOffset representing the expiry time. |
ToTtl(TimeSpan)
Converts a TimeSpan into an uint correctly representing a Time-To-Live, that is expressed in seconds. Durations strictly bigger than 30 days are converted to a unix-syle timestamp (seconds since the Epoch), as described in the couchbase TTL documentation.
Declaration
public static uint ToTtl(this TimeSpan duration)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | duration |
Returns
| Type | Description |
|---|---|
| uint | The TTL, expressed as a suitable uint. |
ToTtl(uint)
Converts a duration expressed as milliseconds to a unix-based TTL.
Declaration
public static uint ToTtl(this uint duration)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | duration | Milliseconds to use as TTL. |
Returns
| Type | Description |
|---|---|
| uint | The TTL, expressed as a unix-based TTL in milliseconds. |