r-lib / clock

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

Need specialized `diff()` method for calendar / time point types #364

Open DavisVaughan opened 5 months ago

DavisVaughan commented 5 months ago

For the size 0 case, where vctrs / base R assume you would return vec_ptype(x), but in reality you need to return an empty duration object with the right precision.

That is also a reason that diff.Date() exists.

diff(clock::year_month_day(2000, 2))
#> <year_month_day<month>[0]>

(should be duration_months(integer()))

Can probably check length and then pass on to vctrs method if long enough, also keep in mind lag and difference arguments, because they affect this too