The type of a time-zone.
bin_io and sexp representations of Zone.t are the name of the zone, and not the full
data that is read from disk when Zone.find is called. The full Zone.t is
reconstructed on the receiving/reading side by reloading the zone file from disk. Any
zone name that is accepted by
find is acceptable in the bin_io and sexp
find name looks up a
t by its name and returns it.
local is the machine's local timezone, as determined from the
variable or the
/etc/localtime file. It is computed from the state of the process
environment and on-disk tzdata database at some unspecified moment prior to its first
use, so its value may be unpredictable if that state changes during program operation.
Arguably, changing the timezone of a running program is a problematic operation anyway
-- most people write code assuming the clock doesn't suddenly jump several hours
Note that any function using this timezone can throw an exception if the
environment variable is misconfigured or if the appropriate timezone files can't be
found because of the way the box is configured. We don't sprinkle
_exn all over all
the names in this module because such misconfiguration is quite rare.
likely_machine_zones is a list of zone names that will be searched first when trying
to determine the machine zone of a box. Setting this to a likely set of zones for
your application will speed the very first use of the local timezone.
of_utc_offset offset returns a timezone with a static UTC offset (given in
default_utc_offset returns the UTC offset of default regime for timezone
seconds. Note: the default utc offset may not reflect the current utc offset.
utc the UTC time zone. Included for convenience
abbreviation zone t returns t abbreviation name such as EDT, EST, JST of given
zone at the time
t. This string conversion is one-way only, and cannot reliably
be turned back into a t
name zone returns the name of the time zone
init () pre-load all available time zones from disk, this function has no effect if
it is called multiple times. Time zones will otherwise be loaded at need from the
disk on the first call to find/find_exn.
digest t return the MD5 digest of the file the t was created from (if any)
initialized_zones () returns a sorted list of time zone names that have been loaded
from disk thus far.
shift_epoch_time zone [`Local | `UTC] time Takes an epoch (aka "unix") time given
either in local or in UTC (as indicated in the arguments) and shifts it according to
the local time regime in force in zone. That is, given a Local epoch time it will
return the corresponding UTC timestamp and vice versa. This function is low level,
and is not intended to be called by most client code. Use the high level functions
provided in Time instead.
This library replicates and extends the functionality of the standard Unix time handling functions (currently exposed in the Unix module, and indirectly through the Time module).
Things you should know before delving into the mess of time...
general overview - http://www.twinsun.com/tz/tz-link.htm zone abbreviations - http://blogs.msdn.com/oldnewthing/archive/2008/03/07/8080060.aspx leap seconds - http://en.wikipedia.org/wiki/Leap_second epoch time - http://en.wikipedia.org/wiki/Unix_time UTC/GMT time - http://www.apparent-wind.com/gmt-explained.html TAI time - http://en.wikipedia.org/wiki/International_Atomic_Time Almost every possible time measurement - http://www.ucolick.org/~sla/leapsecs/timescales.html
All of these systems start to exhibit problems as you go further back in time, partly because truly accurate timekeeping didn't make an appearance until roughly 1958, and partly because different parts of the world didn't actually have well defined time zones for a long time. If you go back far enough, you run into the switch between the Julian (old) and the Gregorian calendar, which happened at different times in history in different places in the world.
for more information on the obscure forms. The common form represents a relative path from the base /usr/share/zoneinfo/posix, and is generally in the form of a continent or country name paired with a city name (Europe/London, America/New_York). This is used to load the specified file from disk, which contains a time zone database in zic format (man tzfile).
It's worth noting that under this system there is no place on the system to go to get the name of the file you are using (/etc/localtime may not be a link, and may just be a copy, or its own database not represented in /usr/share/zoneinfo). Additionally, the names of the files in the system zoneinfo database follow an internal standard, and there is no established standard for naming timezones. So even if you were using one of these files, and you did know its name, you cannot assume that that name matches any timezone specified by any other system or description.
One common misconception about time zones is that the standard time zone abbreviations can be used. For instance, EST surely refers to Eastern Standard Time. This is unfortunately not true - CST can refer to China Central Time, Central Standard Time, or Cuba Summer Time for instance - and time zone libraries that appear to correctly parse times that use time zone abbreviations do so by using a heuristic that usually assumes you mean a time in the US or Europe, in that order. Time zones also sometimes use two different abbreviations depending on whether the time in question is in standard time, or daylight savings time. These abbreviations are kept in the timezone databases, which is how programs like date manage to output meaningful abbreviations, it is only reading in times with abbreviations that is poorly specified.
This library contains a function that attempts to make an accurate determination of the machine timezone by testing the md5 sum of the currently referenced timezone file against all of the possible candidates in the system database. It additionally makes some adjustments to return the more common timezone names since some files in the database are duplicated under several names. It returns an option because of the problems mentioned above.
There are two cases where string time conversions are problematic, both related to daylight savings time.
In the case where time jumps forward one hour, there are possible representations of times that never happened 2006-04-02T02:30:00 in the eastern U.S. never happened for instance, because the clock jumped forward one hour directly from 2 to 3. Unix time zone libraries asked to convert one of these times will generally produce the epoch time that represents the time 1/2 hour after 2 am, which when converted back to a string representation will be T03:30:00.
The second case is when the clocks are set back one hour, which causes one hour of time to happen twice. Converting a string in this range without further specification into an epoch time is indeterminate since it could be referring to either of two times. Unix libraries handle this by either allowing you to pass in a dst flag to the conversion function to specify which time you mean, or by using a heuristic to guess which time you meant.
The existence of both cases make a strong argument for serializing all times in UTC, which doesn't suffer from these issues.