r-lib / clock

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

Can't convert day precision sys-time to POSIXct #278

Closed DavisVaughan closed 2 years ago

DavisVaughan commented 2 years ago

But you can convert a day precision naive-time, because it goes through zoned-time first and gets common typed up to second precision

library(clock)

nt <- as_naive_time(year_month_day(2019, 1, 1))
st <- as_sys_time(year_month_day(2019, 1, 1))

as.POSIXct(nt, "UTC")
#> [1] "2019-01-01 UTC"
as.POSIXct(st, "UTC")
#> Error: Can't floor to a more precise precision.

Created on 2021-12-21 by the reprex package (v2.0.1)

So it probably needs the same x <- vec_cast(x, vec_ptype2(x, naive_seconds())) trick that as_zoned_time.clock_naive_time() uses