Rev 71221 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/timezones.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2016 R Core Team% Distributed under GPL 2 or later\name{timezones}\alias{Sys.timezone}\alias{OlsonNames}\alias{timezone}\alias{timezones}\alias{time zone}\alias{time zones}\alias{TZ}\alias{TZDIR}\title{Time Zones}\description{Information about time zones in \R. \code{Sys.timezone} returnsthe name of the current time zone.}\usage{Sys.timezone(location = TRUE)OlsonNames()}\arguments{\item{location}{logical: should an attempt be made to find thelocation name as used in the Olson/IANA database?(See \sQuote{Time zone names} below.)}}\details{Time zones are a system-specific topic, but these days almost all \Rplatforms use similar underlying code, used by Linux, macOS, Solaris,AIX, FreeBSD, Sun Java >= 1.4 and Tcl >= 8.5, and installed with \R onWindows. Unfortunately there are many system-specific errors in theimplementations. It is possible to use \R's own version of the codeon Unix-alikes as well as on Windows: this is the default for macOS andrecommended for Solaris.It should be possible to set the time zone via the environmentvariable \env{TZ}: see the section on \sQuote{Time zone names} forsuitable values. \code{Sys.timezone()} will return the value of\env{TZ} if set (and on some OSes it is always set), otherwise it willtry to retrieve a value which if set for \env{TZ} would give thecurrent time zone. This is not in general possible, and\code{Sys.timezone(FALSE)} on Windows will retrieve the abbreviationused for the current time.If \env{TZ} is set but empty or invalid, most platforms default to\samp{UTC}, the time zone colloquially known as \samp{GMT} (see\url{https://en.wikipedia.org/wiki/Coordinated_Universal_Time}). (Somebut not all platforms will give a warning for invalid time zones.)Time zones did not come into use until the second half of thenineteenth century and were not widely adopted until the twentieth,and \emph{daylight saving time} (DST, also known as \emph{summertime}) was first introduced in the early twentieth century, mostwidely in 1916. Over the last 100 years places have changed theiraffiliation between major time zones, have opted out of (or in to) DSTin various years or adopted DST rule changes late or not at all.A quite common system implementation of \code{POSIXct} is as signed32-bit integers and so only goes back to the end of 1901: on suchsystems \R assumes that dates prior to that are in the same time zoneas they were in 1902. Most of the world had not adopted time zones by1902 (so used local \sQuote{mean time} based on longitude) but for afew places there had been time-zone changes before then. 64-bitrepresentations are becoming common; unfortunately on some 64-bit OSes(notably macOS) the database information is 32-bit and so onlyavailable for the range 1901--2038, and incompletely for the endyears.}\value{\code{Sys.timezone} returns an OS-specific character string, possibly\code{NA} or an empty string (which on some OSes means \samp{UTC}).For the default \code{location = TRUE} this will be a location such as\code{"Europe/London"} if one can be ascertained. For \code{location= FALSE} this may be an abbreviation such as \code{"EST"} or\code{"CEST"} on Windows.\code{OlsonNames} returns a character vector.}\section{Time zone names}{Names \code{"UTC"} and its synonym \code{"GMT"} are accepted on allplatforms.Where OSes describe their valid time zones can be obscure. The helpfor the C function \code{tzset} can be helpful, but it can also beinaccurate. There is a cumbersome POSIX specification (listed underenvironment variable \env{TZ} at\url{http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08}),which is often at least partially supported, but there are other moreuser-friendly ways to specify time zones.Almost all \R platforms make use of a time-zone database originallycompiled by Arthur David Olson and now managed by IANA, in which thepreferred way to refer to a time zone is by a location (typically of acity), e.g., \code{Europe/London}, \code{America/Los_Angeles},\code{Pacific/Easter}. Some traditional designations are also allowedsuch as \code{EST5EDT} or \code{GB}. (Beware that some of thesedesignations may not be what you expect: in particular \code{EST} is atime zone used in Canada \emph{without} daylight saving time, and not\code{EST5EDT} nor (Australian) Eastern Standard Time.) Thedesignation can also be an optional colon prepended to the path to afile giving complied zone information (and the examples above are allfiles in a system-specific location). See\url{http://www.twinsun.com/tz/tz-link.htm} for more details andreferences. By convention, regions with a unique time-zone historysince 1970 have specific names in the database, but those withdifferent earlier histories may not. Each time zone has one or two(the second for DST) \emph{abbreviations} used when formatting times.The abbreviations used have changed over the years: for example Franceused \samp{PMT} (\sQuote{Paris Mean Time}) from 1891 to 1911 then\samp{WET/WEST} up to 1940 and \samp{CET/CEST} from 1946. (In almostall time zones the abbreviations have been stable since 1970.) ThePOSIX standard allows only one or two abbreviations per time zone, soyou may see the current abbreviation(s) used for older times.The function \code{OlsonNames} returns the time-zone names known tothe Olson/IANA database on the current system. The system-specificlocation in the file system varies, e.g.\sspace{}\file{/usr/share/zoneinfo}(Linux, macOS, FreeBSD), \file{/usr/share/lib/zoneinfo} (Solaris, AIX),\ldots. It is likely that there is a file named something like\file{zone.tab} under that directory listing the locations known astime-zone names (but not for example \code{EST5EDT}): this is read by\code{OlsonNames}. See also\url{https://en.wikipedia.org/wiki/Zone.tab}.Where \R was configured with option \option{--with-internal-tzcode}(the default on macOS and Windows: recommended on Solaris), the database at\code{file.path(R.home("share"), "zoneinfo")} is used by default: file\file{VERSION} in that directory states the version. Environmentvariable \env{TZDIR} can be used to point to a different\file{zoneinfo} directory: this is also supported by the nativeservices on some OSes, e.g.\sspace{}Linux).#ifdef windowsAn attempt is made (once only per session) to map Windows' idea of thecurrent time zone to a location, following a version of\url{http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml}with additional values deduced from the Windows Registry and documentation.It can be overridden by setting the \env{TZ} environment variablebefore any date-times are used in the session.#endifMost platforms support time zones of the form \samp{GMT+n} and\samp{GMT-n}, which assume at a fixed offset from UTC (hence no DST).Contrary to some expectations (but consistent with names such as\samp{PST8PDT}), negative offsets are times ahead of (east of) UTC,positive offsets are times behind (west of) UTC.Immediately prior to the advent of legislated time zones, most peopleused time based on their longitude (or that of a nearby town), knownas \sQuote{Local Mean Time} and abbreviated as \samp{LMT} in thedatabases: in many countries that was codified with a specific namebefore the switch to a standard time. For example, Paris codified itsLMT as \sQuote{Paris Mean Time} in 1891 (to be used throughoutmainland France) and switched to \samp{GMT+0} in 1911.%% it is a ksh script so could well pop up elsewhere.Some systems (notably Linux) have a \command{tzselect} command whichallows the interactive selection of a supported time zone name.}\section{Warning}{%% glibc and macOS have _POSIX_TZNAME_MAX and define it as 6.%% Earlier versions of R's code assumed 10, and it was discovered%% that some implemntations did not abbreviate unusual names, thereby%% exceeding this.%% Olson's tzcode has a limit of 255 and does not check: this has been%% corrected in R's copy.%% sysconf(_SC_TZNAME_MAX) might allow it to be checked:%% that gives 27 on macOS. However, seems it is dynamic on glibc.There is a system-specific upper limit on the number of bytes in(abbreviated) time-zone names which can be as low as 6 (as required byPOSIX). Some OSes allow the setting of time zones with names whichexceed their limit, and that can crash the \R session.}\note{Since 2007 there has been considerable disruption over changes to thetimings of the DST transitions, aimed at energy conservation. Theseoften have short notice and time-zone databases may not be up to date.(Morocco in 2013 announced a change to the end of DST at \emph{a days}notice, and in 2015 North Korea gave imprecise information about achange a week in advance.)On platforms with case-insensitive file systems, time zone names will becase-insensitive. They may or may not be on other platforms and so,for example, \code{"gmt"} is valid on some platforms and not on others.Note that except where replaced, the operation of time zones is an OSservice, and even where replaced a third-party database is used andcan be updated (see the section on \sQuote{Time zone names}).Incorrect results will never be an \R issue, so please ensure that youhave the courtesy not to blame \R for them.}% Unlike Tony Plate and John Pfuntner\seealso{\code{\link{Sys.time}}, \code{\link{as.POSIXlt}}.\url{https://en.wikipedia.org/wiki/Time_zone} and\url{http://www.twinsun.com/tz/tz-link.htm} for extensive sets of links.}\examples{Sys.timezone()str(OlsonNames()) ## a few hundred names}\keyword{utilities}\keyword{chron}