<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>293431</bug_id>
          
          <creation_ts>2025-05-22 09:18:46 -0700</creation_ts>
          <short_desc>Incorrect date formatting in Gregorian-derived calendars before 1582</short_desc>
          <delta_ts>2025-05-28 20:39:34 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Devon Govett">govett</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>karlcow</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2118990</commentid>
    <comment_count>0</comment_count>
    <who name="Devon Govett">govett</who>
    <bug_when>2025-05-22 09:18:46 -0700</bug_when>
    <thetext>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(&apos;th-TH-u-ca-buddhist&apos;)
// =&gt; &apos;22/12/2122&apos; (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&apos;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(&apos;th-TH-u-ca-buddhist&apos;) 
// =&gt; &quot;1/1/2123&quot; (correct)
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2119438</commentid>
    <comment_count>1</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2025-05-23 16:48:03 -0700</bug_when>
    <thetext>Since WebKit only uses C-ICU API, unless ucal_setGregorianChange gets fixed, we cannot do much. So this is basically ICU bug</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2119439</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-05-23 16:48:41 -0700</bug_when>
    <thetext>&lt;rdar://problem/151952896&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2119864</commentid>
    <comment_count>3</comment_count>
    <who name="Devon Govett">govett</who>
    <bug_when>2025-05-27 10:32:26 -0700</bug_when>
    <thetext>I&apos;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?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>