Couchbase .NET SDK __CB_SDK_VERSION__

Show / Hide Table of Contents

Class TimeSpanExtensions

Inheritance
object
TimeSpanExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: Couchbase.Utils
Assembly: Couchbase.NetClient.dll
Syntax
public static class TimeSpanExtensions

Methods

View Source

GetSeconds(TimeSpan)

Retrieves the number of seconds expressed in a TimeSpan as an uint.

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

  • View Source
In this article
Back to top Copyright © 2020 Couchbase, Inc. All rights reserved.