Rcpp bindings for CCTZ
CCTZ is (yet another, you sigh?) time zones library. It was written from the ground up in proper C++11, and has no other dependencies than the presence of proper timezone files. These are commonly located in
/usr/share/zoneinfo which requires a Unix-alike OS such as Linux or OS X. Old school Unix variants may work too. On Windows we use the zoneinfo copy which R brings along.
It was written at Google and is used there, but is not "an official Google project" as the CCTZ page states at the top.
CCTZ actually implements two libraries:
See the excellent discussion on the README.md page for CCTZ for more.
We provide R-accessible wrappers to the examples included in CCTZ. We also added two simple time-zone helpers.
The first one tabulates the time difference between New York and London (at a weekly level for compactness):
R> example(tzDiff) tzDiffR> # simple call: difference now tzDiffR> tzDiff("America/New_York", "Europe/London", Sys.time())  5 tzDiffR> # tabulate difference for every week of the year tzDiffR> table(sapply(0:52, function(d) tzDiff("America/New_York", "Europe/London", tzDiff+ as.POSIXct(as.Date("2016-01-01") + d*7)))) 4 5 3 50 R>
Because the two continents happen to spring forward and fall backwards between regular and daylight savings times, there are, respectively, two and one week periods where the difference is one hour less than usual.
A second example shifts the time to a different time zone:
R> example(toTz) toTzR> toTz(Sys.time(), "America/New_York", "Europe/London")  "2016-07-14 10:28:39.91740 CDT" R>
Note that because we return a
POSIXct object, it is printed by R with the default (local) TZ attribute (for "America/Chicago" in my case). A more direct example asks what time it is in my time zone when it is midnight in Tokyo:
R> toTz(ISOdatetime(2016,7,15,0,0,0), "Japan", "America/Chicago")  "2016-07-14 15:00:00 CDT" R>
Fairly complete and robust. Since version 0.2.0 also supported on Windows.
The package is on CRAN and can be installed from every mirror via
GPL (>= 2)