Rcpp bindings for CCTZ

So what is 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.

Key Features of CCTZ

CCTZ actually implements two libraries:

  • A civil-time library dealing with human-readable dates and times, and
  • A time-zone library converting between absolute time and civil time.

See the excellent discussion on the README.md page for CCTZ for more.

Quick Examples

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())
[1] 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

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")
[1] "2016-07-14 10:28:39.91740 CDT"

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")
[1] "2016-07-14 15:00:00 CDT"


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



Dirk Eddelbuettel


GPL (>= 2)

Initially created: Thu Jul 14 06:19:32 CDT 2016
Last modified: Sun Jan 08 15:51:53 CST 2017