as-zoned-time-Date {clock} | R Documentation |
Convert to a zoned-time from a date
Description
This is a Date method for the as_zoned_time()
generic.
clock assumes that Dates are naive date-time types. Like naive-times, they have a yet-to-be-specified time zone. This method allows you to specify that time zone, keeping the printed time. If possible, the time will be set to midnight (see Details for the rare case in which this is not possible).
Usage
## S3 method for class 'Date'
as_zoned_time(x, zone, ..., nonexistent = NULL, ambiguous = NULL)
Arguments
x |
A Date. |
zone |
The zone to convert to. |
... |
These dots are for future extensions and must be empty. |
nonexistent |
One of the following nonexistent time resolution strategies, allowed to be either length 1, or the same length as the input:
Using either If If |
ambiguous |
One of the following ambiguous time resolution strategies, allowed to be either length 1, or the same length as the input:
Alternatively, Finally, If If |
Details
In the rare instance that the specified time zone does not contain a
date-time at midnight due to daylight saving time, nonexistent
can be used
to resolve the issue. Similarly, if there are two possible midnight times due
to a daylight saving time fallback, ambiguous
can be used.
Value
A zoned-time.
Examples
x <- as.Date("2019-01-01")
# The resulting zoned-times have the same printed time, but are in
# different time zones
as_zoned_time(x, "UTC")
as_zoned_time(x, "America/New_York")
# Converting Date -> zoned-time is the same as naive-time -> zoned-time
x <- as_naive_time(year_month_day(2019, 1, 1))
as_zoned_time(x, "America/New_York")
# In Asia/Beirut, there was a DST gap from
# 2021-03-27 23:59:59 -> 2021-03-28 01:00:00,
# skipping the 0th hour entirely. This means there is no midnight value.
x <- as.Date("2021-03-28")
try(as_zoned_time(x, "Asia/Beirut"))
# To resolve this, set a `nonexistent` time resolution strategy
as_zoned_time(x, "Asia/Beirut", nonexistent = "roll-forward")