Class ZonedClockExtensions
- Namespace
- LfrlAnvil.Chrono.Extensions
- Assembly
- LfrlAnvil.Chrono.dll
Contains IZonedClock extension methods.
public static class ZonedClockExtensions
- Inheritance
-
ZonedClockExtensions
- Inherited Members
Methods
Create(IZonedClock, DateTime)
Creates a new ZonedDateTime instance from the provided dateTime
and with the time zone of the given clock
.
[Pure]
public static ZonedDateTime Create(this IZonedClock clock, DateTime dateTime)
Parameters
clock
IZonedClockSource clock.
dateTime
DateTimeDate time value.
Returns
- ZonedDateTime
New ZonedDateTime instance.
Exceptions
- InvalidZonedDateTimeException
When
dateTime
is not a valid date time in the clock's time zone.
Freeze(IZonedClock)
Creates a new frozen IZonedClock instance from the given clock
,
using its current ZonedDateTime.
[Pure]
public static IZonedClock Freeze(this IZonedClock clock)
Parameters
clock
IZonedClockSource clock.
Returns
- IZonedClock
New frozen IZonedClock instance.
GetDurationOffset(IZonedClock, IZonedClock)
Calculates an offset between current ZonedDateTime instances of two clocks.
[Pure]
public static Duration GetDurationOffset(this IZonedClock clock, IZonedClock other)
Parameters
clock
IZonedClockSource clock.
other
IZonedClockOther clock to check.
Returns
GetDurationOffset(IZonedClock, ZonedDateTime)
Calculates an offset between the provided dateTime
and the current ZonedDateTime of the given clock
.
[Pure]
public static Duration GetDurationOffset(this IZonedClock clock, ZonedDateTime dateTime)
Parameters
clock
IZonedClockSource clock.
dateTime
ZonedDateTimeDate time to check.
Returns
IsFrozen(IZonedClock)
Checks whether or not the given clock
is frozen.
[Pure]
public static bool IsFrozen(this IZonedClock clock)
Parameters
clock
IZonedClockClock to check.
Returns
- bool
true when
clock
is frozen, otherwise false.
IsInFuture(IZonedClock, ZonedDateTime)
Checks whether or not the provided dateTime
is in the future
relative to the given clock
.
[Pure]
public static bool IsInFuture(this IZonedClock clock, ZonedDateTime dateTime)
Parameters
clock
IZonedClockSource clock.
dateTime
ZonedDateTimeDate time to check.
Returns
- bool
true when
dateTime
is in the future, otherwise false.
IsInPast(IZonedClock, ZonedDateTime)
Checks whether or not the provided dateTime
is in the past
relative to the given clock
.
[Pure]
public static bool IsInPast(this IZonedClock clock, ZonedDateTime dateTime)
Parameters
clock
IZonedClockSource clock.
dateTime
ZonedDateTimeDate time to check.
Returns
- bool
true when
dateTime
is in the past, otherwise false.
IsNow(IZonedClock, ZonedDateTime)
Checks whether or not the provided dateTime
is in the present
relative to the given clock
.
[Pure]
public static bool IsNow(this IZonedClock clock, ZonedDateTime dateTime)
Parameters
clock
IZonedClockSource clock.
dateTime
ZonedDateTimeDate time to check.
Returns
- bool
true when
dateTime
is in the present, otherwise false.
TryCreate(IZonedClock, DateTime)
Attempts to create a new ZonedDateTime instance from the provided dateTime
and with the time zone of the given clock
.
[Pure]
public static ZonedDateTime? TryCreate(this IZonedClock clock, DateTime dateTime)
Parameters
clock
IZonedClockSource clock.
dateTime
DateTimeDate time value.
Returns
- ZonedDateTime?
New ZonedDateTime instance or null when
dateTime
is not a valid date time in the clock's time zone.