Bug 293431
Summary: | Incorrect date formatting in Gregorian-derived calendars before 1582 | ||
---|---|---|---|
Product: | WebKit | Reporter: | Devon Govett <govett> |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | NEW | ||
Severity: | Normal | CC: | karlcow, webkit-bug-importer, ysuzuki |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari Technology Preview | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Devon Govett
When formatting dates before 1582 in Gregorian-derived calendars such as buddhist and japanese, the month and day are incorrect.
```
new Date(1580, 0, 1).toLocaleDateString('th-TH-u-ca-buddhist')
// => '22/12/2122' (incorrect)
```
As discussed in https://github.com/tc39/ecma402/issues/1003, all of these calendars should be defined as proleptic - meaning they extend before the Gregorian Calendar was invented in 1582.
WebKit overrides ICU's default Gregorian cutover date here: https://github.com/WebKit/WebKit/blob/c35dad9edf1cbad19d9af6749d43c7329eada970/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp#L958-L961, however this only applies to the Gregorian Calendar itself and not to its subclasses due to this code in ICU: https://github.com/unicode-org/icu/blob/b30c63d1b930610850489a67433b9c3ba55d6f43/icu4c/source/i18n/ucal.cpp#L298-L310. Seems like this should be overridden for all Gregorian-based calendars.
Looks like Firefox has already made this change in version 139 beta and in that version returns the correct result:
```
new Date(1580, 0, 1).toLocaleDateString('th-TH-u-ca-buddhist')
// => "1/1/2123" (correct)
```
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Yusuke Suzuki
Since WebKit only uses C-ICU API, unless ucal_setGregorianChange gets fixed, we cannot do much. So this is basically ICU bug
Radar WebKit Bug Importer
<rdar://problem/151952896>
Devon Govett
I'm not sure whether ICU is planning on changing their behavior, but based on the code for ucal_setGregorianChange, it seems like maybe you could cast the pointer to the equivalent C++ Calendar API and use that directly?