Category | Functions |
---|---|
Time zones | TimeZone UTC LocalTime PosixTimeZone WindowsTimeZone SimpleTimeZone |
Utilities | clearTZEnvVar parseTZConversions setTZEnvVar TZConversions |
Represents a time zone. It is used with std.datetime.systime.SysTime
to indicate the time zone of a std.datetime.systime.SysTime
.
The 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 name that Windows chose to give the registry key for that time zone (typically the name that they give stdTime
if the OS is in English). For other time zone types, what it is depends on how they're implemented.
Typically, 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.
However, on Windows, it may be the unabbreviated name (e.g. Pacific Standard Time). Regardless, it is not the same as name.
Typically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is in effect (e.g. PDT). It is not necessarily unique.
However, on Windows, it may be the unabbreviated name (e.g. Pacific Daylight Time). Regardless, it is not the same as name.
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 time zone did at some point have DST.
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 stdTime
| The UTC time that needs to be checked for DST in this time zone. |
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 stdTime
| The UTC time that needs to be adjusted to this time zone's time. |
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).
long adjTime
| The time in this time zone that needs to be adjusted to UTC time. |
Returns what the offset from UTC is at the given std time. It includes the DST offset in effect at that time (if any).
long stdTime
| The UTC time for which to get the offset from UTC for this time zone. |
string name
| The name of the time zone. |
string stdName
| The abbreviation for the time zone during std time. |
string 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.
LocalTime
is a singleton class. LocalTime
returns its only instance.
In principle, this is the name of the local time zone. However, this always returns the empty string. This is because time zones cannot be uniquely identified by the attributes given by the OS (such as the stdName
and dstName
), and neither Posix systems nor Windows systems provide an easy way to get the TZ Database name of the local time zone.
Typically, 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.
However, on Windows, it may be the unabbreviated name (e.g. Pacific Standard Time). Regardless, it is not the same as name.
This property is overridden because the local time of the system could change while the program is running and we need to determine it dynamically rather than it being fixed like it would be with most time zones.
Typically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is in effect (e.g. PDT). It is not necessarily unique.
However, on Windows, it may be the unabbreviated name (e.g. Pacific Daylight Time). Regardless, it is not the same as name.
This property is overridden because the local time of the system could change while the program is running and we need to determine it dynamically rather than it being fixed like it would be with most time zones.
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 time zone did at some point have DST.
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 in effect in this time zone at the given point in time.
long stdTime
| The UTC time that needs to be checked for DST in this time zone. |
Returns 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 from std time.
long stdTime
| The UTC time that needs to be adjusted to this time zone's time. |
TimeZone.utcToTZ
Returns 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.
TimeZone.tzToUTC
long adjTime
| The time in this time zone that needs to be adjusted to UTC time. |
A TimeZone
which represents UTC.
UTC
is a singleton class. UTC
returns its only instance.
Always returns false.
Always returns false.
Returns the given hnsecs without changing them at all.
long stdTime
| The UTC time that needs to be adjusted to this time zone's time. |
TimeZone.utcToTZ
Returns the given hnsecs without changing them at all.
TimeZone.tzToUTC
long adjTime
| The time in this time zone that needs to be adjusted to UTC time. |
Returns a core.time.Duration
of 0.
long stdTime
| The UTC time for which to get the offset from UTC for this time zone. |
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 std.datetime.systime.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.
Always returns false.
Always returns false.
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 stdTime
| The UTC time that needs to be adjusted to this time zone's time. |
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).
long adjTime
| The time in this time zone that needs to be adjusted to UTC time. |
Returns utcOffset as a core.time.Duration
.
long stdTime
| The UTC time for which to get the offset from UTC for this time zone. |
Duration utcOffset
| This time zone's offset from UTC with west of UTC being negative (it is added to UTC to get the adjusted time). |
string stdName
| The stdName for this time zone. |
The amount of time the offset from UTC is (negative is west of UTC, positive is east).
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).
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). 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 time zone did at some point have DST.
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 in effect in this time zone at the given point in time.
long stdTime
| The UTC time that needs to be checked for DST in this time zone. |
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 stdTime
| The UTC time that needs to be adjusted to this time zone's time. |
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).
long adjTime
| The time in this time zone that needs to be adjusted to UTC time. |
The default directory where the TZ Database files are stored. It's empty for Windows, since Windows doesn't have them. You can also use the TZDatabaseDir version to pass an arbitrary path at compile-time, rather than hard-coding it here. Android concatenates all time zone data into a single file called tzdata and stores it in the directory below.
Returns 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 name
| The TZ Database name of the desired time zone |
string tzDatabaseDir
| The directory where the TZ Database files are located. Because these files are not located on Windows systems, provide them and give their location here to use PosixTimeZone s. |
std.datetime.date.DateTimeException
if the given time zone could not be found or FileException
if the TZ Database file could not be opened.version (Posix) { auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles"); writeln(tz.name); // "America/Los_Angeles" writeln(tz.stdName); // "PST" writeln(tz.dstName); // "PDT" }
Returns a list of the names of the time zones installed on the system.
Providing a sub-name narrows down the list of time zones (which can number in the thousands). For example, passing in "America" as the sub-name returns only the time zones which begin with "America".
string subName
| The first part of the desired time zones. |
string tzDatabaseDir
| The directory where the TZ Database files are located. |
FileException
if it fails to read from disk.This class is Windows-Only.
Represents a time zone from the Windows registry. 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.
The TZ Database files and Windows' time zone information frequently do not match. Windows has many errors with regards to when DST switches occur (especially for historical dates). Also, the TZ Database files include far more time zones than Windows does. So, for accurate time zone information, use the TZ Database files with PosixTimeZone
rather than WindowsTimeZone
. However, because WindowsTimeZone
uses Windows system calls to deal with the time, it's far more likely to match the behavior of other Windows programs. Be aware of the differences when selecting a method.
WindowsTimeZone
does not exist on Posix systems.
To get a WindowsTimeZone
, call WindowsTimeZone.getTimeZone
.
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 time zone did at some point have DST.
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 in effect in this time zone at the given point in time.
long stdTime
| The UTC time that needs to be checked for DST in this time zone. |
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 stdTime
| The UTC time that needs to be adjusted to this time zone's time. |
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).
long adjTime
| The time in this time zone that needs to be adjusted to UTC time. |
Returns a TimeZone
with the given name per the Windows time zone names. The time zone information is fetched from the Windows registry.
string name
| The TZ Database name of the desired time zone. |
std.datetime.date.DateTimeException
if the given time zone could not be found. auto tz = WindowsTimeZone.getTimeZone("Pacific Standard Time");
Returns a list of the names of the time zones installed on the system. The list returned by WindowsTimeZone contains the Windows TZ names, not the TZ Database names. However, TimeZone.getinstalledTZNames
will return the TZ Database names which are equivalent to the Windows TZ names.
This function is Posix-Only.
Sets the local time zone on Posix systems with the TZ Database name by setting the TZ environment variable.
Unfortunately, there is no way to do it on Windows using the TZ Database name, so this function only exists on Posix systems.
This function is Posix-Only.
Clears the TZ environment variable.
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.
string windowsZonesXMLText
| The text from windowsZones.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 = "http://unicode.org/cldr/data/common/supplemental/windowsZones.xml"; auto conversions2 = parseTZConversions(std.net.curl.get(url));
The 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).
The 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).
© 1999–2019 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/std_datetime_timezone.html