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
NowOffset
The current instant with the region's offset (e.g. -03:00 in Brasília).
DateTimeOffset NowOffset { get; }
Property Value
Region
The configured region.
TimeZoneRegion Region { get; }
Property Value
TimeZone
The configured region's time zone.
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.
DateOnly Today { get; }
Property Value
UtcNow
The current instant as a UTC DateTime.
DateTime UtcNow { get; }
Property Value
UtcNowOffset
The current instant at +00:00.
DateTimeOffset UtcNowOffset { get; }
Property Value
Methods
ConvertFromUtc(DateTime)
Converts a UTC DateTime to the region's wall-clock time.
DateTime ConvertFromUtc(DateTime utcDateTime)
Parameters
utcDateTimeDateTime
Returns
ConvertFromUtc(DateTimeOffset)
Returns the same instant with the region's offset.
DateTimeOffset ConvertFromUtc(DateTimeOffset utcDateTime)
Parameters
utcDateTimeDateTimeOffset
Returns
ConvertToUtc(DateTime)
Converts the region's wall-clock time to a UTC DateTime.
DateTime ConvertToUtc(DateTime localDateTime)
Parameters
localDateTimeDateTime
Returns
ConvertToUtc(DateTimeOffset)
Returns the same instant at +00:00.
DateTimeOffset ConvertToUtc(DateTimeOffset localDateTime)
Parameters
localDateTimeDateTimeOffset