tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
527 stars 49 forks source link

No year/month/day components with `interval_pull.POSIXt` #271

Closed jerlev closed 1 year ago

jerlev commented 2 years ago

interval_pull doesn't work with POSIXt vectors when intervals are >= one day:

> biweekly <- 
      seq(from = lubridate::ymd_hms("2021-01-01 00:00:00"), 
            to = lubridate::ymd_hms("2021-12-31 00:00:00"), 
            by = "2 weeks") %>% print
[1] "2021-01-01 UTC" "2021-01-15 UTC" "2021-01-29 UTC" "2021-02-12 UTC"
 [5] "2021-02-26 UTC" "2021-03-12 UTC" "2021-03-26 UTC" "2021-04-09 UTC"
 [9] "2021-04-23 UTC" "2021-05-07 UTC" "2021-05-21 UTC" "2021-06-04 UTC"
[13] "2021-06-18 UTC" "2021-07-02 UTC" "2021-07-16 UTC" "2021-07-30 UTC"
[17] "2021-08-13 UTC" "2021-08-27 UTC" "2021-09-10 UTC" "2021-09-24 UTC"
[21] "2021-10-08 UTC" "2021-10-22 UTC" "2021-11-05 UTC" "2021-11-19 UTC"
[25] "2021-12-03 UTC" "2021-12-17 UTC" "2021-12-31 UTC"

> biweekly %>% tsibble::interval_pull()
<interval[1]>
[1] ?

There also seems to be a bug with split_period:

> biweekly %>% tsibble::gcd_interval()
Time difference of 14 days

> biweekly %>% tsibble::gcd_interval() %>% tsibble:::split_period()
$year
[1] 0

$month
[1] 0

$day
[1] 0

$hour
[1] 0

$minute
[1] 0

$second
[1] 14
earowang commented 1 year ago

Yea, we only support POSIXct for sub-daily time series data. Regarding weekly data, please use yearweek() to represent weeks. and see FAQ for details.

library(tsibble, warn.conflicts = FALSE)
biweekly <- seq(yearweek("2021 W1"), yearweek("2021 W52"), by = 2)
interval_pull(biweekly)
#> <interval[1]>
#> [1] 2W

Created on 2022-10-09 with reprex v2.0.2