Title: | 'Rcpp' Bindings for the Boost Date_Time Library |
---|---|
Description: | Access to Boost Date_Time functionality for dates, durations (both for days and date time objects), time zones, and posix time ('ptime') is provided by using 'Rcpp modules'. The posix time implementation can support high-resolution of up to nano-second precision by using 96 bits (instead of 64 with R) to present a 'ptime' object (but this needs recompilation with a #define set). |
Authors: | Dirk Eddelbuettel [aut, cre] , Romain Francois [aut] |
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2.6.1 |
Built: | 2024-10-28 06:36:39 UTC |
Source: | https://github.com/eddelbuettel/rcppbdt |
This package provides R with access to Boost Date_Time functonality by using Rcpp modules.
Date, Local time, duration and time zone functionality is covered.
Please consult the Boost documentation for (copious) details on the Date_Time library.
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
The bdtDd
module is created using Rcpp modules and wraps a
helper class bdtDd
around Boost Date_time date duration
functionality provided by the Boost class boost::gregorian::date_duration
.
New instances can be created using an integer for days of duration.
days(...) weeks(...)
days(...) weeks(...)
... |
suitable argument, often an integer, denoting one unit of the reference duration component |
Please consult the Boost documentation for (copious) details on the Date_Time library. See the Rcpp-modules vignette for details on Rcpp modules.
signature(x = "Rcpp_bdtDd")
: prints a (BDTdd)
date duration class object
signature(x = "Rcpp_bdtDd")
: formats a (BDTdd)
date duration class object
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
The bdtDt
module is created using Rcpp modules and wraps a
helper class bdtDt
around Boost Date_time date
functionality provided by the Boost class boost::gregorian::date
.
New instances can be created using either the default constructor (without arguments) or the constructor using year, month, date arguments.
The bdt
variable is a default instance of this bdtDt
reference class. It facilities accessing the member functions via
utility function, see for example getEndOfBizWeek
or
print(bdtDt)
for the available methods.
Please consult the Boost documentation for (copious) details on the Date_Time library. See the Rcpp-modules vignette for details on Rcpp modules.
signature(x = "Rcpp_bdtDt")
: prints a (bdtDt) date class object
signature(x = "Rcpp_bdtDt")
: formats a (bdtDt) date class object
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
The bdtDu
module is created using Rcpp modules and wraps a
helper class bdtDu
around Boost Date_time duration
functionality provided by the Boost class boost::posix_time::duration
.
New instances can be created using four integer values for hour, minute, seconds and fractional seconds. Fractional seconds ought to be at a nano-second granularity; there may be platforms not permitting this.
hours(...) microseconds(...) milliseconds(...) minutes(...) nanoseconds(...) seconds(...)
hours(...) microseconds(...) milliseconds(...) minutes(...) nanoseconds(...) seconds(...)
... |
suitable argument, often an integer, denoting one unit of the reference duration component |
Please consult the Boost documentation for (copious) details on the Date_Time library. See the Rcpp-modules vignette for details on Rcpp modules.
signature(x = "Rcpp_bdtDu")
: prints a (BDTdu) duration class object
signature(x = "Rcpp_bdtDu")
: formats a (BDTdu) duration class object
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
The bdtDu
module is created using Rcpp modules and wraps a
helper class bdtPt
around Boost Date_time duration
functionality provided by the Boost class boost::posix_time::ptime
.
New instances can be created using either a default construction (creating an unset instance) or using seven integer values for year, month, day, hour, minute, seconds and fractional seconds. Fractional seconds ought to be at a nano-second granularity; there may be platforms not permitting this.
Please consult the Boost documentation for (copious) details on the Date_Time library. See the Rcpp-modules vignette for details on Rcpp modules.
signature(x = "Rcpp_bdtPt")
: prints a (bdtPt) ptime class object
signature(x = "Rcpp_bdtPt")
: formats a (bdtPt) ptime class object
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
The bdtTz
module is created using Rcpp modules and wraps a
helper class bdtTz
around Boost Date_time timezone
functionality provided mainly by the Boost classes
boost::local_time::tz_database
and
boost::local_time::time_zone_ptr
.
On startup, the database object is initialized using a local copy (in csv format) of the timezone data. Instances of the timezone object, represented by an instance of the timezone pointer class, can be created and queried.
New instances can be created using a valid timezone region string (such “Europe/London”).
Please consult the Boost documentation for (copious) details on the Date_Time library. See the Rcpp-modules vignette for details on Rcpp modules.
signature(x = "Rcpp_bdtTz")
: prints a (bdtTz) timezone class object
signature(x = "Rcpp_bdtTz")
: formats a (bdtTz) timezone class object
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
This function uses the Boost Date_Time library to parse
datetimes from strings. It returns a vector of POSIXct
objects. These represent dates and time as (possibly
fractional) seconds since the ‘epoch’ of January 1, 1970.
A timezone can be set, if none is supplied ‘UTC’ is set.
charToPOSIXct(sv, tz = "UTC")
charToPOSIXct(sv, tz = "UTC")
sv |
A vector of type character with datetime expressions in ISO format to be parsed and converted. |
tz |
A string with the timezone, defaults to ‘UTC’ if unset |
A single standard ISO format ‘YYYY-MM-DD HH:MM:SS’ (with
optional trailing fractional seconds) is tried. In the case of
parsing failure a NA
value is returned. See the function
toPOSIXct
for more general input format
Fractional seconds are supported as well. As R itself only supports microseconds, the Boost compile-time option for nano-second resolution has not been enabled.
A vector of ‘POSIXct’ elements.
Dirk Eddelbuettel
times <- c("2004-03-21 12:45:33.123456", "2004-03-21 12:45:34") charToPOSIXct(times)
times <- c("2004-03-21 12:45:33.123456", "2004-03-21 12:45:34") charToPOSIXct(times)
This function uses Rcpp to parse
datetimes from strings. It returns a vector of POSIXct
objects. These represent dates and time as (possibly
fractional) seconds since the ‘epoch’ of January 1, 1970.
A timezone can be set, if none is supplied ‘UTC’ is set.
cToPOSIXct(sv, fmt = "%Y-%m-%d %H:%M:%OS", tz = "UTC")
cToPOSIXct(sv, fmt = "%Y-%m-%d %H:%M:%OS", tz = "UTC")
sv |
A vector of type character with datetime expressions in ISO format to be parsed and converted. |
fmt |
A format, defaults to the ISO format if unset |
tz |
A string with the timezone, defaults to ‘UTC’ if unset |
The default standard ISO format ‘YYYY-MM-DD HH:MM:SS.FFFFFFF’ is is used by default along with the UTC time zone.
This function is for comparison only.
A vector of ‘POSIXct’ elements.
Dirk Eddelbuettel
times <- c("2004-03-21 12:45:33.123456", "2004-03-21 12:45:34") cToPOSIXct(times)
times <- c("2004-03-21 12:45:33.123456", "2004-03-21 12:45:34") cToPOSIXct(times)
This constants are provided for convenience. In the C++ sources, enumeration types are used for days of the week, months of the year as well as the ordering terms.
Similar package-level constants are provided here as well. This should be considered as experimental and may be withdrawn in a later version of the package.
getEndOfBizWeek(date) getEndOfMonth(date) getYear(date) getMonth(date) getDay(date) getDayOfWeek(date) getDayOfYear(date) getIMMDate(mon, year) getNthDayOfWeek(nthday, dow, mon, year) getLastDayOfWeekInMonth(dow, mon, year) getFirstDayOfWeekInMonth(dow, mon, year) getFirstDayOfWeekAfter(dow, date) getLastDayOfWeekBefore(dow, date)
getEndOfBizWeek(date) getEndOfMonth(date) getYear(date) getMonth(date) getDay(date) getDayOfWeek(date) getDayOfYear(date) getIMMDate(mon, year) getNthDayOfWeek(nthday, dow, mon, year) getLastDayOfWeekInMonth(dow, mon, year) getFirstDayOfWeekInMonth(dow, mon, year) getFirstDayOfWeekAfter(dow, date) getLastDayOfWeekBefore(dow, date)
date |
a |
mon |
a month, specified either as an integer or one of the
constants |
year |
a four-digit year, specified as an integer |
nthday |
either an integer between 1 and 5, or one of the
constants |
dow |
either an integer between 0 and 6 denoting a day of the
week, or one of the constants |
Details of the Boost functions are provided by the Boost documentation.
All functions return a Date
object.
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
This constants are provided for convenience. In the C++ sources, enumeration types are used for days of the week, months of the year as well as the ordering terms.
Similar package-level constants are provided here as well. This should be considered as experimental and may be withdrawn in a later version of the package.
Sun
, Mon
, Tue
, ..., Sat
can be used instead of the values 0 to 6.
Jan
, Feb
, ..., Dec
can be used instead of the values 1 to 12.
first
, second
, ..., fifth
can be used instead of the values 1 to 5.
We use the same values as the Boost source code. In other words, Sunday is 0, Monday is 1 and so on. Months, however, start at 1 for January.
Dirk Eddelbuettel [email protected]
Boost Date_Time: https://www.boost.org/doc/libs/release/doc/html/date_time.html
This function uses the Boost Date_Time library to parse
datetimes (and dates) from strings, integers or even numeric values
(which are cast to strings internall). It returns a vector of
POSIXct
objects. These represent dates and time as (possibly
fractional) seconds since the ‘epoch’ of January 1, 1970.
A timezone can be set, if none is supplied ‘UTC’ is set.
toPOSIXct(x, tz = "UTC")
toPOSIXct(x, tz = "UTC")
x |
A vector of type character, integer or numeric with date(time) expressions to be parsed and converted. |
tz |
A string with the timezone, defaults to ‘UTC’ if unset |
A number of fixed formats are tried in succession. These include
the standard ISO format ‘YYYY-MM-DD HH:MM:SS’ as well as
different local variants including several forms popular in the
United States. Two-digits years and clearly ambigous formats such
as ‘03/04/05’ are ignored. In the case of parsing failure
a NA
value is returned.
Fractional seconds are supported as well. As R itself only supports microseconds, the Boost compile-time option for nano-second resolution has not been enabled.
A vector of ‘POSIXct’ elements.
Dirk Eddelbuettel
The funtion in the anytime package which is a more finished. variant which is based on the initial work with function, and taken into its own package.
## See the source code (hah!) for a full list of formats times <- c("2004-03-21 12:45:33.123456", "2004/03/21 12:45:33.123456", "20040321 124533.123456", "21.03.2004 12:45:33.123456", "03/21/2004 12:45:33.123456", "03-21-2004 12:45:33.123456", "2004-03-21", "20040321", "03/21/2004", "03-21-2004", "20010101") toPOSIXct(times)
## See the source code (hah!) for a full list of formats times <- c("2004-03-21 12:45:33.123456", "2004/03/21 12:45:33.123456", "20040321 124533.123456", "21.03.2004 12:45:33.123456", "03/21/2004 12:45:33.123456", "03-21-2004 12:45:33.123456", "2004-03-21", "20040321", "03/21/2004", "03-21-2004", "20010101") toPOSIXct(times)