Class SystemDateTimeService
- Namespace
- NuvTools.Common.Dates
- Assembly
- NuvTools.Common.dll
Default IDateTimeService: the clock comes from a TimeProvider (System unless one is given) and the zone from a TimeZoneRegion.
public class SystemDateTimeService : IDateTimeService
- Inheritance
-
SystemDateTimeService
- Implements
- Inherited Members
- Extension Methods
Constructors
SystemDateTimeService(TimeZoneRegion)
Uses the system clock.
public SystemDateTimeService(TimeZoneRegion region = TimeZoneRegion.Brasilia)
Parameters
regionTimeZoneRegion
SystemDateTimeService(TimeZoneRegion, TimeProvider)
Uses the given clock, e.g. a FakeTimeProvider in a test.
public SystemDateTimeService(TimeZoneRegion region, TimeProvider timeProvider)
Parameters
regionTimeZoneRegiontimeProviderTimeProvider
Properties
Now
The current wall-clock time in the configured region.
public DateTime Now { get; }
Property Value
NowOffset
The current instant with the region's offset (e.g. -03:00 in Brasília).
public DateTimeOffset NowOffset { get; }
Property Value
Region
The configured region.
public TimeZoneRegion Region { get; }
Property Value
TimeZone
The configured region's time zone.
public TimeZoneInfo TimeZone { get; }
Property Value
Today
Today's date in the configured region. A server usually runs in UTC, where after 21:00 in Brasília the date is already tomorrow; read calendar dates ("overdue", "not in the future") against this one.
public DateOnly Today { get; }
Property Value
UtcNow
The current instant as a UTC DateTime.
public DateTime UtcNow { get; }
Property Value
UtcNowOffset
The current instant at +00:00.
public DateTimeOffset UtcNowOffset { get; }
Property Value
Methods
ConvertFromUtc(DateTime)
Converts a UTC DateTime to the region's wall-clock time.
public DateTime ConvertFromUtc(DateTime utcDateTime)
Parameters
utcDateTimeDateTime
Returns
ConvertFromUtc(DateTimeOffset)
Returns the same instant with the region's offset.
public DateTimeOffset ConvertFromUtc(DateTimeOffset utcDateTime)
Parameters
utcDateTimeDateTimeOffset
Returns
ConvertToUtc(DateTime)
Converts the region's wall-clock time to a UTC DateTime.
public DateTime ConvertToUtc(DateTime localDateTime)
Parameters
localDateTimeDateTime
Returns
ConvertToUtc(DateTimeOffset)
Returns the same instant at +00:00.
public DateTimeOffset ConvertToUtc(DateTimeOffset localDateTime)
Parameters
localDateTimeDateTimeOffset