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
set_day()this can also be "last".- ...
Currently ignored.
- na_set
If
TRUEset component forNAdatetimes (making them no longerNA)- digits
If
NULLdo not update thesubsecond_digitsfield. Otherwise an integer vector (1Lthrough9LorNA_integer_) to update thesubsecond_digitsfield with.
Value
get_millisecond(), get_microsecond(), and get_subsecond() returns an integer vector.
set_millisecond(), set_microsecond(), and set_subsecond() returns a datetime vector.
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
We implement datetimeoffset() support for the following S3 methods from clock:
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()
Examples
library("clock")
dt <- as_datetimeoffset("2020-01-01T10:10:10.123456789")
format(dt)
#> [1] "2020-01-01T10:10:10.123456789"
get_millisecond(dt)
#> [1] 123
get_microsecond(dt)
#> [1] 123456
get_subsecond(dt, 1L)
#> [1] 1
get_subsecond(dt, 7L)
#> [1] 1234567
set_microsecond(dt, 123456L)
#> <datetimeoffset[1]>
#> [1] 2020-01-01T10:10:10.123456
set_millisecond(dt, 123L)
#> <datetimeoffset[1]>
#> [1] 2020-01-01T10:10:10.123
set_subsecond(dt, 12L, digits = 2L)
#> <datetimeoffset[1]>
#> [1] 2020-01-01T10:10:10.12
set_subsecond(dt, 12L, digits = 3L)
#> <datetimeoffset[1]>
#> [1] 2020-01-01T10:10:10.012