Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Improving time_length for 29 Feb (when dealing with date time) #295
With previous version, we had:
> naiss <- ymd_hms("1992-02-29 12:00:00") > evt <- ymd_hms("2014-03-01 01:00:00") > time_length(interval(naiss, evt), "years")  21.99874
We should consider that the anniversary occurs between 28 Feb at 23:59:59 and 1st March at 00:00:00. Therefore,
> time_length(interval(naiss, evt), "years")  22.00011
This should not happen. It's a bug in as.period.
Well. There is a mirror problem with negative intervals that use
So we will have to change %m+% as well, and I am not sure that's a good idea. %m+% will basically make all intraday timestamps for Feb 29 equal, and that's clearly not suitable for intraday analysis.
One easy solution is to add an optional argument to
When we think with time, even for negative intervals we should not use
Therefore, the code is simpler.
Now, we obtain:
> time_length(interval(ymd_hms('2000-02-29 12:00:00'), ymd_hms('1999-02-28 20:00:00')), "years")  -1.000457