Method FromExpirationTime
FromExpirationTime(DateTime, Nullable<DateTime>, Nullable<TTLTimeUnit>)
Constructs TTL from absolute expiration time given reference time
from which to measure record expiration.
Declaration
public static TimeToLive FromExpirationTime(DateTime expirationTime, Nullable<DateTime> referenceTime = null, Nullable<TTLTimeUnit> timeUnit = null)
Parameters
Type | Name | Description |
---|---|---|
DateTime | expirationTime | Expiration time. Must be greater
than referenceTime . |
Nullable<DateTime> | referenceTime | (Optional) Reference time. Defaults to UtcNow. |
Nullable<TTLTimeUnit> | timeUnit | (Optional) Specifies TimeUnit of the resulting TTL. If not specified, the time unit is determined as described. |
Returns
Type | Description |
---|---|
TimeToLive | TTL computed according to the description. |
Remarks
The TTL is computed as follows depending on whether
timeUnit
parameter is specified:
timeUnit
is specified, expiration time is
rounded up to the nearest day or hour boundary depending on the
value of timeUnit
. Then the duration is
computed as the difference between the adjusted expiration time
and the reference time and is rounded up to the nearest day or
hour boundary depending on the value of
timeUnit
. TTL with the resulting number of
days or hours and specified timeUnit
is
returned.
timeUnit
is not specified, expiration time
is rounded up to the nearest hour boundary. If the adjusted
expiration time indicates midnight in UTC time zone, the returned
TTL will be in days, otherwise it will be in hours. Then the
duration is computed as the difference between the adjusted
expiration time and the reference time and is rounded up to the
nearest day or hour boundary as determined above. TTL with the
resulting number of days or hours and the time unit as determined
above is returned.
If the reference time is not specified, it defaults to current time in UTC (UtcNow). The expiration time specified must be later than the reference time.
If not in UTC already, expirationTime
and
referenceTime
(if specified) are converted to
UTC via ToUniversalTime() before computing
the returned TTL (this also means that both
Unspecified and
Local will be treated as local time
and the conversion would be performed).
Exceptions
Type | Condition |
---|---|
ArgumentException | If timeUnit
has invalid value. |
ArgumentOutOfRangeException | If
expirationTime is less then or equal
referenceTime (or current UTC time if
referenceTime is not specified). |