Table of Contents

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

region TimeZoneRegion

SystemDateTimeService(TimeZoneRegion, TimeProvider)

Uses the given clock, e.g. a FakeTimeProvider in a test.

public SystemDateTimeService(TimeZoneRegion region, TimeProvider timeProvider)

Parameters

region TimeZoneRegion
timeProvider TimeProvider

Properties

Now

The current wall-clock time in the configured region.

public DateTime Now { get; }

Property Value

DateTime

NowOffset

The current instant with the region's offset (e.g. -03:00 in Brasília).

public DateTimeOffset NowOffset { get; }

Property Value

DateTimeOffset

Region

The configured region.

public TimeZoneRegion Region { get; }

Property Value

TimeZoneRegion

TimeZone

The configured region's time zone.

public TimeZoneInfo TimeZone { get; }

Property Value

TimeZoneInfo

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

DateOnly

UtcNow

The current instant as a UTC DateTime.

public DateTime UtcNow { get; }

Property Value

DateTime

UtcNowOffset

The current instant at +00:00.

public DateTimeOffset UtcNowOffset { get; }

Property Value

DateTimeOffset

Methods

ConvertFromUtc(DateTime)

Converts a UTC DateTime to the region's wall-clock time.

public DateTime ConvertFromUtc(DateTime utcDateTime)

Parameters

utcDateTime DateTime

Returns

DateTime

ConvertFromUtc(DateTimeOffset)

Returns the same instant with the region's offset.

public DateTimeOffset ConvertFromUtc(DateTimeOffset utcDateTime)

Parameters

utcDateTime DateTimeOffset

Returns

DateTimeOffset

ConvertToUtc(DateTime)

Converts the region's wall-clock time to a UTC DateTime.

public DateTime ConvertToUtc(DateTime localDateTime)

Parameters

localDateTime DateTime

Returns

DateTime

ConvertToUtc(DateTimeOffset)

Returns the same instant at +00:00.

public DateTimeOffset ConvertToUtc(DateTimeOffset localDateTime)

Parameters

localDateTime DateTimeOffset

Returns

DateTimeOffset