You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Usually, I'm able to run lubridate::today() + lubridate::years(1) + 7 to get the date that is exactly one week from the day that is a year from today. Maybe not the best way to do that, but that's not the actual point.
I noticed today, February 29, 2024, that lubridate::today() + lubridate::years(1) returns NA.
Expectation
On the one hand, the current behavior makes sense if you see the function as "increment the year by one," but I think I was expecting the logic to be more complex and to account for leap days. Something like: "X + lubridate::years(Y) adds 365*Y days, plus 1 day for each leap day included in the date-range [X, Z) where Z is the resulting date (but exclusive of the resulting date)".
In other words, I think I would've wanted February 29, 2024 + 1 Year to be equal to March 1st, 2025 and February 29, 2024 + 4 Years to be equal to February 29, 2028
I understand that my expected implementation is perhaps a bit more risky (maybe out of the ISO spec?). However, as it is, it's not possible (without writing workarounds) to write something that uses Date X + lubridate::year(Y) and increments Date X across a four-year span.
Anyway, I realize date times are a complex domain, so feel free to close if I'm off the mark here.
The text was updated successfully, but these errors were encountered:
Happy leap-day 😅
Notes
I'm using lubridate 1.8.0
Problem
Usually, I'm able to run
lubridate::today() + lubridate::years(1) + 7
to get the date that is exactly one week from the day that is a year from today. Maybe not the best way to do that, but that's not the actual point.I noticed today, February 29, 2024, that
lubridate::today() + lubridate::years(1)
returns NA.Expectation
On the one hand, the current behavior makes sense if you see the function as "increment the year by one," but I think I was expecting the logic to be more complex and to account for leap days. Something like: "
X + lubridate::years(Y)
adds365*Y
days, plus 1 day for each leap day included in the date-range [X, Z) where Z is the resulting date (but exclusive of the resulting date)".In other words, I think I would've wanted
February 29, 2024 + 1 Year
to be equal to March 1st, 2025 andFebruary 29, 2024 + 4 Years
to be equal to February 29, 2028Reproducible example
Some other thoughts
I understand that my expected implementation is perhaps a bit more risky (maybe out of the ISO spec?). However, as it is, it's not possible (without writing workarounds) to write something that uses
Date X + lubridate::year(Y)
and increments Date X across a four-year span.Anyway, I realize date times are a complex domain, so feel free to close if I'm off the mark here.
The text was updated successfully, but these errors were encountered: