Movatterモバイル変換


[0]ホーム

URL:


Dirk Eddelbuettel

RcppCCTZ: Rcpp bindings forCCTZ

Build StatusLicenseCRANDependenciesDownloadsLast Commit

What is CCTZ?

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

What is RcppCCTZ?

This package wraps CCTZ for use by R viaRcpp.

Examples

Difference between Timezones

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

Shifting Timezone

R># Given current time in NY what is the time London, UKR># (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' exampleR># 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-2022:56:00-04001969-07-2112:56:00+1000[1]"1969-07-20 21:56:00 CDT"R># whereas explicitly formating for Sydney time does the right thingR>format(toTz(ISOdatetime(1969,7,20,22,56,0,tz="UTC"),+"America/New_York","Australia/Sydney",verbose=TRUE),+tz="Australia/Sydney")1969-07-2022:56:00-04001969-07-2112: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 valueR>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

TheCCTZ library dependson timezone files typically found in/usr/share/zoneinfowhich requires a Unix-alike OS such as Linux or OS X. Old school Unixvariants may work.

Status

OnCRAN,builds and tests cleanly, and the example functions are accessible fromR.

Installation

The package is now onCRANand can be installed via a standard

install.packages("RcppCCTZ")

Continued Testing

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

tinytest::test_package("RcppCCTZ")

at any later point.

Author

Dirk Eddelbuettel

License

GPL (>= 2)

Initially created: Thu Jul 14 06:19:32 CDT 2016
Last modified: Sun May 26 10:09:44 CDT 2024


[8]
ページ先頭

©2009-2025 Movatter.jp