r-lib / clock

A Date-Time Library for R
https://clock.r-lib.org
Other
102 stars 5 forks source link

Add "..." to "as_sys_time()" #305

Closed trevorld closed 1 year ago

trevorld commented 1 year ago

Currently

library("clock")
library("datetimeoffset") # remotes::install_github("trevorld/datetimeoffset")
dts <- c("2020-11-01T01:30:00[America/New_York]", # ambiguous sys time
         "2020-11-01T01:30:00-05:00",
         "2020-11-01T01:30:00-04:00")
dto <- as_datetimeoffset(dts)
as_sys_time(dto)
Error in `map()`:
ℹ In index: 1.
Caused by error in `stop_clock()`:
! Ambiguous time due to daylight saving time at location 1.
ℹ Resolve ambiguous time issues by specifying the `ambiguous` argument.

It could be nice to be able to support an ambiguous argument:

as_sys_time(dto, ambiguous = "NA")
<clock_sys_time[3]>
[1] NA "2020-11-01T06:30:00" "2020-11-01T05:30:00"
as_sys_time(dto, ambiguous = "earliest")
<clock_sys_time[3]>
[1] "2020-1101T05:30:00" "2020-11-01T06:30:00" "2020-11-01T05:30:00"
as_sys_time(dto, ambiguous = "latest")
<clock_sys_time[3]>
[1] "2020-1101T06:30:00" "2020-11-01T06:30:00" "2020-11-01T05:30:00"

Note since with pdf metadata datetimes we often don't know the time zone but more often know the UTC offsets the current strategy to convert to a zoned time is to first convert to a sys time and then convert to a zoned time. So converting to a zoned time (by first converting to a sys time) to then convert to a sys time would be awkward...

trevorld commented 1 year ago

In general the following {clock} coercion methods currently support ...:

The following {clock} coercion methods currently do not support ...:

DavisVaughan commented 1 year ago

Those 3 functions have ... for very specific reasons:

As mentioned elsewhere I do not currently see clock as an extensible system that you can convert in and out of from types that aren't natively supported at this time

trevorld commented 1 year ago

As mentioned elsewhere I do not currently see clock as an extensible system that you can convert in and out of from types that aren't natively supported at this time

I don't really understand why as a developer you'd want to deliberately make it harder for users/developers to get their date times into {clock}