UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

887 lines (885 loc) • 29.8 kB
import { Temporal } from "../temporal.js"; // src/internal/temporalCompat/probeRepros.ts const MAX_ISO = "+275760-09-13"; const MIN_ISO = "-271821-04-19"; /** `year|monthCode|day` of an ISO date read in `calendar`. */ function readFields(iso, calendar) { const date = Temporal.PlainDate.from(iso).withCalendar(calendar); return `${date.year}|${date.monthCode}|${date.day}`; } function fieldsToIso(calendar, year, month, day) { return Temporal.PlainDate.from({ calendar, year, month, day }, { overflow: "reject" }).withCalendar("iso8601").toString(); } /** D1: fields → ISO probes outside the legacy `Date` range near both limits and throws. */ const d1Repros = [ [ "buddhist", -271278, 4, 19, 276303, 9, 13 ], [ "hebrew", -268058, 11, 4, 279517, 10, 11 ], [ "indian", -271899, 1, 29, 275682, 6, 22 ], [ "islamic-civil", -280804, 3, 21, 283583, 5, 23 ], [ "islamic-tbla", -280804, 3, 22, 283583, 5, 24 ], [ "islamic-umalqura", -280804, 3, 21, 283583, 5, 23 ], [ "persian", -272442, 1, 9, 275139, 7, 12 ], [ "ethioaa", -266323, 3, 23, 281247, 5, 22 ] ].flatMap(([calendar, minY, minM, minD, maxY, maxM, maxD]) => [{ defect: "D1", calendar, name: "fieldsMax", expected: MAX_ISO, run: () => fieldsToIso(calendar, maxY, maxM, maxD) }, { defect: "D1", calendar, name: "fieldsMin", expected: MIN_ISO, run: () => fieldsToIso(calendar, minY, minM, minD) }]); /** * D10 (tc39/proposal-temporal#3329): proposal-temporal #3292 gave `calendarToIsoDate` a fixed 8-day * search step, which skips a 5- or 6-day month 13 in far years and trips an assertion. Polyfill * 0.5.1 predates #3292 and passes; these rows catch a js-temporal release that ports #3292 without * the #3329 fix. GMT computes coptic and ethiopic in ethioaa (`calendarSystemIds.ts`), so ethioaa * is the only id probed. Chromium 153 native Temporal: ethioaa 18196 (coptic 12420 + 5776). */ const d10Repros = [ { defect: "D10", calendar: "ethioaa", name: "fieldsFarMonth13", expected: "+012704-11-26", run: () => fieldsToIso("ethioaa", 18196, 13, 1) }, { defect: "D10", calendar: "ethioaa", name: "fieldsFarMonth12", expected: "+012704-11-25", run: () => fieldsToIso("ethioaa", 18196, 12, 30) }, { defect: "D11", calendar: "iso8601", name: "totalMonthFromDay31", expected: "1.0161290322580645", run: () => monthTotal("2024-01-31T00:00:00", "2024-02-29T12:00:00") }, { defect: "D11", calendar: "iso8601", name: "totalMonthFromDay31ShortTarget", expected: "1.0161290322580645", run: () => monthTotal("2023-01-31T00:00:00", "2023-02-28T12:00:00") }, { defect: "D11", calendar: "iso8601", name: "totalMonthFromDay31ThirtyDayTarget", expected: "1.0161290322580645", run: () => monthTotal("2024-03-31T00:00:00", "2024-04-30T12:00:00") }, { defect: "D11", calendar: "iso8601", name: "roundMonthFromDay31Floor", expected: "P1M", run: () => monthRound("P29DT12H", "2024-01-31", "floor") }, { defect: "D11", calendar: "iso8601", name: "roundMonthFromDay30Ceil", expected: "P2M", run: () => monthRound("P30DT12H", "2024-01-30", "ceil") }, { defect: "D11", calendar: "iso8601", name: "untilMonthFromDay31Trunc", expected: "P1M", run: () => monthUntil("2024-01-31T00:00:00", "2024-02-29T12:00:00", "trunc") } ]; /** * `Duration#total({ unit: "month" })` for the span between two ISO datetimes, as a string. * * TC39 TotalRelativeDuration divides the leftover by the length of the month the *end* falls in — * the span from `relativeTo` plus the whole months to `relativeTo` plus one more. The polyfill * divides by the month that ends there instead, so any `relativeTo` on the 29th, 30th or 31st, * where adding a month constrains the day, gets a fraction over the wrong denominator. */ function monthTotal(start, end) { const from = Temporal.PlainDateTime.from(start); return String(from.until(Temporal.PlainDateTime.from(end), { largestUnit: "month" }).total({ unit: "month", relativeTo: from })); } /** * `Duration#round` and `PlainDateTime#until` to a calendar unit, as strings. * * Same window as `monthTotal`: the directed rounding modes take the answer from whichever bound the * target sits nearest, so a window that does not contain the target loses a whole unit rather than a * fraction of one. */ function monthRound(duration, relativeTo, roundingMode) { return Temporal.Duration.from(duration).round({ smallestUnit: "month", roundingMode, relativeTo: Temporal.PlainDate.from(relativeTo) }).toString(); } function monthUntil(start, end, roundingMode) { return Temporal.PlainDateTime.from(start).until(Temporal.PlainDateTime.from(end), { largestUnit: "month", smallestUnit: "month", roundingMode }).toString(); } function isoOf(date) { return date.withCalendar("iso8601").toString(); } function monthsUntil(calendar, from, to) { return Temporal.PlainDate.from(from).withCalendar(calendar).until(Temporal.PlainDate.from(to).withCalendar(calendar), { largestUnit: "months" }).toString(); } /** * D1 in add and until: the same out-of-range probe as fields → ISO. Expected values are Chromium 152 * native Temporal (q2-xscan-chromium152.json): `until(+275760-07-01, max)` is `edge.max[74]`, the * add rows are `edge.buddhist.max[366]` and `edge["islamic-civil"].min[400]`. */ const d1ArithmeticRepros = [ ...[ ["hebrew", "P2M15D"], ["buddhist", "P2M12D"], ["islamic-civil", "P2M15D"], ["islamic-tbla", "P2M15D"], ["islamic-umalqura", "P2M15D"], ["persian", "P2M12D"], ["indian", "P2M12D"], ["ethioaa", "P2M14D"] ].map(([calendar, expected]) => ({ defect: "D1", calendar, name: "untilNearMax", expected, run: () => monthsUntil(calendar, "+275760-07-01", MAX_ISO) })), { defect: "D1", calendar: "buddhist", name: "addNearMax", expected: MAX_ISO, run: () => isoOf(Temporal.PlainDate.from("+275759-09-13").withCalendar("buddhist").add({ years: 1 })) }, { defect: "D1", calendar: "islamic-civil", name: "subtractNearMin", expected: "-271821-06-03", run: () => isoOf(Temporal.PlainDate.from("-271820-05-23").withCalendar("islamic-civil").subtract({ years: 1 })) } ]; /** * D6: `until` re-constrains the day while counting months. The spec's NonISODateSurpasses compares * the un-constrained day, so a month-end start does not reach a shorter month's end. Hebrew and * ethioaa are test262 `wrapping-at-end-of-month-{hebrew,ethioaa}.js`; the rest are Chromium 152 * (q2-grid-chromium152.json, the first D6 row of each calendar), and gregory is Chromium 153 * (added to `CalendarSystem` in CORE-8; gregory months and days are ISO's, and ISO's own * `ISODateSurpasses` gives the same P30D). */ const d6Repros = [...[ [ "buddhist", "2023-08-31", "2023-09-30", "P30D" ], [ "gregory", "2023-08-31", "2023-09-30", "P30D" ], [ "japanese", "2023-08-31", "2023-09-30", "P30D" ], [ "roc", "2023-08-31", "2023-09-30", "P30D" ], [ "persian", "2023-09-22", "2023-10-22", "P30D" ], [ "indian", "2023-09-22", "2023-10-22", "P30D" ], [ "islamic-civil", "2023-06-19", "2023-07-18", "P29D" ], [ "islamic-tbla", "2023-06-18", "2023-07-17", "P29D" ], [ "islamic-umalqura", "2023-07-18", "2023-08-16", "P29D" ] ].map(([calendar, from, to, expected]) => ({ defect: "D6", calendar, name: "monthEnd", expected, run: () => monthsUntil(calendar, from, to) })), ...[[ "hebrew", 5783, "M07", 30, "M08", 29, "P29D" ], [ "ethioaa", 1970, "M12", 28, "M13", 5, "P7D" ]].map(([calendar, year, fromCode, fromDay, toCode, toDay, expected]) => ({ defect: "D6", calendar, name: "monthEnd", expected, run: () => Temporal.PlainDate.from({ calendar, year, monthCode: fromCode, day: fromDay }, { overflow: "reject" }).until(Temporal.PlainDate.from({ calendar, year, monthCode: toCode, day: toDay }, { overflow: "reject" }), { largestUnit: "months" }).toString() }))]; /** * D7: `until` with `largestUnit: "years"` from a leap-year `M05L` date throws "mixed-sign" * (tc39/proposal-temporal#3159). Chromium 152: ISO 2024-02-11 + 384 days is `P12M29D`. */ const d7Repro = { defect: "D7", calendar: "hebrew", name: "mixedSign", expected: "P12M29D", run: () => Temporal.PlainDate.from({ calendar: "hebrew", year: 5784, month: 6, day: 2 }).until(Temporal.PlainDate.from({ calendar: "hebrew", year: 5785, month: 6, day: 1 }), { largestUnit: "years" }).toString() }; /** * D7, the leap-month end: from the last day of `M05L` (Adar I 30) in leap year 5784 to Adar 29 of * common year 5785, by years. The intermediate `5784-M05L-30 + 1 year` constrains to Adar 29, which * equals the end date, so upstream counts a whole year; `NonISODateSurpasses` compares the * unconstrained day (30 > 29) and gives `P12M29D`. Spec and Chromium: `P12M29D`. Polyfill 0.5.1 * returns `P1Y`, and so does a js-temporal main build with `10aeb98` + `0e32ee0`: the `mixedSign` * probe alone would report D7 removable while this row is still wrong * (`context/domination/js-temporal-polyfill-bugs.md` § C, C-D7b). */ const d7LeapMonthEndRepro = { defect: "D7", calendar: "hebrew", name: "leapMonthEnd", expected: "P12M29D", run: () => Temporal.PlainDate.from({ calendar: "hebrew", year: 5784, monthCode: "M05L", day: 30 }).until(Temporal.PlainDate.from({ calendar: "hebrew", year: 5785, monthCode: "M06", day: 29 }), { largestUnit: "years" }).toString() }; /** * D1 in `Duration` rounding: a calendared `relativeTo` near the maximum reaches the same fields -> * ISO probe. Chromium 153: P40D from Hebrew 279517-08-15 is 1 month (M08 has 30 days) and 10 days. */ const d1RelativeToRepro = { defect: "D1", calendar: "hebrew", name: "relativeTo", expected: "P1M10D", run: () => Temporal.Duration.from("P40D").round({ largestUnit: "months", relativeTo: Temporal.PlainDate.from({ calendar: "hebrew", year: 279517, month: 8, day: 15 }) }).toString() }; function readRepro(defect, calendar, iso, expected) { return { defect, calendar, name: iso, expected, run: () => readFields(iso, calendar) }; } /** The epoch nanoseconds `Temporal.ZonedDateTime.from(item)` reads, or the error's name. */ function zonedStringEpoch(item) { try { return String(Temporal.ZonedDateTime.from(item).epochNanoseconds); } catch (error) { return error instanceof Error ? error.name : "Error"; } } /** * D12 (`internal/zonedWallClock.ts` defect 4): `ToTemporalZonedDateTime` matches a string's * offset against the zone by minutes even when the offset is written with seconds, where TC39 * requires match-exactly ("If offsetParseResult contains more than one MinuteSecond Parse Node, * set matchBehaviour to match-exactly"). Expected values: test262 * `test/intl402/Temporal/ZonedDateTime/from/zoneddatetime-sub-minute-offset.js` ("rounded * HH:MM:SS not accepted in string offset (offset=reject)", and the Pacific/Niue edge case, * "-11:20:00 is accepted as -11:20:00": `reference + 20_000_000_000n`). The test writes the * Monrovia time as `T12`; `T12:00` is the same wall time. */ const d12Repros = [{ defect: "D12", calendar: "iso8601", name: "roundedSecondsRejected", expected: "RangeError", run: () => zonedStringEpoch("1970-01-01T12:00-00:45:00[Africa/Monrovia]") }, { defect: "D12", calendar: "iso8601", name: "exactSecondsSecondPass", expected: "-543069601000000000", run: () => zonedStringEpoch("1952-10-15T23:59:59-11:20:00[Pacific/Niue]") }]; /** More `Intl.DateTimeFormat#format` reads than this for one transition lookup is a stalled search. */ const D13_INTL_READ_LIMIT = 2e4; /** * `run()`'s output, or a note when it made more than `D13_INTL_READ_LIMIT` reads through * `Intl.DateTimeFormat.prototype.format`, where the read then throws so a search that would never * return stops. Polyfill 0.5.1 reads every offset through that getter. */ function withBoundedOffsetReads(run) { const prototype = Intl.DateTimeFormat.prototype; const original = Object.getOwnPropertyDescriptor(prototype, "format"); const originalGet = original?.get; if (original === void 0 || originalGet === void 0) return "cannot bound Intl.DateTimeFormat#format"; let reads = 0; Object.defineProperty(prototype, "format", { configurable: true, get() { const format = originalGet.call(this); return (date) => { reads++; if (reads > D13_INTL_READ_LIMIT) throw new RangeError(`more than ${D13_INTL_READ_LIMIT} offset reads`); return format(date); }; } }); try { return run(); } finally { Object.defineProperty(prototype, "format", original); } } /** America/Boa_Vista's 2000-10-08T04:00:00Z advance (−04:00 → −03:00, local midnight skipped). */ const BOA_VISTA_ADVANCE = "2000-10-08T01:00:00-03:00[America/Boa_Vista]"; /** * D13 (`internal/zonedWallClock.ts` defect 5): `GetNamedTimeZoneNextTransition` and * `…PreviousTransition` sample the offset every 14 days. Two changes inside one step that return * to the same offset are skipped (America/Boa_Vista 2000-10-08 and 2000-10-15, 601,200 s apart), * so `GetStartOfDay` for the skipped midnight of 2000-10-08 fails too; three different offsets in * one step (Europe/Riga 1944-10-02 and 1944-10-12) make `bisect` loop for ever, its assertion * compiled out. Spec: TC39 Temporal `GetNamedTimeZoneNextTransition`, "the smallest integer * greater than epochNanoseconds" at which the offset changes. Expected values: Node 26.10.0's * native Temporal and `zdump -v` (tz 2026c). The polyfill's main branch (a79c6a1, per-zone search * windows, in no release) fixes the zones it lists but leaves `bisect` unchanged, and its 17-day * window for Africa/El_Aaiun holds three offsets in 1976: `stall.nextElAaiun` covers that, so the * workaround stays until every repro here passes. * * Order matters: the capability probe stops at the first failing repro, so the `skip.*` repros, * which cannot stall, come before `stall.*`, which a runtime that fails them never runs in * process. The canary runs `stall.*` under `withBoundedOffsetReads`. */ const d13Repros = [ { defect: "D13", calendar: "iso8601", name: "skip.nextBoaVista", expected: BOA_VISTA_ADVANCE, run: () => String(Temporal.Instant.from("2000-10-01T12:00:00Z").toZonedDateTimeISO("America/Boa_Vista").getTimeZoneTransition("next")) }, { defect: "D13", calendar: "iso8601", name: "skip.previousBoaVista", expected: "2000-10-14T23:00:00-04:00[America/Boa_Vista]", run: () => String(Temporal.Instant.from("2000-10-20T12:00:00Z").toZonedDateTimeISO("America/Boa_Vista").getTimeZoneTransition("previous")) }, { defect: "D13", calendar: "iso8601", name: "skip.startOfDayBoaVista", expected: BOA_VISTA_ADVANCE, run: () => String(Temporal.PlainDate.from("2000-10-08").toZonedDateTime("America/Boa_Vista")) }, { defect: "D13", calendar: "iso8601", name: "skip.hoursInDayNoronha", expected: "23", run: () => String(Temporal.ZonedDateTime.from("2000-10-08T12:00[America/Noronha]").hoursInDay) }, { defect: "D13", calendar: "iso8601", name: "stall.nextRiga", expected: "1944-10-02T02:00:00+01:00[Europe/Riga]", run: () => withBoundedOffsetReads(() => String(Temporal.Instant.from("1944-04-15T12:00:00Z").toZonedDateTimeISO("Europe/Riga").getTimeZoneTransition("next"))) }, { defect: "D13", calendar: "iso8601", name: "stall.nextSimferopol", expected: "1944-04-03T03:00:00+02:00[Europe/Simferopol]", run: () => withBoundedOffsetReads(() => String(Temporal.Instant.from("1943-10-15T12:00:00Z").toZonedDateTimeISO("Europe/Simferopol").getTimeZoneTransition("next"))) }, ...["1976-04-14T00:30:00Z", "1976-03-28T00:30:00Z"].map((from) => ({ defect: "D13", calendar: "iso8601", name: `stall.nextElAaiun ${from}`, expected: "1976-04-14T01:00:00+00:00[Africa/El_Aaiun]", run: () => withBoundedOffsetReads(() => String(Temporal.Instant.from(from).toZonedDateTimeISO("Africa/El_Aaiun").getTimeZoneTransition("next"))) })) ]; /** * D14 (`internal/zonedWallClockOperations.ts` `roundZonedDateTime`): rounding to the day in a zone * where a date starts twice. Antarctica/Casey went from +11 to +08 at 2010-03-05T02:00, so * 2010-03-04 runs again from 23:00+08:00. `Temporal.ZonedDateTime.prototype.round` clamps the * instant to the end of that date ("Set thisNs to min(thisNs, endNs - 1)", tc39/ecma262#3966, * commit 5f44331e0a11; tc39/proposal-temporal#3312), so `trunc` gives the first midnight. Expected * value: test262 * `test/intl402/Temporal/ZonedDateTime/prototype/round/same-date-starts-twice.js`. A runtime that * throws (V8 in Node 26) or answers the next date fails the repro. */ const d14Repros = [{ defect: "D14", calendar: "iso8601", name: "dayRoundClamp", expected: "2010-03-04T00:00:00+11:00[Antarctica/Casey]", run: () => String(Temporal.ZonedDateTime.from("2010-03-04T23:10:00+08:00[Antarctica/Casey]").round({ smallestUnit: "day", roundingMode: "trunc" })) }]; /** * D15 (`internal/zonedWallClock.ts` defect 6): `ToTemporalZonedDateTime` reads a `Z` string as an * exact instant under every `offset` option. It sets `offsetBehaviour` to ~exact~ for a UTC * designator, and `InterpretISODateTimeOffset` applies `ignore` only when `offsetBehaviour` is * ~option~ (step 3: "If offsetBehaviour is ~wall~, or offsetBehaviour is ~option~ and offsetOption * is ~ignore~"). The polyfill applies `ignore` first and reads the wall clock in the zone: London * is on +01:00 in July, so `2022-07-08T00:14:07Z[Europe/London]` gives `2022-07-07T23:14:07Z`. * Expected value: the string's own instant (spec text above); Node 24.21's native Temporal * shares the polyfill's answer, so it is not an oracle here. */ const d15Repros = [{ defect: "D15", calendar: "iso8601", name: "zIgnoreIsExact", expected: "2022-07-08T00:14:07Z", run: () => Temporal.ZonedDateTime.from("2022-07-08T00:14:07Z[Europe/London]", { offset: "ignore" }).toInstant().toString() }]; const d16Repros = [ "short", "long", "shortGeneric", "longGeneric", "shortOffset", "longOffset" ].map((style) => ({ defect: "D16", calendar: "iso8601", name: `range.${style}`, expected: "same", run: () => { const format = new Intl.DateTimeFormat("en", { hour: "numeric", minute: "numeric", timeZone: "+01:00", timeZoneName: style }); const zonePart = (parts) => JSON.stringify(parts.find((part) => part.type === "timeZoneName")?.value ?? null); const range = zonePart(format.formatRangeToParts(0, 36e5)); const single = zonePart(format.formatToParts(0)); return range === single ? "same" : `range ${range} vs single ${single}`; } })); /** * D17 (`zoned/format/formatZonedRange.ts`): SpiderMonkey (Firefox 155) `formatRange` writes the * AM/PM day period where `dayPeriod` asks for a flexible one, when `timeZoneName` is also set and * neither `hourCycle` nor `hour12` is. ECMA-402 §11.5.8 picks the range pattern by the resolved * [[HourCycle]] only, and en-US resolves to h12 with or without an explicit `hourCycle: "h12"`, * yet the explicit one prints the flexible period and the omitted one AM/PM, so identical resolved * options give two range outputs. The repro compares the range's day period parts with those of * the two single formats, so it owns no CLDR string. The instants are 10:00 and 12:00 in `+01:00`. */ const d17Repros = [{ defect: "D17", calendar: "iso8601", name: "range.dayPeriod", expected: "same", run: () => { const format = new Intl.DateTimeFormat("en", { hour: "numeric", dayPeriod: "short", timeZone: "+01:00", timeZoneName: "short" }); const dayPeriods = (parts) => parts.filter((part) => part.type === "dayPeriod").map((p) => p.value); const range = JSON.stringify(dayPeriods(format.formatRangeToParts(324e5, 396e5))); const single = JSON.stringify([...dayPeriods(format.formatToParts(324e5)), ...dayPeriods(format.formatToParts(396e5))]); return range === single ? "same" : `range ${range} vs single ${single}`; } }]; /** * D18 (`calendarFields.ts`, `islamicEra.ts`): in WebKit (JavaScriptCore, Safari and Playwright * WebKit 26.6), `Intl.DateTimeFormat` prints an `islamic-civil`, `islamic-tbla` or * `islamic-umalqura` date before the Hijra as a positive year in a second era (`Before Hijra`), * and polyfill 0.5.1 (`IslamicBaseHelper`, no era) takes the year part as printed, so ISO * `0621-01-01` reads as year 2 instead of -1. V8 and SpiderMonkey print the year as -1 in the * one era. Expected values are Node 26.12.1's native Temporal (`bh` era year 2 = year -1), as the * Intl era/monthCode proposal numbers the years. Reads only: the polyfill's fields → ISO and * `until` for such a year do not return in WebKit, so no probe may ask them. */ const d18Repros = [ readRepro("D18", "islamic-civil", "0621-01-01", "-1|M05|28"), readRepro("D18", "islamic-civil", "0500-01-01", "-126|M09|12"), readRepro("D18", "islamic-tbla", "0621-01-01", "-1|M05|29"), readRepro("D18", "islamic-tbla", "0500-01-01", "-126|M09|13"), readRepro("D18", "islamic-umalqura", "0621-01-01", "-1|M05|28"), readRepro("D18", "islamic-umalqura", "0500-01-01", "-126|M09|12") ]; /** * D19 (`internal/zonedWallClockDifference.ts`): `ZonedDateTime#equals` answers false for two * identifiers of one zone on a host whose `Intl.DateTimeFormat#resolvedOptions` returns the * identifier as written. The polyfill's `GetAvailableNamedTimeZoneIdentifier` finds the primary * identifier in `Intl.supportedValuesOf("timeZone")` or, for a non-primary one, takes * `resolvedOptions().timeZone`. ECMA-402 §6.5 (Time Zone Identifiers) says "UTC" is primary and * "Etc/UTC" is a non-primary identifier that resolves to "UTC", and TimeZoneEquals compares the * primary identifiers, so `Etc/UTC` equals `UTC` on every host. JavaScriptCore (WebKit 26.6, Safari * 27) keeps the identifier as written (the Time Zone Canonicalization proposal), so the polyfill * compares `Etc/UTC` with `UTC` there and answers false. V8 and SpiderMonkey return the primary * identifier. The repro names the one pair the specification fixes, so it owns no time zone data. */ const d19Repros = [{ defect: "D19", calendar: "iso8601", name: "etcUtcEqualsUtc", expected: "true", run: () => String(new Temporal.ZonedDateTime(0n, "Etc/UTC").equals(new Temporal.ZonedDateTime(0n, "UTC"))) }]; /** * D20 (`temporalCompat/isoCalendarFrom.ts`): `ParseTemporalMonthDayString` and `ParseTemporalYearMonthString` compare the `u-ca` value * with `"iso8601"` as written, so an upper-case calendar annotation throws "MM-DD format is only * valid with iso8601 calendar" on a month-day and "YYYY-MM format is only valid with iso8601 * calendar" on a year-month. Temporal ParseISODateTime lower-cases the value first, for goal * TemporalMonthDayString with no DateYear and for goal TemporalYearMonthString with no DateDay: * "If calendar is not empty and the ASCII-lowercase of calendar is not "iso8601", throw a * RangeError exception". tc39 * `385b479bf8` aligned the reference polyfill. A throw counts as a failed repro. */ const d20Repros = [{ defect: "D20", calendar: "iso8601", name: "upperCaseIsoCalendarOnMonthDay", expected: "12-25", run: () => Temporal.PlainMonthDay.from("--12-25[u-ca=ISO8601]").toString() }, { defect: "D20", calendar: "iso8601", name: "upperCaseIsoCalendarOnYearMonth", expected: "2026-10", run: () => Temporal.PlainYearMonth.from("2026-10[u-ca=ISO8601]").toString() }]; /** * D22 (`internal/zonedDifference/nudgeOrigin.ts`): a zoned `relativeTo` or start in either pass of a * repeated hour is mismeasured. TC39 `ComputeNudgeWindow` takes the window's start from the origin's * own exact time when no unit has been added (tc39/proposal-temporal#3148 for `total`, #3149 for * `round`), and `DifferenceZonedDateTime` subtracts the exact times when both fall on one local date * (#3141). Polyfill 0.5.1 turns the wall clock back into an exact time with `"compatible"`, which takes * the earlier pass, and backs up a day when the end falls in the later pass at a lower wall clock. New * York repeats 01:00-02:00 on 2024-11-03, so from 01:30-05:00 the next day is 24 hours away and from * 01:30-04:00 it is 25. Expected values: Chromium 153 native Temporal. * * `roundWeekWithoutStartDays` passes on 0.5.1. js-temporal `main` (`3c403686d39`) tests `r1 = 0` where * tc39/ecma262#3759 commit `1f4e6717ef23` tests for an empty start duration, which fails it. It keeps * the probe failing until a release carries both fixes. * * The last three read lengths with no spec value, where a TC39 Assert fails, and GMT returns its * sentinel. They keep the probe failing until a release reports no value for all of them, because * removing the workaround before then would turn a sentinel back into a number. * - `totalsWithNoValue`, `NudgeToCalendarUnit` (tc39/proposal-temporal#3336) and * `CombineDateAndTimeDuration` (#3311): Chromium 153 throws and 0.5.1 extrapolates. * - `noDayCorrection`, `DifferenceZonedDateTime` (#3311): Chromium 153 and 0.5.1 both answer `PT45M`. * - `emptyDaySpan`, `NudgeToZonedTime` (#3310): 0.5.1 throws and Chromium 153 answers `-P1DT12H`. */ const LATER_PASS = "2024-11-03T01:30:00-05:00[America/New_York]"; const EARLIER_PASS = "2024-11-03T01:30:00-04:00[America/New_York]"; /** * What `read` returns for a length from `origin`, or `"none"` when it throws. A thrown message and * type vary by engine and build: Chromium throws a `RangeError`, a debug polyfill's assert an `Error`. * Only the read can report no value, so `origin` and `duration` are parsed outside the `try`. A zone * this engine lacks, or an offset its data disagrees with, fails the repro rather than passing it, and * so does a `TypeError`, which is a broken read. */ function readOrNone(origin, duration, read) { const zoned = Temporal.ZonedDateTime.from(origin); const length = Temporal.Duration.from(duration); try { return String(read(length, zoned)); } catch (error) { if (error instanceof TypeError) throw error; return "none"; } } const NO_CORRECTION_FROM = "1944-10-01T00:00:59-07:00[America/Phoenix]"; const d22Repros = [ { defect: "D22", calendar: "iso8601", name: "totalDaysFromLaterPass", expected: "0.041666666666666664", run: () => String(Temporal.Duration.from("PT1H").total({ unit: "day", relativeTo: LATER_PASS })) }, { defect: "D22", calendar: "iso8601", name: "roundToDayFromLaterPass", expected: "PT0S", run: () => Temporal.Duration.from("PT11H45M").round({ smallestUnit: "day", relativeTo: LATER_PASS }).toString() }, { defect: "D22", calendar: "iso8601", name: "untilSameDayFromLaterPass", expected: "PT1H", run: () => { const start = Temporal.ZonedDateTime.from(LATER_PASS); return start.until(start.add({ hours: 1 }), { largestUnit: "day" }).toString(); } }, { defect: "D22", calendar: "iso8601", name: "totalDaysFromEarlierPass", expected: "0.02", run: () => String(Temporal.Duration.from("PT30M").total({ unit: "day", relativeTo: EARLIER_PASS })) }, { defect: "D22", calendar: "iso8601", name: "roundWeekWithoutStartDays", expected: "P1W", run: () => Temporal.Duration.from("P7D").round({ largestUnit: "week", smallestUnit: "day", relativeTo: LATER_PASS }).toString() }, { defect: "D22", calendar: "iso8601", name: "totalsWithNoValue", expected: "none,none", run: () => `${readOrNone("2024-11-02T01:30:00-04:00[America/New_York]", "PT24H30M", (length, zoned) => length.total({ unit: "day", relativeTo: zoned }))},${readOrNone("1944-10-01T00:00:59-06:00[America/Phoenix]", "PT15M", (length, zoned) => length.total({ unit: "month", relativeTo: zoned }))}` }, { defect: "D22", calendar: "iso8601", name: "noDayCorrection", expected: "none,none", run: () => `${readOrNone(NO_CORRECTION_FROM, "-PT15M", (length, zoned) => length.round({ largestUnit: "day", relativeTo: zoned }).toString())},${readOrNone(NO_CORRECTION_FROM, "-PT15M", (length, zoned) => zoned.until(zoned.add(length), { largestUnit: "day" }).toString())}` }, { defect: "D22", calendar: "iso8601", name: "emptyDaySpan", expected: "none", run: () => readOrNone("1995-01-01T12:00:00+13:00[Pacific/Enderbury]", "-PT43199S", (length, zoned) => length.round({ largestUnit: "day", smallestUnit: "minute", relativeTo: zoned }).toString()) } ]; /** The shipped-probe groups, each in the order the full table places it. */ const probeReproGroups = { d1: d1Repros, d1Arithmetic: d1ArithmeticRepros, d1RelativeTo: [d1RelativeToRepro], d10: d10Repros, d12: d12Repros, d13: d13Repros, d14: d14Repros, d15: d15Repros, d16: d16Repros, d17: d17Repros, d18: d18Repros, d19: d19Repros, d20: d20Repros, d22: d22Repros, d6: d6Repros, d7: [d7Repro, d7LeapMonthEndRepro], /** D2-D5 and D8: single-read repros. */ reads: [ readRepro("D2", "buddhist", "1000-01-01", "1543|M01|1"), readRepro("D2", "buddhist", "1582-10-04", "2125|M10|4"), { defect: "D3", calendar: "hebrew", name: "-100000-01-01", expected: "12", run: () => String(Temporal.PlainDate.from("-100000-01-01").withCalendar("hebrew").monthsInYear) }, readRepro("D4", "hebrew", "-271821-11-05", "-268057|M05|28"), readRepro("D4", "hebrew", "-003761-09-01", "0|M01|13"), readRepro("D5", "indian", "-000500-06-15", "-578|M03|25"), ...[ ["1800-01-01", "ce|1800"], ["1872-12-31", "ce|1872"], ["0000-12-31", "bce|1"] ].map(([iso, expected]) => ({ defect: "D8", calendar: "japanese", name: iso, expected, run: () => { const date = Temporal.PlainDate.from(iso).withCalendar("japanese"); return `${date.era}|${date.eraYear}`; } })) ] }; /** Every repro a shipped capability probe reads. */ const probeRepros = Object.values(probeReproGroups).flat(); export { probeReproGroups, probeRepros, readOrNone };