MyNixOS website logo
Description

'Rcpp' Bindings for the 'CCTZ' Library.

'Rcpp' Access to the 'CCTZ' timezone library is provided. 'CCTZ' is a C++ library for translating between absolute and civil times using the rules of a time zone. The 'CCTZ' source code, released under the Apache 2.0 License, is included in this package. See <https://github.com/google/cctz> for more details.

RcppCCTZ: Rcpp bindings for CCTZ

CI License CRAN Dependencies Downloads Last Commit

What is CCTZ?

CCTZ (C++ Time Zone) is an excellent (yet small) C++11 library for translating between absolute times and civil times using the rules defined by a time zone. See its repository (as well as code) for very detailed documentation. CCTZ is being developed by Google but not an officially endorsed product.

What is RcppCCTZ?

This package wraps CCTZ for use by R via Rcpp.

Examples

Difference between Timezones

R> # simple call: difference now
R> tzDiff("America/New_York", "Europe/London", Sys.time())
[1] 5
R> # tabulate difference for every week of the year
R> table(sapply(0:52, function(d) tzDiff("America/New_York", "Europe/London",
+                                        as.POSIXct(as.Date("2016-01-01") + d*7))))

 4  5
 3 50

Shifting Timezone

R> # Given current time in NY what is the time London, UK
R> # (running the code locally in Chicago hence CST text format)    
R> toTz(Sys.time(), "America/New_York", "Europe/London") 	
[1] "2016-12-10 17:15:04.20370 CST"
R> # this redoes the 'Armstrong on the moon in NYC and Sydney' example
R> # note that the default print method will print the return object in _your local time_
R> toTz(ISOdatetime(1969,7,20,22,56,0,tz="UTC"), "America/New_York", "Australia/Sydney", TRUE)
1969-07-20 22:56:00 -0400
1969-07-21 12:56:00 +1000
[1] "1969-07-20 21:56:00 CDT"
R> # whereas explicitly formating for Sydney time does the right thing
R> format(toTz(ISOdatetime(1969,7,20,22,56,0,tz="UTC"),
+             "America/New_York", "Australia/Sydney", verbose=TRUE),
+        tz="Australia/Sydney")
1969-07-20 22:56:00 -0400
1969-07-21 12:56:00 +1000
[1] "1969-07-21 12:56:00"

Parsing and Formatting

R> now <- Sys.time()
R> formatDatetime(now)            # current (UTC) time, in full precision RFC3339
[1] "2016-12-10T18:23:03.327956+00:00"
R> formatDatetime(now, tgttzstr="America/New_York")  # same but in NY
[1] "2016-12-10T13:23:03.327956-05:00"
R> formatDatetime(now + 0:4)	   # vectorised
[1] "2016-12-10T18:23:03.327956+00:00" "2016-12-10T18:23:04.327956+00:00"
[3] "2016-12-10T18:23:05.327956+00:00" "2016-12-10T18:23:06.327956+00:00"
[5] "2016-12-10T18:23:07.327956+00:00"
R>

R> ds <- getOption("digits.secs")
R> options(digits.secs=6) # max value
R> parseDatetime("2016-12-07 10:11:12",        "%Y-%m-%d %H:%M:%S");   # full seconds
[1] "2016-12-07 04:11:12 CST"
R> parseDatetime("2016-12-07 10:11:12.123456", "%Y-%m-%d %H:%M:%E*S"); # fractional seconds
[1] "2016-12-07 04:11:12.123456 CST"
R> parseDatetime("2016-12-07T10:11:12.123456-00:00")  ## default RFC3339 format
[1] "2016-12-07 04:11:12.123456 CST"
R> now <- trunc(Sys.time())
R> parseDatetime(formatDatetime(now + 0:4))	   			# vectorised
[1] "2016-12-10 12:24:25 CST" "2016-12-10 12:24:26 CST" "2016-12-10 12:24:27 CST"
[4] "2016-12-10 12:24:28 CST" "2016-12-10 12:24:29 CST"
R> options(digits.secs=ds)

Requirements

The CCTZ library depends on timezone files typically found in /usr/share/zoneinfo which requires a Unix-alike OS such as Linux or OS X. Old school Unix variants may work.

Status

On CRAN, builds and tests cleanly, and the example functions are accessible from R.

Installation

The package is now on CRAN and can be installed via a standard

install.packages("RcppCCTZ")

Continued Testing

As we rely on the tinytest package, the already-installed package can also be verified via

tinytest::test_package("RcppCCTZ")

at any later point.

Author

Dirk Eddelbuettel

License

GPL (>= 2)

Metadata

Version

0.2.12

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows