moment / luxon

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

Intl parsing fromFormat problem with Persian calendar converting #1315

Closed erfanatp closed 1 year ago

erfanatp commented 1 year ago

Describe the bug Assume this code, works fine for converting a "fr" year to a "fa" year.

DateTime.fromFormat("mai 25 2002", "LLLL dd yyyy", { locale: "fr" }).reconfigure({
  outputCalendar: "persian",
  locale: "fa",
}).toLocaleString(DateTime.DATE_FULL); // returns: ۴ خرداد ۱۳۸۱

The "۱۳۸۱" in Persian means: 1381, exactly 20 years ago (This year is 1401 in the Persian calendar) Let's see the same approach for the Persian calendar:

DateTime.fromFormat("خرداد 04 1381", "LLLL dd yyyy", { locale: "fa" }).reconfigure({
  outputCalendar: "en",
  locale: "en",
}).toLocaleString(DateTime.DATE_FULL); // returns: June 4, 1381

As you see, the reverse way returns 1381(which means 641 years ago!!!). It seems it can't convert the Persian year to the Gregorian year.

Tested on:

diesieben07 commented 1 year ago

Support for calendars other than Gregorian and ISO week is limited to formatting, they cannot be used for parsing. See the documentation on Output calendars. In your second example the year is parsed as a gregorian year.

icambron commented 1 year ago

@diesieben07 is correct