std.datetime.timezone

Types 6

Represents a time zone. It is used with SysTime to indicate the time zone of a SysTime.

Fields
string _name
string _stdName
string _dstName
Methods
string name() @property @safe const nothrowThe name of the time zone. Exactly how the time zone name is formatted depends on the derived class. In the case of PosixTimeZone, it's the TZ Database name, whereas with WindowsTimeZone, it's the ...
string stdName() @property @safe const scope nothrowTypically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is not in effect (e.g. PST). It is not necessarily unique.
string dstName() @property @safe const scope nothrowTypically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is in effect (e.g. PDT). It is not necessarily unique.
bool hasDST() @property @safe const nothrow;Whether this time zone has Daylight Savings Time at any point in time. Note that for some time zone types it may not have DST for current dates but will still return true for `hasDST` because the t...
bool dstInEffect(long stdTime) @safe const scope nothrow;Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and returns whether DST is effect in this time zone at the given point in time.
long utcToTZ(long stdTime) @safe const scope nothrow;Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and converts it to this time zone's time.
long tzToUTC(long adjTime) @safe const scope nothrow;Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in this time zone's time and converts it to UTC (i.e. std time).
Duration utcOffsetAt(long stdTime) @safe const scope nothrowReturns what the offset from UTC is at the given std time. It includes the DST offset in effect at that time (if any).
private string _getOldName(string windowsTZName) @safe pure nothrow
Constructors
this(string name, string stdName, string dstName)Params: name = The name of the time zone. stdName = The abbreviation for the time zone during std time. dstName = The abbreviation for the time zone during DST.

A TimeZone which represents the current local time zone on the system running your program.

This uses the underlying C calls to adjust the time rather than using specific D code based off of system settings to calculate the time such as

PosixTimeZone and WindowsTimeZone do. That also means that

it will use whatever the current time zone is on the system, even if the system's time zone changes while the program is running.

Methods
immutable(LocalTime) opCall() @trusted pure nothrowLocalTime is a singleton class. LocalTime returns its only instance.
string stdName() @property @trusted const scope nothrowTypically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is not in effect (e.g. PST). It is not necessarily unique.
string dstName() @property @trusted const scope nothrowTypically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is in effect (e.g. PDT). It is not necessarily unique.
bool hasDST() @property @trusted const nothrowWhether this time zone has Daylight Savings Time at any point in time. Note that for some time zone types it may not have DST for current dates but will still return true for `hasDST` because the t...
bool dstInEffect(long stdTime) @trusted const scope nothrowTakes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and returns whether DST is in effect in this time zone at the given point in time.
long utcToTZ(long stdTime) @trusted const scope nothrowReturns hnsecs in the local time zone using the standard C function calls on Posix systems and the standard Windows system calls on Windows systems to adjust the time to the appropriate time zone f...
long tzToUTC(long adjTime) @trusted const scope nothrowReturns std time using the standard C function calls on Posix systems and the standard Windows system calls on Windows systems to adjust the time to UTC from the appropriate time zone.
immutable(LocalTime) singleton() @trusted
Constructors
classUTC : TimeZone

A TimeZone which represents UTC.

Fields
UTC _utc
Methods
immutable(UTC) opCall() @safe pure nothrow`UTC` is a singleton class. `UTC` returns its only instance.
bool hasDST() @property @safe const nothrowAlways returns false.
bool dstInEffect(long stdTime) @safe const scope nothrowAlways returns false.
long utcToTZ(long stdTime) @safe const scope nothrowReturns the given hnsecs without changing them at all.
long tzToUTC(long adjTime) @safe const scope nothrowReturns the given hnsecs without changing them at all.
Duration utcOffsetAt(long stdTime) @safe const scope nothrowReturns a Duration of 0.
Constructors

Represents a time zone with an offset (in minutes, west is negative) from UTC but no DST.

It's primarily used as the time zone in the result of

SysTime's fromISOString,

fromISOExtString, and fromSimpleString.

name and dstName are always the empty string since this time zone has no DST, and while it may be meant to represent a time zone which is in the TZ Database, obviously it's not likely to be following the exact rules of any of the time zones in the TZ Database, so it makes no sense to set it.

Fields
Duration _utcOffset
Methods
bool hasDST() @property @safe const nothrowAlways returns false.
bool dstInEffect(long stdTime) @safe const scope nothrowAlways returns false.
long utcToTZ(long stdTime) @safe const scope nothrowTakes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and converts it to this time zone's time.
long tzToUTC(long adjTime) @safe const scope nothrowTakes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in this time zone's time and converts it to UTC (i.e. std time).
Duration utcOffsetAt(long stdTime) @safe const scope nothrowReturns utcOffset as a Duration.
Duration utcOffset() @property @safe const pure nothrowThe amount of time the offset from UTC is (negative is west of UTC, positive is east).
string toISOString(Duration utcOffset) @safe pure
void toISOString(W)(ref W writer, Duration utcOffset) if (isOutputRange!(W, char))
string toISOExtString(Duration utcOffset) @safe pure
void toISOExtString(W)(ref W writer, Duration utcOffset)
immutable(SimpleTimeZone) fromISOString(S)(S isoString) if (isSomeString!S) @safe pure
immutable(SimpleTimeZone) fromISOExtString(S)(scope S isoExtString) if (isSomeString!S) @safe pure
Constructors
this(Duration utcOffset, string stdName = "")Params: utcOffset = This time zone's offset from UTC with west of UTC being negative (it is added to UTC to get the adjusted time). stdName = The `stdName` for this time zone.

Represents a time zone from a TZ Database time zone file. Files from the TZ Database are how Posix systems hold their time zone information. Unfortunately, Windows does not use the TZ Database. To use the TZ Database, use PosixTimeZone (which reads its information from the TZ Database files on disk) on Windows by providing the TZ Database files and telling PosixTimeZone.getTimeZone where the directory holding them is.

To get a PosixTimeZone, call PosixTimeZone.getTimeZone (which allows specifying the location the time zone files).

Note

Unless your system's local time zone deals with leap seconds (which is

highly unlikely), then the only way to get a time zone which takes leap seconds into account is to use PosixTimeZone with a time zone whose name starts with "right/". Those time zone files do include leap seconds, and PosixTimeZone will take them into account (though posix systems which use a "right/" time zone as their local time zone will not take leap seconds into account even though they're in the file).

See Also

Fields
Transition[] _transitions
LeapSecond[] _leapSeconds
bool _hasDST
Methods
bool hasDST() @property @safe const nothrowWhether this time zone has Daylight Savings Time at any point in time. Note that for some time zone types it may not have DST for current dates but will still return true for `hasDST` because the t...
bool dstInEffect(long stdTime) @safe const scope nothrowTakes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and returns whether DST is in effect in this time zone at the given point in time.
long utcToTZ(long stdTime) @safe const scope nothrowTakes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and converts it to this time zone's time.
long tzToUTC(long adjTime) @safe const scope nothrowTakes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in this time zone's time and converts it to UTC (i.e. std time).
private string getDefaultTZDatabaseDir()
immutable(PosixTimeZone) getTimeZone(string name, string tzDatabaseDir = getDefaultTZDatabaseDir()) @trustedReturns a TimeZone with the give name per the TZ Database. The time zone information is fetched from the TZ Database time zone files in the given directory.
string[] getInstalledTZNames(string subName = "", string tzDatabaseDir = getDefaultTZDatabaseDir()) @safeReturns a list of the names of the time zones installed on the system.
T readVal(T)(ref File tzFile) if ((isIntegral!T || isSomeChar!T) || is(immutable T == immutable bool)) @trusted
T readVal(T)(ref File tzFile, size_t length) if (isArray!T) @trusted
T readVal(T)(ref File tzFile) if (is(T == TempTTInfo)) @safe
void _enforceValidTZFile(bool result, size_t line = __LINE__) @safe pure
int calculateLeapSeconds(long stdTime) @safe const scope pure nothrow
Constructors
this(immutable Transition[] transitions, immutable LeapSecond[] leapSeconds, string name, string stdName, string dstName, bool hasDST)
Nested Templates
Transition
LeapSecond
TTInfo
TempTTInfo
TempTransition
TransitionType

Provides the conversions between the IANA time zone database time zone names (which POSIX systems use) and the time zone names that Windows uses.

Windows uses a different set of time zone names than the IANA time zone database does, and how they correspond to one another changes over time (particularly when Microsoft updates Windows).

windowsZones.xml

provides the current conversions (which may or may not match up with what's on a particular Windows box depending on how up-to-date it is), and parseTZConversions reads in those conversions from windowsZones.xml so that a D program can use those conversions.

However, it should be noted that the time zone information on Windows is frequently less accurate than that in the IANA time zone database, and if someone really wants accurate time zone information, they should use the IANA time zone database files with PosixTimeZone on Windows rather than WindowsTimeZone, whereas WindowsTimeZone makes more sense when trying to match what Windows will think the time is in a specific time zone.

Also, the IANA time zone database has a lot more time zones than Windows does.

Parameters

windowsZonesXMLTextThe text from windowsZones.xml

Throws

Exception if there is an error while parsing the given XML.

-------------------- // Parse the conversions from a local file. auto text = std.file.readText("path/to/windowsZones.xml"); auto conversions = parseTZConversions(text);

// Alternatively, grab the XML file from the web at runtime // and parse it so that it's guaranteed to be up-to-date, though // that has the downside that the code needs to worry about the // site being down or unicode.org changing the URL. auto url = "https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml"; auto conversions2 = parseTZConversions(std.net.curl.get(url)); --------------------

Fields
string[][string] toWindowsThe key is the Windows time zone name, and the value is a list of IANA TZ database names which are close (currently only ever one, but it allows for multiple in case it's ever necessary).
string[][string] fromWindowsThe key is the IANA time zone database name, and the value is a list of Windows time zone names which are close (usually only one, but it could be multiple).

Functions 1

fnTZConversions parseTZConversions(string windowsZonesXMLText) @safe pureditto