vspinu / timechange

Efficient Updating of Date-Times
GNU General Public License v3.0
30 stars 3 forks source link

fractional units should round with respect to the parent unit #15

Closed vspinu closed 1 year ago

vspinu commented 2 years ago
floor_date(ymd_hms("2020-10-10 13:22:00"), ".6H") # round with respect to DAY
floor_date(ymd_hms("2020-10-10 13:22:00"), "40M") # round with respect to hour

https://github.com/tidyverse/lubridate/issues/925

vspinu commented 1 year ago

There is no simple and consistent way to implement this. The moment one opens a box of rounding across units a question arises why not to round across parent of the parent. For example if if .6H rounds with respect to the day origin then we would need to round both hours and minutes, and potentially seconds of the original date time.

The current implementation allows for integer multi-units and fractional sub-units map to the child unit (e.g. .6h = 40min).

I have just implemented a new argument origin which can be used with absolute units (aka durations) only. It is vectorised across the input date-time vector, thus should cover most of the use-cases.