subsecond {datetimeoffset} | R Documentation |
Subsecond helper getter/setter
Description
Helper getter/setter methods for the subseconds (aka fractional seconds) of datetimeoffset()
objects.
Usage
## S3 method for class 'datetimeoffset'
get_millisecond(x)
## S3 method for class 'datetimeoffset'
set_millisecond(x, value, ..., na_set = FALSE, digits = 3L)
## S3 method for class 'datetimeoffset'
get_microsecond(x)
## S3 method for class 'datetimeoffset'
set_microsecond(x, value, ..., na_set = FALSE, digits = 6L)
get_subsecond(x, ...)
## S3 method for class 'datetimeoffset'
get_subsecond(x, digits = get_subsecond_digits(x), ...)
set_subsecond(x, value, digits = 1L, ...)
## S3 method for class 'datetimeoffset'
set_subsecond(x, value, digits = 1L, ..., na_set = FALSE)
Arguments
x |
A datetime object. |
value |
The replacement value. For |
... |
Currently ignored. |
na_set |
If |
digits |
If |
Details
Internally datetimeoffset()
objects represent subseconds with two fields:
Nanoseconds (as an integer)
Number of subsecond digits (as an integer)
One can explicitly get/set these fields with
-
get_nanosecond()
/set_nanosecond()
-
get_subsecond_digits()
/set_subsecond_digits()
We implement datetimeoffset()
support for the following S3 methods from clock
:
-
get_millisecond()
-
get_microsecond()
-
set_millisecond()
(note sets any non-zero microsecond/nanosecond elements to zero) -
set_microsecond()
(note sets any non-zero nanosecond elements to zero)
We implement the following new S3 methods:
-
get_subsecond()
-
set_subsecond()
Value
get_millisecond()
, get_microsecond()
, and get_subsecond()
returns an integer vector.
set_millisecond()
, set_microsecond()
, and set_subsecond()
returns a datetime vector.
Examples
library("clock")
dt <- as_datetimeoffset("2020-01-01T10:10:10.123456789")
format(dt)
get_millisecond(dt)
get_microsecond(dt)
get_subsecond(dt, 1L)
get_subsecond(dt, 7L)
set_microsecond(dt, 123456L)
set_millisecond(dt, 123L)
set_subsecond(dt, 12L, digits = 2L)
set_subsecond(dt, 12L, digits = 3L)