February 29th on unspecified year
SylvainBigonneau opened this issue · 2 comments
Using v2.7.1, here is another tricky corner case:
> edtf('21XX-02-29').edtf // expecting '21XX-02-29'
'21XX-03-01'
Since some unspecified year components can match leap years, the library should not move that date to March.
But then we should be careful! Because some other unspecified years such as "21X3" never match a leap year and should therefore behave accordingly.
But right now, the behavior is basically depending on whether the "chosen builtin date" is a leap year, which gives inconsistent results:
> edtf('24XX-02-29').edtf // expecting '24XX-02-29'... good
'24XX-02-29'
> edtf('21XX-02-29').edtf // expecting '21XX-02-29'... wrong
'21XX-03-01'
Would it be possible to check whether there is a matching leap year among the ones matching the year component, and set the Date element to the first occuring leap year?
Ha, yes, that's a good one!
We should think about this carefully, as you say, because this could easily get out of hand. Since the only thing we should be looking to achieve here is consistency, I think we might be able to do something along the lines of:
- Do nothing unless the input is
02-29
(I think if it's any other day, we're fine, regardless of which year we default to) - If the input is Feb 29, then set the year to the first leap year that also matches the range.
- If there is no such year then I think the current behavior is correct.
Looks great.
We can also wonder about the desired result of edtf("201X-02-28").next()
and edtf("201X-03-01").prev()
in that case.