Skip to content

[JSC] Intl.DateTimeFormat: remove the era override for dates before an islamic or coptic epoch - #922

Draft
robobun wants to merge 1 commit into
mainfrom
robobun/4e797182/intl-dtf-no-pre-epoch-era-override
Draft

robobun wants to merge 1 commit into
mainfrom
robobun/4e797182/intl-dtf-no-pre-epoch-era-override

Conversation

@robobun

@robobun robobun commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Draft: a maintainer must accept that test262 formatToParts/era.js fails again.

Problem

  • For a date before an islamic or the coptic epoch, format() prints Saf. 10, 1054 Before Hijra and formatRangeToParts(d, d) prints Saf. 10, -1053 Anno Hegirae. ECMA-402 gives both the same parts.
  • Upstream's proposalEraOverrideString (runtime/IntlDateTimeFormat.cpp, 318428@main) rewrites ICU's era and year on 4 of 11 output paths, in English. The first 7 h 52 min of 1 AH print Muh. 1, 0 Before Hijra.
  • @js-temporal/polyfill 0.5.1 reads formatToParts(): Temporal.PlainYearMonth.from("0622-07-25[u-ca=islamic-civil]") does not return in 10 s (1.4 GB).

Fix

  • Remove the override. islamic-civil, islamic-tbla, islamic-umalqura and coptic print ICU's era and year from every method: V8's text on ICU 78.3 for a Number or a Date.
  • A #pragma GCC poison fails a merge that brings it back.
  • Verified: stress/intl-datetimeformat.js and the new stress/bun-intl-datetimeformat-pre-epoch-era-one-text.js fail on the base and pass here.

Background

  • ICU's islamic calendars have one era: before the Hijra the year is 0 or less. Upstream's override is a stopgap that makes test262 era.js see two era texts.
  • Considered an early return under USE(BUN_JSC_ADDITIONS) (gate and 4.6 KB stay), the override on range paths (true ranges still differ), an ICU patch (macOS links the system ICU).

Downsides

  • test262 formatToParts/era.js fails (1 of 3,357 intl402 files), as in node 26.3.0.
  • Intl prints -1053 AH where Temporal reports era bh, eraYear 1054.
  • The fork's delta to upstream in this file grows from +2/-1 to +14/-185.
Notes

The question for a maintainer. With this change test262 test/intl402/DateTimeFormat/prototype/formatToParts/era.js goes from pass to fail: islamic-civil eras (Anno Hegirae,Anno Hegirae) should be unique. node 26.3.0 fails it with the same message. V8 and SpiderMonkey skip the file. SpiderMonkey's skip names ICU-23327 ("Before Hijri era not implemented in ICU"). No job of this repository or of oven-sh/bun runs test262. If that failure is not acceptable, the route that keeps the file passing is a patch to ICU's IslamicCalendar and CopticCalendar, on top of this same deletion. That patch does not reach macOS, where Bun links the system ICU.

Upstream chose the override. 318428@main calls it a stopgap (ICU4C-WORKAROUND: rdar://182953351) and declines to extend it to the range methods. 318847@main and 319172@main reworked it. Upstream's tests pin its limits (English text, era width ignored). WebKit main has the same block today. It came into Bun with oven-sh/bun#39371 and is in Bun 1.4.0 to 1.4.3.

Reach. No user reported it in oven-sh/bun or oven-sh/WebKit. A regression sweep of the maintainers found it. Natively it needs a formatter with islamic-civil, islamic-tbla, islamic-umalqura or coptic (or the aliases islamic and islamicc), a pattern with a year (no era option is needed, the CLDR patterns of these calendars have an era next to a year), and a date before 622-07-19 (284-08-29 for coptic). Through @js-temporal/polyfill 0.5.1 it needs less: the polyfill takes the year from formatToParts(). northguild/gmt#370 reports the same override through Safari and Playwright WebKit.

What the override prints (Bun 1.4.3-canary 367d939d9, then node 26.3.0 on the same ICU 78.3):

case Bun 1.4.3 node 26.3.0
sv, islamic-tbla, era long, ISO -400-01-15: format() / formatRangeToParts(d, d) 11 Saf. 1054 Before Hijra / 11 Saf. \u22121053 efter Hirja 11 Saf. \u22121053 efter Hirja from both
en, coptic, the same date Toba 24, 685 Anno Martyrum / Toba 24, 685 Toba 24, 685 from both
en, islamic-civil, era short Saf. 10, 1054 Before Hijra Saf. 10, -1053 AH
en, islamic-civil, {year, month, day}, no era option Saf. 10, 1054 Before Hijra Saf. 10, -1053 AH
en, islamic-civil, UTC, 622-07-19T00:00Z to 07:52:57Z Muh. 1, 0 Before Hijra Muh. 1, 1 Anno Hegirae
ja, islamic-civil Before Hijra1054年2月10日 AH-1053年2月10日
ar-u-nu-arab, islamic-civil, the year part 1054 \u061c-\u0661\u0660\u0665\u0663
a Temporal.PlainMonthDay with a reference year before the epoch, en, islamic-civil Raj. 11 Before Hijra Raj. 11
a true range, ISO -400 to -399 Saf. 10, -1053 \u2013 Saf. 22, -1052 Anno Hegirae (no override) the same

The coptic text is one for ISO -400 and ISO 969: 685 is ICU's year of the era before the epoch.

@js-temporal/polyfill 0.5.1, islamic-civil. Eight operations, each with a limit of 20 s. node 26.3.0 returns all eight in under 20 ms. Bun 1.4.3: PlainDate.from({year: 1, month: 1, day: 1}), from({year: 1, month: 1, day: 2}), from({year: -100, month: 1, day: 1}) and from("2025-06-15").subtract({years: 1450}) do not return. Three return a wrong value (from("0622-07-20").subtract({days: 1}) has year 0, node: 1). One is right.

Runs with a debug jsc of this change (fork commit 680ef47 plus this diff, the same IntlDateTimeFormat.cpp blob as the base, bundled ICU 78.3, Linux x64):

  • Tools/Scripts/run-jsc-stress-tests --filter intl-datetimeformat: 517 of 517 runs pass (39 files, 17 modes). On the base 34 fail: the two files named above, in 17 modes each.
  • Tools/Scripts/test262-runner -o test/intl402: 6,686 runs. Base: 22 failures, all expected. Change: 24. The two new ones are era.js in default and strict mode. The entry in expectations-linux.yaml comes from --save. The same entry in expectations.yaml is not verified on a Mac.
  • A sweep of 620 locales, 17 option shapes and 5 dates before the epoch (52,700 cases). Base: format() and formatRangeToParts(d, d) differ in 43,256. 33,309 print an English era in a locale that is not English. 2,649 print ASCII year digits under another numbering system. The start year of a true range differs from format() in 24,069 of 43,380. A Temporal.PlainDate gets two texts in 40,156 of 46,500. Change: 0 in each.
  • The same texts as node 26.3.0 for a Number or a Date in every case I compared. V8 formats a Temporal value with a pattern that it builds apart, so that text can differ in layout.
  • The pragma: a use of one of the three names is error: attempt to use a poisoned identifier with clang 23 for Linux, Darwin and Windows targets.

Measurements on CI builds (base 191c6a4 against this pull request's preview build ea4f330, the bun-webkit-linux-amd64 release tarballs):

  • Instructions per call (gdb single-step from entry to return, --useJIT=false, 30 warm-up calls, two measured calls that agree). format(), pattern with no era: 6,784 (base 6,788). Era field in another calendar: 7,458 (base 7,531, 4 fewer WTF::equal calls). A date of today in the four calendars: 67 to 131 fewer. A date before the epoch, islamic-civil: 7,818 (base 13,428). formatToParts(): 10,257 (base 10,369). formatRangeToParts(d, d): 19,850 (base 19,960). format() of a Temporal.PlainDate: 5 to 94 fewer. No case is higher.
  • Allocator calls per format(): 4 and 4 for a gregorian formatter, 5 and 5 for islamic-civil today, 22 fewer for an islamic-civil date before the epoch (27 to 5). Syscalls per call: 0 in both.
  • IntlDateTimeFormat.cpp.o text: 9,959 bytes less (121,102 to 111,143, llvm-size). formatWithEraOverride (4,452 bytes) and flippedEraOverrideYear (466 bytes) are gone. buildFormattedDateTimeParts: 9,616 to 5,928 bytes. jsc text: 9,696 bytes less.
  • The sweep of 52,700 cases with the preview's jsc: 0 in each count (base: 43,256, 33,309, 2,649, 24,069 of 43,380, 40,156 of 46,500).
  • test262 intl402 with the preview's jsc and this branch's expectations-linux.yaml: 6,686 runs, 24 failures, 0 new failures, 0 new passes. With the base's file the 2 new failures are era.js in default and strict mode.
  • The test job of this pull request (all of JSTests) passes on its 6 lanes.
  • @js-temporal/polyfill 0.5.1 on a debug build of Bun with this preview (Bump WebKit: Intl.DateTimeFormat prints one text for a date before an islamic or coptic epoch bun#47107): 8 of 8 probed operations return node's value (Bun 1.4.3: 1 of 8).

Delete, not guard. An early return in proposalEraOverrideString under USE(BUN_JSC_ADDITIONS) is 3 lines and gives the same text. On a scratch build it keeps the gate in both format() overloads, the checks of each part in buildFormattedDateTimeParts (9,516 bytes against 5,838) and 4,566 bytes more text than the deletion. The deletion costs a conflict each time upstream edits the block. Fork delta in this file against upstream 23b0720: +14/-185 in 11 hunks (fork main: +2/-1 in 2 hunks).

At a sync. JSTests/BUN-TEST-DIFFERENCES.md ("Intl.DateTimeFormat prints ICU's own era and year") has the rule: a conflict in this file whose fork side is empty resolves to the fork side, and the check is that a grep for the removed names prints the pragma only.

Not in this pull request.

  • A test262 intl402 step in the test job. It is handed off as separate work.
  • The one-text check for every supported calendar. It is in the Bun pull request that pins this build (test/js/web/intl/intl.test.ts).
  • chinese and dangi dates in the far future (year +071968): format() returns a space and the other three methods throw, with and without this change. node throws from all four. It is handed off as separate work.

ICU. ICU-23327 is the missing era before the Hijra (named by SpiderMonkey's skip of era.js). ICU-23277 is the coptic calendar's second era (unicode-org/icu#4081, open). ICU main has the same islamcal.cpp and coptccal.cpp as 78.3.

…n islamic or coptic epoch

For a date before the epoch of islamic-civil, islamic-tbla,
islamic-umalqura or coptic, upstream replaces ICU's era and year
(318428@main, ICU4C-WORKAROUND rdar://182953351) in format() and
formatToParts(), and so in formatRange() of two Numbers or Dates that
print as one date. formatRangeToParts(), formatRange() of Temporal values
and every true range keep ICU's text. One formatter gave two texts for
one date: "Saf. 10, 1054 Before Hijra" and "Saf. 10, -1053 Anno Hegirae".
ECMA-402 gives a range of two practically equal dates the parts of the
single date (PartitionDateTimeRangePattern).

The override text was English in every locale and ignored the era width.
Its epoch was one fixed instant, 07:52:58Z, so the first hours of 1 AH in
UTC were "Muh. 1, 0 Before Hijra". @js-temporal/polyfill 0.5.1 reads its
calendar fields from formatToParts(): with the override,
Temporal.PlainYearMonth.from("0622-07-25[u-ca=islamic-civil]") did not
return, and the process had 1.4 GB after 10 s.

Remove the override. In these four calendars every method prints ICU's
own era and year. For a Number or a Date that is the text V8 prints on
the same ICU 78.3. A #pragma GCC poison keeps a merge from bringing the
override back.

test262 intl402/DateTimeFormat/prototype/formatToParts/era.js now fails,
as it does in node 26.3.0. V8 and SpiderMonkey skip that file. It has an
entry in the test262 expectations. stress/intl-datetimeformat.js has the
fork's values, and "Intl.DateTimeFormat prints ICU's own era and year" in
BUN-TEST-DIFFERENCES.md describes them.
@robobun

robobun commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status

Reproduced with the jsc shell of fork build 191c6a4 and with Bun 1.4.3-canary (367d939d9) on Linux x64:

const d = Date.UTC(-400, 0, 15);
const f = new Intl.DateTimeFormat("en", { calendar: "islamic-civil", timeZone: "UTC", era: "long", year: "numeric", month: "short", day: "numeric" });
print(f.format(d));                                           // Saf. 10, 1054 Before Hijra
print(f.formatRangeToParts(d, d).map(p => p.value).join("")); // Saf. 10, -1053 Anno Hegirae

node 26.3.0 on the same ICU 78.3 prints Saf. 10, -1053 Anno Hegirae from both. The jsc of this pull request's preview build does too.

The Bun pull request that pins the preview build and adds the tests: oven-sh/bun#47107.

@github-actions

Copy link
Copy Markdown

Preview build of ea4f330: autobuild-preview-pr-922-ea4f330e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants