std.datetime.timezone
License
Types 6
string _namestring _stdNamestring _dstNamestring 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).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 thatit will use whatever the current time zone is on the system, even if the system's time zone changes while the program is running.
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.this()A TimeZone which represents UTC.
UTC _utcimmutable(UTC) opCall() @safe pure nothrow`UTC` is a singleton class. `UTC` returns its only instance.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.this()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.
Duration _utcOffsetlong 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 utcOffset() @property @safe const pure nothrowThe amount of time the offset from UTC is (negative is west of UTC, positive is east).void toISOString(W)(ref W writer, Duration utcOffset) if (isOutputRange!(W, char))void toISOExtString(W)(ref W writer, Duration utcOffset)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
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
Transition[] _transitionsLeapSecond[] _leapSecondsbool _hasDSTbool 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).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.this(immutable Transition[] transitions,
immutable LeapSecond[] leapSeconds,
string name,
string stdName,
string dstName,
bool hasDST)TransitionLeapSecondTTInfoTempTTInfoTempTransitionTransitionTypeProvides 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.xmlprovides 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
windowsZonesXMLText | The text from windowsZones.xml |
Throws
-------------------- // 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)); --------------------
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).