Table of Contents

Class TimeZoneContext

Namespace
Arc4u
Assembly
Arc4u.dll

Converts dates between UTC and the time zone of the application, which is defined by TimeZone in the ApplicationConfig. When the time zone is not configured or cannot be found, the time zone of the machine is used. The most recently created instance is available through Current.

[Export]
[Shared]
public class TimeZoneContext
Inheritance
TimeZoneContext
Inherited Members

Constructors

TimeZoneContext(IOptionsMonitor<ApplicationConfig>, ILogger<TimeZoneContext>)

Initializes a new instance of the TimeZoneContext class and makes it the Current context.

public TimeZoneContext(IOptionsMonitor<ApplicationConfig> config, ILogger<TimeZoneContext> logger)

Parameters

config IOptionsMonitor<ApplicationConfig>

The application configuration that defines the time zone.

logger ILogger<TimeZoneContext>

The logger used to trace the time zone selection and errors.

Properties

Current

Gets the most recently created TimeZoneContext.

public static TimeZoneContext Current { get; }

Property Value

TimeZoneContext

Exceptions

InvalidOperationException

No TimeZoneContext has been created yet.

TimeZoneInfo

Gets the time zone used by the context.

public TimeZoneInfo TimeZoneInfo { get; }

Property Value

TimeZoneInfo

Methods

ConvertFromUtc(DateTime)

Converts a UTC date to the time zone of the context.

public DateTime ConvertFromUtc(DateTime value)

Parameters

value DateTime

The date, whose Kind must be Utc.

Returns

DateTime

The date in the time zone of the context, with a Kind of Local.

Exceptions

InvalidTimeZoneException

value is not a UTC date.

ConvertToUtc(DateTime)

Converts a date expressed in the time zone of the context to UTC.

public DateTime ConvertToUtc(DateTime value)

Parameters

value DateTime

The date. A date of kind Utc is returned unchanged; otherwise it is considered to be in the time zone of the context.

Returns

DateTime

The UTC date.

GetDaylightChanges(int)

Gets the start and end of the daylight saving time of the time zone for a year.

public DaylightTime? GetDaylightChanges(int inYear)

Parameters

inYear int

The year.

Returns

DaylightTime

The daylight saving period, or null when the time zone has no adjustment rule for that year.

GetWeekNumber(DateTime)

Gets the week number of a date, using the calendar week rule and the first day of the week of the current culture.

public static int GetWeekNumber(DateTime date)

Parameters

date DateTime

The date.

Returns

int

The week number in the year.