tidyverse / hms

A simple class for storing time-of-day values
https://hms.tidyverse.org/
Other
138 stars 25 forks source link

Support `seq` for hms values #117

Open AshesITR opened 1 year ago

AshesITR commented 1 year ago

It would be nice to be able to use seq() with hms values like this:

seq(hms::hms(hours = 8), hms::hms(hours = 19), by = hms::hms(minutes = 30))
#> Error in `/.difftime`(del, by): second argument of / cannot be a "difftime" object

Created on 2023-05-24 with reprex v2.0.2

An ugly workaround is this:

hms::as_hms(seq(as.numeric(hms::hms(hours = 8)), as.numeric(hms::hms(hours = 19)), by = as.numeric(hms::hms(minutes = 30))))
#> 08:00:00
#> 08:30:00
#> 09:00:00
#> 09:30:00
#> 10:00:00
#> 10:30:00
#> 11:00:00
#> 11:30:00
#> 12:00:00
#> 12:30:00
#> 13:00:00
#> 13:30:00
#> 14:00:00
#> 14:30:00
#> 15:00:00
#> 15:30:00
#> 16:00:00
#> 16:30:00
#> 17:00:00
#> 17:30:00
#> 18:00:00
#> 18:30:00
#> 19:00:00

Created on 2023-05-24 with reprex v2.0.2