nanoperiod
is a length of time type (implemented as an S4
class) with nanosecond precision. It differs from
nanoduration
because it is capable of representing calendar
months and days. It can thus represent years (12 months) and weeks
(7 days). A period is a somewhat abstract representation of time:
it is only when anchored to a point in time and in a specific time
zone that it is possible to convert it to a specific
duration. This means that many of the operations involving periods
need the additional argument tz
.
nanoperiod(months = 0, days = 0, duration = as.nanoduration(0))# S4 method for character
as.nanoperiod(x)
# S4 method for integer64
as.nanoperiod(x)
# S4 method for numeric
as.nanoperiod(x)
# S4 method for integer
as.nanoperiod(x)
# S4 method for nanoduration
as.nanoperiod(x)
# S4 method for `NULL`
as.nanoperiod(x)
# S4 method for missing
as.nanoperiod(x)
# S4 method for nanoperiod
show(object)
# S4 method for nanoperiod
print(x, quote = FALSE, ...)
# S3 method for nanoperiod
format(x, ...)
# S4 method for nanoperiod
as.character(x)
# S4 method for nanoperiod
is.na(x)
# S4 method for nanoperiod
is.na(x) <- value
# S4 method for nanoperiod
[[(x, i, j, ..., drop = FALSE)
# S4 method for nanoperiod,numeric
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoperiod,logical
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoperiod,character
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoperiod,ANY
[(x, i, j, ..., drop = FALSE)
# S4 method for nanoperiod,ANY,ANY,ANY
[(x, i, j, ...) <- value
# S3 method for nanoperiod
c(...)
# S4 method for nanoperiod
names(x)
# S4 method for nanoperiod
names(x) <- value
# S4 method for nanoperiod,ANY
-(e1, e2)
# S4 method for nanoperiod,nanoperiod
-(e1, e2)
# S4 method for nanoperiod,nanoduration
-(e1, e2)
# S4 method for nanoperiod,integer64
-(e1, e2)
# S4 method for nanoperiod,numeric
-(e1, e2)
# S4 method for nanoduration,nanoperiod
-(e1, e2)
# S4 method for integer64,nanoperiod
-(e1, e2)
# S4 method for numeric,nanoperiod
-(e1, e2)
# S4 method for nanoperiod,ANY
+(e1, e2)
# S4 method for nanoperiod,nanoperiod
+(e1, e2)
# S4 method for nanoperiod,nanoduration
+(e1, e2)
# S4 method for nanoperiod,integer64
+(e1, e2)
# S4 method for nanoperiod,nanotime
+(e1, e2)
# S4 method for nanoival,nanoperiod
+(e1, e2)
# S4 method for nanoperiod,nanoival
+(e1, e2)
# S4 method for nanotime,nanoperiod
+(e1, e2)
# S4 method for nanoperiod,numeric
+(e1, e2)
# S4 method for nanoduration,nanoperiod
+(e1, e2)
# S4 method for integer64,nanoperiod
+(e1, e2)
# S4 method for numeric,nanoperiod
+(e1, e2)
# S4 method for nanoperiod,integer64
*(e1, e2)
# S4 method for nanoperiod,numeric
*(e1, e2)
# S4 method for integer64,nanoperiod
*(e1, e2)
# S4 method for numeric,nanoperiod
*(e1, e2)
# S4 method for nanoperiod,integer64
/(e1, e2)
# S4 method for nanoperiod,numeric
/(e1, e2)
# S4 method for nanoperiod,nanoperiod
==(e1, e2)
# S4 method for nanoperiod,nanoperiod
!=(e1, e2)
# S4 method for nanotime,nanoperiod,character
plus(e1, e2, tz)
# S4 method for nanoperiod,nanotime,character
plus(e1, e2, tz)
# S4 method for nanotime,nanoperiod,character
minus(e1, e2, tz)
# S4 method for nanoperiod,nanotime,character
minus(e1, e2, tz)
# S4 method for nanoival,nanoperiod,character
plus(e1, e2, tz)
# S4 method for nanoperiod,nanoival,character
plus(e1, e2, tz)
# S4 method for nanoival,nanoperiod,character
minus(e1, e2, tz)
NA_nanoperiod_
An object of class nanoperiod
of length 1.
Used in the constructor to indicate the number of
months of the nanoperiod
Used in the constructor to indicate the number of
days of the nanoperiod
Used in the constructor to indicate the duration
component of the nanoperiod
An object of class nanoperiod
argument for method show
indicates if the output of print
should be
quoted
further arguments
index specifying elements to extract or replace.
Required for [
signature but ignored here
Required for [
signature but ignored here
Operand of class nanoperiod
Operand of class nanoperiod
character
indicating a timezone
The true constructor is
A nanoperiod
is displayed as months, days, and nanoduration
like this: 10m2d/10:12:34.123_453_000
.
Dirk Eddelbuettel
Leonardo Silvestri
Adding or subtracting nanoperiod
and nanotime
require a timezone as third argument. For this reason it is not
possible to use the binary operator `+
`. Instead the
functions `plus
` and `minus
` are defined. These
functions attempt to keep the same offset within a day in the
specified timezone: this means for instance that adding a day when
that day crosses a time zone adjustment such as a daylight saving
time, results in a true time increment of less or more than 24
hours to preserve the offset. Preserving the offset works for
increments that are smaller than a day too, provided the increment
results in a datetime where the timezone adjustment is valid. When
this is not the case, adding a `nanoperiod` behaves in the same
way as adding a `nanoduration`.
nanotime
, nanoduration
,
nanoival
, nanoperiod.month,nanoperiod-method
if (FALSE) {
p <- nanoperiod(months=12, days=7, duration="01:00:00")
print(p)
# when adding a \code{nanoperiod} to a \code{nanotime} or to a
# \code{nanoival}, a time zone must be specified:
y <- nanotime("1970-01-01T00:00:00+00:00")
plus(y, p, tz="America/Chicago")
}
Run the code above in your browser using DataLab