inukshuk/edtf.js

Max property of masked dates incorrect

stevetweeddale opened this issue · 2 comments

As far as I understand it, the maximum possible extent of 20XX would be the last second of the year 2099. However it's parse as if it has year precision, so next() gives the year 2001, and .max gives you the year 2001 - 1 millisecond.

> new Date(edtf('20XX').max)
2000-12-31T23:59:59.999Z
> new Date(edtf('20XX').min)
2000-01-01T00:00:00.000Z

Looking at the code, I think this would need a bit of a refactor, with the introduction of a secondary notion of precision. Whereas currently it just knows "how many date parts we have provided" it would need to know which the most precise digit before any unknown ones is. So in this case, 20XX feels like it ought to be treated as a century instead of a year, whilst 201X would be a decade.

Well spotted!

I have to admit that I have not implemented min/max next/prev for masked dates yet -- I have some code in the parser which makes sure things like 2000-9X or 2000-02-3X will be rejected but that does not account for leap years yet. Ideally, we would use the same logic for parsing and computing min/max of masked dates.

@stevetweeddale @darthsteven I finally implemented next/max for L1/L2 unspecified dates. It would be much appreciated if you take a look at some of the test cases -- particularly L2 unspecified can be confusing so I hoping that our expectations are the same.

I pushed this as 2.0.0 because we also renamed until() to through() and reintroduced until() with slightly different semantics. See #4