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, ...)

Arguments

x

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.

tz, recursive, ...

Further arguments to be passed to individual methods.

i

Indices specifying elements to extract or replace.

value

Replacement values, either as another Rfc3339 instance, a character vector or something that can be coerced into one.

path

String containing the path to a directory in which to save x.

Value

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.

Details

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.

Author

Aaron Lun

Examples

out <- as.Rfc3339(Sys.time() + 1:10)
out
#>  [1] "2024-09-22T23:55:58+00:00" "2024-09-22T23:55:59+00:00"
#>  [3] "2024-09-22T23:56:00+00:00" "2024-09-22T23:56:01+00:00"
#>  [5] "2024-09-22T23:56:02+00:00" "2024-09-22T23:56:03+00:00"
#>  [7] "2024-09-22T23:56:04+00:00" "2024-09-22T23:56:05+00:00"
#>  [9] "2024-09-22T23:56:06+00:00" "2024-09-22T23:56:07+00:00"
#> attr(,"class")
#> [1] "Rfc3339"

out[2:5]
#> [1] "2024-09-22T23:55:59+00:00" "2024-09-22T23:56:00+00:00"
#> [3] "2024-09-22T23:56:01+00:00" "2024-09-22T23:56:02+00:00"
#> attr(,"class")
#> [1] "Rfc3339"
out[2] <- "2"
c(out, out)
#>  [1] "2024-09-22T23:55:58+00:00" NA                         
#>  [3] "2024-09-22T23:56:00+00:00" "2024-09-22T23:56:01+00:00"
#>  [5] "2024-09-22T23:56:02+00:00" "2024-09-22T23:56:03+00:00"
#>  [7] "2024-09-22T23:56:04+00:00" "2024-09-22T23:56:05+00:00"
#>  [9] "2024-09-22T23:56:06+00:00" "2024-09-22T23:56:07+00:00"
#> [11] "2024-09-22T23:55:58+00:00" NA                         
#> [13] "2024-09-22T23:56:00+00:00" "2024-09-22T23:56:01+00:00"
#> [15] "2024-09-22T23:56:02+00:00" "2024-09-22T23:56:03+00:00"
#> [17] "2024-09-22T23:56:04+00:00" "2024-09-22T23:56:05+00:00"
#> [19] "2024-09-22T23:56:06+00:00" "2024-09-22T23:56:07+00:00"
#> attr(,"class")
#> [1] "Rfc3339"

as.character(out)
#>  [1] "2024-09-22T23:55:58+00:00" NA                         
#>  [3] "2024-09-22T23:56:00+00:00" "2024-09-22T23:56:01+00:00"
#>  [5] "2024-09-22T23:56:02+00:00" "2024-09-22T23:56:03+00:00"
#>  [7] "2024-09-22T23:56:04+00:00" "2024-09-22T23:56:05+00:00"
#>  [9] "2024-09-22T23:56:06+00:00" "2024-09-22T23:56:07+00:00"
as.POSIXct(out)
#>  [1] "2024-09-22 23:55:58 UTC" NA                       
#>  [3] "2024-09-22 23:56:00 UTC" "2024-09-22 23:56:01 UTC"
#>  [5] "2024-09-22 23:56:02 UTC" "2024-09-22 23:56:03 UTC"
#>  [7] "2024-09-22 23:56:04 UTC" "2024-09-22 23:56:05 UTC"
#>  [9] "2024-09-22 23:56:06 UTC" "2024-09-22 23:56:07 UTC"