Table of Contents

Interface IDateTimeService

Namespace
NuvTools.Common.Dates
Assembly
NuvTools.Common.dll

The current time and a configured time zone (Region), for code that needs the time people live by: "today" for a due date, a time printed on a document. The clock itself comes from a TimeProvider, so a test can drive it with a fake one.

public interface IDateTimeService
Extension Methods

Remarks

Instants (UtcNowOffset, NowOffset, the DateTimeOffset conversions) carry their offset and compare correctly whatever zone they are shown in. Wall-clock values (Now, the DateTime conversions) are the time on a clock in the region, with no offset. Store instants in UTC.

Properties

Now

The current wall-clock time in the configured region.

DateTime Now { get; }

Property Value

DateTime

NowOffset

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

DateTimeOffset NowOffset { get; }

Property Value

DateTimeOffset

Region

The configured region.

TimeZoneRegion Region { get; }

Property Value

TimeZoneRegion

TimeZone

The configured region's time zone.

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.

DateOnly Today { get; }

Property Value

DateOnly

UtcNow

The current instant as a UTC DateTime.

DateTime UtcNow { get; }

Property Value

DateTime

UtcNowOffset

The current instant at +00:00.

DateTimeOffset UtcNowOffset { get; }

Property Value

DateTimeOffset

Methods

ConvertFromUtc(DateTime)

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

DateTime ConvertFromUtc(DateTime utcDateTime)

Parameters

utcDateTime DateTime

Returns

DateTime

ConvertFromUtc(DateTimeOffset)

Returns the same instant with the region's offset.

DateTimeOffset ConvertFromUtc(DateTimeOffset utcDateTime)

Parameters

utcDateTime DateTimeOffset

Returns

DateTimeOffset

ConvertToUtc(DateTime)

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

DateTime ConvertToUtc(DateTime localDateTime)

Parameters

localDateTime DateTime

Returns

DateTime

ConvertToUtc(DateTimeOffset)

Returns the same instant at +00:00.

DateTimeOffset ConvertToUtc(DateTimeOffset localDateTime)

Parameters

localDateTime DateTimeOffset

Returns

DateTimeOffset