The Rfc3339 class is a character vector that stores Internet Date/time timestamps, formatted as described in RFC3339. It provides a faithful representation of any RFC3339-compliant string in an R session.
as.Rfc3339(x)
# S3 method for class 'character'
as.Rfc3339(x)
# Default S3 method
as.Rfc3339(x)
# S3 method for class 'POSIXt'
as.Rfc3339(x)
# S3 method for class 'Rfc3339'
as.character(x, ...)
is.Rfc3339(x)
# S3 method for class 'Rfc3339'
as.POSIXct(x, tz = "", ...)
# S3 method for class 'Rfc3339'
as.POSIXlt(x, tz = "", ...)
# S3 method for class 'Rfc3339'
x[i]
# S3 method for class 'Rfc3339'
x[[i]]
# S3 method for class 'Rfc3339'
x[i] <- value
# S3 method for class 'Rfc3339'
x[[i]] <- value
# S3 method for class 'Rfc3339'
c(..., recursive = TRUE)
# S4 method for class 'Rfc3339'
saveObject(x, path, ...)
For as.Rfc3339
methods, object to be coerced to an Rfc3339 instance.
For the subset and combining methods, an Rfc3339 instance.
For as.character
, as.POSIXlt
and as.POSIXct
methods, an Rfc3339 instance.
For is.Rfc3339
, any object to be tested for Rfc3339-ness.
Further arguments to be passed to individual methods.
Indices specifying elements to extract or replace.
Replacement values, either as another Rfc3339 instance, a character vector or something that can be coerced into one.
String containing the path to a directory in which to save x
.
For as.Rfc3339
, the subset and combining methods, an Rfc3339 instance is returned.
For the other as.*
methods, an instance of the corresponding type generated from an Rfc3339 instance.
This class is motivated by the difficulty in using the various POSIXt classes to faithfully represent any RFC3339-compliant string. In particular:
The POSIXt classes do not automatically capture the string's timezone offset, instead converting all times to the local timezone.
This is problematic as it discards information about the original timezone.
Technically, the POSIXlt class is capable of holding this information in the gmtoff
field but it is not clear how to set this.
There is no way to distinguish between the timezones Z
and +00:00
.
These are functionally the same but will introduce differences in the checksums of saved files
and thus interfere with deduplication mechanisms in storage backends.
Coercion of POSIXt classes to strings may print more or fewer digits in the fractional seconds than what was present in the original string. Functionally, this is probably unimportant but will still introduce differences in the checksums.
By comparison, the Rfc3339 class preserves all information in the original string,
avoiding unexpected modifications from a roundtrip through readObject
and saveObject
.
This is especially relevant for strings that were created from other languages,
e.g., Node.js Date's ISO string conversion uses Z
by default.
That said, users should not expect too much from this class. It is only used to provide a faithful representation of RFC3339 strings, and does not support any time-related arithmetic. Users are advised to convert to POSIXct or similar if such operations are required.
out <- as.Rfc3339(Sys.time() + 1:10)
out
#> [1] "2025-02-20T19:32:18+00:00" "2025-02-20T19:32:19+00:00"
#> [3] "2025-02-20T19:32:20+00:00" "2025-02-20T19:32:21+00:00"
#> [5] "2025-02-20T19:32:22+00:00" "2025-02-20T19:32:23+00:00"
#> [7] "2025-02-20T19:32:24+00:00" "2025-02-20T19:32:25+00:00"
#> [9] "2025-02-20T19:32:26+00:00" "2025-02-20T19:32:27+00:00"
#> attr(,"class")
#> [1] "Rfc3339"
out[2:5]
#> [1] "2025-02-20T19:32:19+00:00" "2025-02-20T19:32:20+00:00"
#> [3] "2025-02-20T19:32:21+00:00" "2025-02-20T19:32:22+00:00"
#> attr(,"class")
#> [1] "Rfc3339"
out[2] <- "2"
c(out, out)
#> [1] "2025-02-20T19:32:18+00:00" NA
#> [3] "2025-02-20T19:32:20+00:00" "2025-02-20T19:32:21+00:00"
#> [5] "2025-02-20T19:32:22+00:00" "2025-02-20T19:32:23+00:00"
#> [7] "2025-02-20T19:32:24+00:00" "2025-02-20T19:32:25+00:00"
#> [9] "2025-02-20T19:32:26+00:00" "2025-02-20T19:32:27+00:00"
#> [11] "2025-02-20T19:32:18+00:00" NA
#> [13] "2025-02-20T19:32:20+00:00" "2025-02-20T19:32:21+00:00"
#> [15] "2025-02-20T19:32:22+00:00" "2025-02-20T19:32:23+00:00"
#> [17] "2025-02-20T19:32:24+00:00" "2025-02-20T19:32:25+00:00"
#> [19] "2025-02-20T19:32:26+00:00" "2025-02-20T19:32:27+00:00"
#> attr(,"class")
#> [1] "Rfc3339"
as.character(out)
#> [1] "2025-02-20T19:32:18+00:00" NA
#> [3] "2025-02-20T19:32:20+00:00" "2025-02-20T19:32:21+00:00"
#> [5] "2025-02-20T19:32:22+00:00" "2025-02-20T19:32:23+00:00"
#> [7] "2025-02-20T19:32:24+00:00" "2025-02-20T19:32:25+00:00"
#> [9] "2025-02-20T19:32:26+00:00" "2025-02-20T19:32:27+00:00"
as.POSIXct(out)
#> [1] "2025-02-20 19:32:18 UTC" NA
#> [3] "2025-02-20 19:32:20 UTC" "2025-02-20 19:32:21 UTC"
#> [5] "2025-02-20 19:32:22 UTC" "2025-02-20 19:32:23 UTC"
#> [7] "2025-02-20 19:32:24 UTC" "2025-02-20 19:32:25 UTC"
#> [9] "2025-02-20 19:32:26 UTC" "2025-02-20 19:32:27 UTC"