moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.12k stars 728 forks source link

ISO8601 strings starting with + or - can't be parsed #1484

Closed l0drex closed 11 months ago

l0drex commented 11 months ago

Describe the bug A clear and concise description of what the bug is. ISO8601 strings can start with a + or - for dates after or before the year 0. Passing such strings to DateTime.fromISO() results in an invalid date.

To Reproduce Please share a minimal code example that triggers the problem:

DateTime.fromISO("+1923-01-25T18:51:29Z")

Actual vs Expected behavior A clear and concise description of what you expected to happen. With a +, dates should be parsed exactly as without one. Starting with a -, the date object should correspond to a time after year 0.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

https://en.wikipedia.org/wiki/ISO_8601

Happens with the Javascript Date constructor as well:

new Date("+1923-01-25T18:51:29Z")
diesieben07 commented 11 months ago

ISO 8601 does not directly permit the use of a sign for the year, "only by prior agreement between the sender and the receiver". As such this should be an option for fromISO at most, defaulting to false.

icambron commented 11 months ago

I think you're both misreading it a little. The important part is the number of extra year digits:

An expanded year representation [±YYYYY] must have an agreed-upon number of extra year digits beyond the four-digit minimum, and it must be prefixed with a + or − sign[21] instead of the more common AD/BC (or CE/BCE) notation; by convention 1 BC is labelled +0000, 2 BC is labeled −0001, and so on.

Luxon supports plus and minus with 6 digits, so you can say +001923 or -000234, etc

l0drex commented 11 months ago

Oh ok, I see. I am currently working with gedcomx dates, which are very similar to the ISO standard and got confused.