Methods for base R's as.Date(), as.POSIXct() and as.POSIXlt(), and
temporal_to_difftime(), which stands in for as.difftime() because
base R's is not a generic. The other direction is the
constructors: plain_date(<Date>), instant(<POSIXct>),
zoned_date_time(<POSIXct>), plain_date_time(<POSIXct>),
plain_time(<difftime>) and duration(<difftime>).
Usage
# S3 method for class 'zutempo_plain_date'
as.Date(x, ...)
# S3 method for class 'zutempo_plain_date_time'
as.Date(x, ...)
# S3 method for class 'zutempo_zoned_date_time'
as.Date(x, tz = NULL, ...)
# S3 method for class 'zutempo_instant'
as.Date(x, tz = "UTC", ...)
# S3 method for class 'zutempo_instant'
as.POSIXct(x, tz = "UTC", ...)
# S3 method for class 'zutempo_zoned_date_time'
as.POSIXct(x, tz = NULL, ...)
# S3 method for class 'zutempo_plain_date_time'
as.POSIXct(x, tz, ..., disambiguation = "compatible")
# S3 method for class 'zutempo_zoned_date_time'
as.POSIXlt(x, tz = NULL, ...)
# S3 method for class 'zutempo_instant'
as.POSIXlt(x, tz = "UTC", ...)
# S3 method for class 'zutempo_plain_date_time'
as.POSIXlt(x, tz, ..., disambiguation = "compatible")
temporal_to_difftime(x, ...)
# S3 method for class 'zutempo_plain_time'
temporal_to_difftime(x, ...)
# S3 method for class 'zutempo_duration'
temporal_to_difftime(x, ..., relative_to = NULL)Arguments
- x
A zutempo value.
- ...
Must be empty.
- tz
A time zone: for an
instant(), the zone to show it in (the default is"UTC"); for aplain_date_time(), the zone its wall-clock time is in, which has no default (""is the system zone); for azoned_date_time(), a zone to show it in instead of its own.- disambiguation
For a
plain_date_time(): how to resolve a time a zone skips or repeats, as intemporal_to_zoned_date_time().- relative_to
For a
duration()with years, months or weeks: the date or zoned date-time they count from, as intemporal_total().
Details
What each conversion loses:
plain_date()toDate: nothing; both count days from 1970-01-01.instant()toPOSIXct: the nanoseconds, to the nearest double second (ties to even), which keeps about 240 ns at today's dates. The other way takes the double's exact value, rounded half to even to the nanosecond, so 0.1 s is 100 ms.zoned_date_time()toPOSIXct: asinstant(), with the zone astzone. Zones that are equal under Temporal'sTimeZoneEquals, such asAsia/CalcuttaandAsia/Kolkata, count as one, and the first one names thetzone. A vector mixing other zones gets"UTC". A whole-hour offset becomes itsEtc/GMTzone, from+14:00(Etc/GMT-14) to-12:00(Etc/GMT+12); any other offset gets"UTC", since base R cannot name it. The instant is kept either way.zoned_date_time()toPOSIXlt: the fields in each element's own zone, with its offset ingmtoff; the seconds lose precision as above. Thetzoneis chosen as forPOSIXct, so a vector mixing zones gets"UTC"with fields that are not in UTC. Such aPOSIXltdoes not round-trip: base R reads the fields in itstzone, soas.POSIXct()of it can move each element by its offset. Convert withas.POSIXct()instead, or givetzto put every element in one zone.plain_date_time()toPOSIXctorPOSIXlt: needstz, and resolves a wall-clock time a zone skips or repeats withdisambiguation, astemporal_to_zoned_date_time()does.instant(),zoned_date_time()andplain_date_time()toDate: the date, intzfor aninstant().plain_time()todifftime: seconds since midnight, as a double.duration()todifftime: its total in seconds, astemporal_total()gives it, so years, months and weeks needrelative_toand a day is 24 hours without it.
plain_year_month() and plain_month_day() have no base R counterpart;
temporal_to_plain_date() supplies the missing day or year first.
Examples
as.Date(plain_date("2026-03-07"))
#> [1] "2026-03-07"
as.POSIXct(instant("2026-03-07T12:00:00.123456789Z"))
#> [1] "2026-03-07 12:00:00 UTC"
as.POSIXct(zoned_date_time("2026-03-07T12:00[Europe/Lisbon]"))
#> [1] "2026-03-07 12:00:00 WET"
as.POSIXlt(zoned_date_time("2026-03-07T12:00[Europe/Lisbon]"))
#> [1] "2026-03-07 12:00:00 WET"
as.POSIXct(plain_date_time("2026-03-29T01:30"), tz = "Europe/Lisbon")
#> [1] "2026-03-29 02:30:00 WEST"
temporal_to_difftime(plain_time("12:30"))
#> Time difference of 45000 secs
temporal_to_difftime(duration("P1M"), relative_to = "2026-02-01")
#> Time difference of 2419200 secs
# And back.
plain_date(as.Date("2026-03-07"))
#> <zutempo_plain_date[1]>
#> [1] 2026-03-07
instant(as.POSIXct("2026-03-07 12:00:00", tz = "UTC"))
#> <zutempo_instant[1]>
#> [1] 2026-03-07T12:00:00Z
duration(as.difftime(90, units = "mins"))
#> <zutempo_duration[1]>
#> [1] PT5400S