nanotime(x)
"nanotime"(x)
"nanotime"(x)
"nanotime"(x)
"nanotime"(x)
"nanotime"(x)
"nanotime"(x)
"nanotime"(x)
"print"(x, ...)
"format"(x, justify = "right", digits = NULL, na.encode = FALSE, trim = TRUE, ...)
"index2char"(x, frequency = NULL, ...)
"as.POSIXct"(x, tz, ...)
"as.POSIXlt"(x, tz, ...)
"as.Date"(x, ...)
"as.data.frame"(x, ...)
"as.integer64"(x, ...)
"Ops"(e1, e2)
nanotime
format
method but ignored hereformat
method but ignored hereformat
method but ignored hereformat
method but ignored hereindex2char
method but ignored hereas.POSIXct
and as.POSIXlt
,
can be set via options("nanotimeFormat")
and uses UTC as
a default and fallbacknanotime
nanotime
Date
or
POSIXct
objects for the former, and difftime
for the later. Here we (currently) only have time points,
but they are effectively also durations relative to the
epoch of January 1, 1970.bit64
package for integer64
types to represent nanoseconds relative to the epoch. This is
similar to POSIXct
which uses fractional seconds since the
epoch---so here we are essentially having the same values, but
multiplied by 10 to the power 9 and stored as integers. We need
to rely on the external package as we require 64 bit integers
whereas R itself onky has 32 bit integers. The
bit64
package is clever about how it manages to
provide such an integer using only the 64-bit double type and very
clever (and efficient) transformations. The other is the CCTZ library in C++, which we access via the
RcppCCTZ
package. CCTZ extends the C++11 standard
library type chrono
type in very useful ways for time zones and
localtime. We use its formating and parsing features.nanotime
objects is
done by functions from the RcppCCTZ
package relying
on code from its embedded CCTZ
library. The default format
is ISO3339 compliant: %Y-%m-%dT%H:%M:%E9S%Ez
. It
specifies a standard ISO 8601 part for date and time --- as well
as nine digits of precision for fractional seconds (down to
nanoseconds) and on offset (typically zero as we default to UTC).
It can be overriden by using options()
with the key of
nanotimeFormat
and a suitable value. Similarly,
nanotimeTz
can be used to select a different timezone.x <- nanotime("1970-01-01T00:00:00.000000001+00:00")
print(x)
x <- x + 1
print(x)
format(x)
x <- x + 10
print(x)
format(x)
format(nanotime(Sys.time()) + 1:3) # three elements each 1 ns apart
Run the code above in your browser using DataLab