Repository navigation
Conversation
…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.
Collaborator
Author
|
Status Reproduced with the 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 Hegiraenode 26.3.0 on the same ICU 78.3 prints The Bun pull request that pins the preview build and adds the tests: oven-sh/bun#47107. |
|
Preview build of ea4f330: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
format()printsSaf. 10, 1054 Before HijraandformatRangeToParts(d, d)printsSaf. 10, -1053 Anno Hegirae. ECMA-402 gives both the same parts.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 printMuh. 1, 0 Before Hijra.@js-temporal/polyfill0.5.1 readsformatToParts():Temporal.PlainYearMonth.from("0622-07-25[u-ca=islamic-civil]")does not return in 10 s (1.4 GB).Fix
islamic-civil,islamic-tbla,islamic-umalquraandcopticprint ICU's era and year from every method: V8's text on ICU 78.3 for a Number or a Date.#pragma GCC poisonfails a merge that brings it back.stress/intl-datetimeformat.jsand the newstress/bun-intl-datetimeformat-pre-epoch-era-one-text.jsfail on the base and pass here.Background
era.jssee two era texts.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
formatToParts/era.jsfails (1 of 3,357 intl402 files), as in node 26.3.0.-1053 AHwhere Temporal reports erabh, eraYear 1054.Notes
The question for a maintainer. With this change test262
test/intl402/DateTimeFormat/prototype/formatToParts/era.jsgoes 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'sIslamicCalendarandCopticCalendar, 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-umalquraorcoptic(or the aliasesislamicandislamicc), a pattern with a year (noeraoption 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/polyfill0.5.1 it needs less: the polyfill takes the year fromformatToParts(). 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):
sv, islamic-tbla, era long, ISO -400-01-15:format()/formatRangeToParts(d, d)11 Saf. 1054 Before Hijra/11 Saf. \u22121053 efter Hirja11 Saf. \u22121053 efter Hirjafrom bothen, coptic, the same dateToba 24, 685 Anno Martyrum/Toba 24, 685Toba 24, 685from bothen, islamic-civil, era shortSaf. 10, 1054 Before HijraSaf. 10, -1053 AHen, islamic-civil,{year, month, day}, no era optionSaf. 10, 1054 Before HijraSaf. 10, -1053 AHen, islamic-civil, UTC, 622-07-19T00:00Z to 07:52:57ZMuh. 1, 0 Before HijraMuh. 1, 1 Anno Hegiraeja, islamic-civilBefore Hijra1054年2月10日AH-1053年2月10日ar-u-nu-arab, islamic-civil, the year part1054\u061c-\u0661\u0660\u0665\u0663Temporal.PlainMonthDaywith a reference year before the epoch,en, islamic-civilRaj. 11 Before HijraRaj. 11Saf. 10, -1053 \u2013 Saf. 22, -1052 Anno Hegirae(no override)The coptic text is one for ISO -400 and ISO 969: 685 is ICU's year of the era before the epoch.
@js-temporal/polyfill0.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})andfrom("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
jscof this change (fork commit 680ef47 plus this diff, the sameIntlDateTimeFormat.cppblob 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 areera.jsin default and strict mode. The entry inexpectations-linux.yamlcomes from--save. The same entry inexpectations.yamlis not verified on a Mac.format()andformatRangeToParts(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 fromformat()in 24,069 of 43,380. ATemporal.PlainDategets two texts in 40,156 of 46,500. Change: 0 in each.error: attempt to use a poisoned identifierwith 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-amd64release tarballs):--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 fewerWTF::equalcalls). 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 aTemporal.PlainDate: 5 to 94 fewer. No case is higher.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.otext: 9,959 bytes less (121,102 to 111,143,llvm-size).formatWithEraOverride(4,452 bytes) andflippedEraOverrideYear(466 bytes) are gone.buildFormattedDateTimeParts: 9,616 to 5,928 bytes.jsctext: 9,696 bytes less.jsc: 0 in each count (base: 43,256, 33,309, 2,649, 24,069 of 43,380, 40,156 of 46,500).jscand this branch'sexpectations-linux.yaml: 6,686 runs, 24 failures, 0 new failures, 0 new passes. With the base's file the 2 new failures areera.jsin default and strict mode.testjob of this pull request (all of JSTests) passes on its 6 lanes.@js-temporal/polyfill0.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
proposalEraOverrideStringunderUSE(BUN_JSC_ADDITIONS)is 3 lines and gives the same text. On a scratch build it keeps the gate in bothformat()overloads, the checks of each part inbuildFormattedDateTimeParts(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.
testjob. It is handed off as separate work.test/js/web/intl/intl.test.ts).chineseanddangidates 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 sameislamcal.cppandcoptccal.cppas 78.3.