format-temporal 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"formatTemporal.d.ts","sourceRoot":"","sources":["../src/formatTemporal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,QAAQ,CAAC,OAAO,GAChB,QAAQ,CAAC,cAAc,GACvB,QAAQ,CAAC,aAAa,GACtB,QAAQ,CAAC,aAAa,GACtB,QAAQ,CAAC,SAAS,GAClB,QAAQ,CAAC,SAAS,GAClB,QAAQ,CAAC,aAAa,CAAC;AAE3B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,aACf,mBAAmB,UACrB,IAAI,CAAC,cAAc,KAC1B,MAoBF,CAAC"}
1
+ {"version":3,"file":"formatTemporal.d.ts","sourceRoot":"","sources":["../src/formatTemporal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,QAAQ,CAAC,OAAO,GAChB,QAAQ,CAAC,cAAc,GACvB,QAAQ,CAAC,aAAa,GACtB,QAAQ,CAAC,aAAa,GACtB,QAAQ,CAAC,SAAS,GAClB,QAAQ,CAAC,SAAS,GAClB,QAAQ,CAAC,aAAa,CAAC;AAE3B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,mBAAmB,EAC7B,QAAQ,IAAI,CAAC,cAAc,KAC1B,MAoBF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatTemporal.js","sourceRoot":"","sources":["../src/formatTemporal.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,QAA6B,EAC7B,MAA2B,EACnB,EAAE;IACV,QAAQ,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACrC,KAAK,wBAAwB;YAC3B,OAAO,QAAQ,CAAC,cAAc,CAAC,SAAS,EAAE;gBACxC,GAAI,MAAM,CAAC,eAAe,EAAiC;gBAC3D,QAAQ,EAAE,SAAS;aACpB,CAAC,CAAC;QACL,KAAK,yBAAyB;YAC5B,OAAQ,QAAoC,CAAC,cAAc,CAAC,SAAS,EAAE;gBACrE,GAAI,MAAM,CAAC,eAAe,EAAiC;gBAC3D,QAAQ,EAAG,QAAoC,CAAC,UAAU;aAC3D,CAAC,CAAC;QACL,KAAK,wBAAwB;YAC3B,OAAQ,QAAmC,CAAC,cAAc,CAAC,SAAS,EAAE;gBACpE,GAAI,MAAM,CAAC,eAAe,EAAiC;gBAC3D,QAAQ,EAAG,QAAmC,CAAC,UAAU;aAC1D,CAAC,CAAC;QACL;YACE,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { Intl, Temporal } from \"temporal-spec\";\n\n/**\n * A type that can be formatted using {@link formatTemporal}.\n */\nexport type TemporalFormattable =\n | Temporal.Instant\n | Temporal.PlainYearMonth\n | Temporal.PlainMonthDay\n | Temporal.PlainDateTime\n | Temporal.PlainDate\n | Temporal.PlainTime\n | Temporal.ZonedDateTime;\n\n/**\n * Formats a {@link TemporalFormattable} with the provided {@link Intl.DateTimeFormat}.\n *\n * Three types of Temporal objects cannot be directly formatted with {@link Intl.DateTimeFormat#format}:\n * - {@link Temporal.ZonedDateTime}\n * - {@link Temporal.PlainYearMonth}\n * - {@link Temporal.PlainMonthDay}\n * This function formats these other types by calling their `toLocaleString` method directly.\n *\n * @param temporal The {@link TemporalFormattable} to format.\n * @param format The {@link Intl.DateTimeFormat} to use for formatting.\n * @returns\n */\nexport const formatTemporal = (\n temporal: TemporalFormattable,\n format: Intl.DateTimeFormat,\n): string => {\n switch (temporal[Symbol.toStringTag]) {\n case \"Temporal.ZonedDateTime\":\n return temporal.toLocaleString(undefined, {\n ...(format.resolvedOptions() as Intl.DateTimeFormatOptions),\n timeZone: undefined,\n });\n case \"Temporal.PlainYearMonth\":\n return (temporal as Temporal.PlainYearMonth).toLocaleString(undefined, {\n ...(format.resolvedOptions() as Intl.DateTimeFormatOptions),\n calendar: (temporal as Temporal.PlainYearMonth).calendarId,\n });\n case \"Temporal.PlainMonthDay\":\n return (temporal as Temporal.PlainMonthDay).toLocaleString(undefined, {\n ...(format.resolvedOptions() as Intl.DateTimeFormatOptions),\n calendar: (temporal as Temporal.PlainMonthDay).calendarId,\n });\n default:\n return format.format(temporal);\n }\n};\n"]}
1
+ {"version":3,"file":"formatTemporal.js","sourceRoot":"","sources":["../src/formatTemporal.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,QAA6B,EAC7B,MAA2B,EACnB,EAAE;IACV,QAAQ,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACrC,KAAK,wBAAwB;YAC3B,OAAO,QAAQ,CAAC,cAAc,CAAC,SAAS,EAAE;gBACxC,GAAI,MAAM,CAAC,eAAe,EAA4C;gBACtE,QAAQ,EAAE,SAAS;aACpB,CAAC,CAAC;QACL,KAAK,yBAAyB;YAC5B,OAAQ,QAAoC,CAAC,cAAc,CAAC,SAAS,EAAE;gBACrE,GAAI,MAAM,CAAC,eAAe,EAA4C;gBACtE,QAAQ,EAAG,QAAoC,CAAC,UAAU;aAC3D,CAAC,CAAC;QACL,KAAK,wBAAwB;YAC3B,OAAQ,QAAmC,CAAC,cAAc,CAAC,SAAS,EAAE;gBACpE,GAAI,MAAM,CAAC,eAAe,EAA4C;gBACtE,QAAQ,EAAG,QAAmC,CAAC,UAAU;aAC1D,CAAC,CAAC;QACL;YACE,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { Intl, Temporal } from \"temporal-spec\";\n\n/**\n * A type that can be formatted using {@link formatTemporal}.\n */\nexport type TemporalFormattable =\n | Temporal.Instant\n | Temporal.PlainYearMonth\n | Temporal.PlainMonthDay\n | Temporal.PlainDateTime\n | Temporal.PlainDate\n | Temporal.PlainTime\n | Temporal.ZonedDateTime;\n\n/**\n * Formats a {@link TemporalFormattable} with the provided {@link Intl.DateTimeFormat}.\n *\n * Three types of Temporal objects cannot be directly formatted with {@link Intl.DateTimeFormat#format}:\n * - {@link Temporal.ZonedDateTime}\n * - {@link Temporal.PlainYearMonth}\n * - {@link Temporal.PlainMonthDay}\n * This function formats these other types by calling their `toLocaleString` method directly.\n *\n * @param temporal The {@link TemporalFormattable} to format.\n * @param format The {@link Intl.DateTimeFormat} to use for formatting.\n * @returns\n */\nexport const formatTemporal = (\n temporal: TemporalFormattable,\n format: Intl.DateTimeFormat,\n): string => {\n switch (temporal[Symbol.toStringTag]) {\n case \"Temporal.ZonedDateTime\":\n return temporal.toLocaleString(undefined, {\n ...(format.resolvedOptions() as globalThis.Intl.DateTimeFormatOptions),\n timeZone: undefined,\n });\n case \"Temporal.PlainYearMonth\":\n return (temporal as Temporal.PlainYearMonth).toLocaleString(undefined, {\n ...(format.resolvedOptions() as globalThis.Intl.DateTimeFormatOptions),\n calendar: (temporal as Temporal.PlainYearMonth).calendarId,\n });\n case \"Temporal.PlainMonthDay\":\n return (temporal as Temporal.PlainMonthDay).toLocaleString(undefined, {\n ...(format.resolvedOptions() as globalThis.Intl.DateTimeFormatOptions),\n calendar: (temporal as Temporal.PlainMonthDay).calendarId,\n });\n default:\n return format.format(temporal);\n }\n};\n"]}
@@ -9,7 +9,7 @@ describe("formatTemporal", () => {
9
9
  month: "long",
10
10
  });
11
11
  const result = formatTemporal(plainYearMonth, formatter);
12
- expect(result).toBe("May 2023");
12
+ expect(result).toBe("2023 May");
13
13
  });
14
14
  it("should format Temporal.PlainDateTime correctly", () => {
15
15
  const plainDateTime = Temporal.PlainDateTime.from("2023-05-15T13:45:30");
@@ -1 +1 @@
1
- {"version":3,"file":"formatTemporal.test.js","sourceRoot":"","sources":["../src/formatTemporal.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YACjD,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,cAAc,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACzE,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YACjD,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;YACb,GAAG,EAAE,SAAS;YACd,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,EAAE,S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Temporal } from \"temporal-polyfill\";\nimport { describe, expect, it } from \"vitest\";\n\nimport { formatTemporal } from \"./formatTemporal.js\";\n\ndescribe(\"formatTemporal\", () => {\n it(\"should format Temporal.PlainYearMonth correctly\", () => {\n const plainYearMonth = Temporal.PlainYearMonth.from(\"2023-05\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n });\n const result = formatTemporal(plainYearMonth, formatter);\n expect(result).toBe(\"May 2023\");\n });\n\n it(\"should format Temporal.PlainDateTime correctly\", () => {\n const plainDateTime = Temporal.PlainDateTime.from(\"2023-05-15T13:45:30\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n });\n const result = formatTemporal(plainDateTime, formatter);\n expect(result).toBe(\"May 15, 2023 at 1:45:30 PM\");\n });\n\n it(\"should format Temporal.PlainDate correctly\", () => {\n const plainDate = Temporal.PlainDate.from(\"2023-05-15\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n });\n const result = formatTemporal(plainDate, formatter);\n expect(result).toBe(\"May 15, 2023\");\n });\n\n it(\"should format Temporal.PlainTime correctly\", () => {\n const plainTime = Temporal.PlainTime.from(\"13:45:30\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n });\n const result = formatTemporal(plainTime, formatter);\n expect(result).toBe(\"1:45:30 PM\");\n });\n\n it(\"should format Temporal.ZonedDateTime correctly\", () => {\n const zonedDateTime = Temporal.ZonedDateTime.from(\n \"2023-05-15T13:45:30+08:00[Asia/Manila]\",\n );\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n timeZoneName: \"longGeneric\",\n });\n const result = formatTemporal(zonedDateTime, formatter);\n expect(result).toBe(\"May 15, 2023 at 1:45:30 PM Philippine Standard Time\");\n });\n\n it(\"should format Temporal.Instant correctly\", () => {\n const instant = Temporal.Instant.fromEpochMilliseconds(1714857930000);\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n timeZone: \"UTC\",\n });\n const result = formatTemporal(instant, formatter);\n expect(result).toBe(\"May 4, 2024\");\n });\n\n it(\"should format Temporal.PlainMonthDay correctly\", () => {\n const plainMonthDay = Temporal.PlainMonthDay.from({\n month: 5,\n day: 15,\n });\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n });\n const result = formatTemporal(plainMonthDay, formatter);\n expect(result).toBe(\"May 15\");\n });\n});\n"]}
1
+ {"version":3,"file":"formatTemporal.test.js","sourceRoot":"","sources":["../src/formatTemporal.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YACjD,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,cAAc,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,CAA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aAAa,CAAC,IAAI,CAAC;YAChD,KAAK,EAAE,CAAC;YACR,GAAG,EAAE,EAAE;SACR,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YACjD,KAAK,EAAE,MAAM;YACb,GAAG,EAAE,SAAS;SACf,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QACxD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { Intl, Temporal } from \"temporal-polyfill\";\nimport { describe, expect, it } from \"vitest\";\n\nimport { formatTemporal } from \"./formatTemporal.js\";\n\ndescribe(\"formatTemporal\", () => {\n it(\"should format Temporal.PlainYearMonth correctly\", () => {\n const plainYearMonth = Temporal.PlainYearMonth.from(\"2023-05\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n });\n const result = formatTemporal(plainYearMonth, formatter);\n expect(result).toBe(\"2023 May\");\n });\n\n it(\"should format Temporal.PlainDateTime correctly\", () => {\n const plainDateTime = Temporal.PlainDateTime.from(\"2023-05-15T13:45:30\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n });\n const result = formatTemporal(plainDateTime, formatter);\n expect(result).toBe(\"May 15, 2023 at 1:45:30 PM\");\n });\n\n it(\"should format Temporal.PlainDate correctly\", () => {\n const plainDate = Temporal.PlainDate.from(\"2023-05-15\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n });\n const result = formatTemporal(plainDate, formatter);\n expect(result).toBe(\"May 15, 2023\");\n });\n\n it(\"should format Temporal.PlainTime correctly\", () => {\n const plainTime = Temporal.PlainTime.from(\"13:45:30\");\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n });\n const result = formatTemporal(plainTime, formatter);\n expect(result).toBe(\"1:45:30 PM\");\n });\n\n it(\"should format Temporal.ZonedDateTime correctly\", () => {\n const zonedDateTime = Temporal.ZonedDateTime.from(\n \"2023-05-15T13:45:30+08:00[Asia/Manila]\",\n );\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: \"numeric\",\n timeZoneName: \"longGeneric\",\n });\n const result = formatTemporal(zonedDateTime, formatter);\n expect(result).toBe(\"May 15, 2023 at 1:45:30 PM Philippine Standard Time\");\n });\n\n it(\"should format Temporal.Instant correctly\", () => {\n const instant = Temporal.Instant.fromEpochMilliseconds(1714857930000);\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n timeZone: \"UTC\",\n });\n const result = formatTemporal(instant, formatter);\n expect(result).toBe(\"May 4, 2024\");\n });\n\n it(\"should format Temporal.PlainMonthDay correctly\", () => {\n const plainMonthDay = Temporal.PlainMonthDay.from({\n month: 5,\n day: 15,\n });\n const formatter = new Intl.DateTimeFormat(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n });\n const result = formatTemporal(plainMonthDay, formatter);\n expect(result).toBe(\"May 15\");\n });\n});\n"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "format-temporal",
3
3
  "description": "Format Temporal objects as localized strings.",
4
4
  "author": "Ian Macalinao <me@ianm.com>",
5
- "version": "0.2.0",
5
+ "version": "0.3.0",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -24,13 +24,13 @@
24
24
  "tslib": "^2.8.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@macalinao/eslint-config": "^4.1.6",
27
+ "@macalinao/eslint-config": "^4.1.8",
28
28
  "@macalinao/tsconfig": "^3.1.0",
29
- "eslint": "^9.20.1",
30
- "temporal-polyfill": "^0.2.5",
31
- "temporal-spec": "^0.2.4",
32
- "typescript": "^5.7.3",
33
- "vitest": "^3.0.5"
29
+ "eslint": "^9.23.0",
30
+ "temporal-polyfill": "^0.3.0",
31
+ "temporal-spec": "^0.3.0",
32
+ "typescript": "^5.8.2",
33
+ "vitest": "^3.0.9"
34
34
  },
35
35
  "main": "dist/index.js",
36
36
  "types": "dist/index.d.ts",
@@ -49,7 +49,7 @@
49
49
  "*.{md,json}": "prettier --write"
50
50
  },
51
51
  "peerDependencies": {
52
- "temporal-spec": "^0.2.4"
52
+ "temporal-spec": "^0.3.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsc",
@@ -11,7 +11,7 @@ describe("formatTemporal", () => {
11
11
  month: "long",
12
12
  });
13
13
  const result = formatTemporal(plainYearMonth, formatter);
14
- expect(result).toBe("May 2023");
14
+ expect(result).toBe("2023 May");
15
15
  });
16
16
 
17
17
  it("should format Temporal.PlainDateTime correctly", () => {
@@ -32,17 +32,17 @@ export const formatTemporal = (
32
32
  switch (temporal[Symbol.toStringTag]) {
33
33
  case "Temporal.ZonedDateTime":
34
34
  return temporal.toLocaleString(undefined, {
35
- ...(format.resolvedOptions() as Intl.DateTimeFormatOptions),
35
+ ...(format.resolvedOptions() as globalThis.Intl.DateTimeFormatOptions),
36
36
  timeZone: undefined,
37
37
  });
38
38
  case "Temporal.PlainYearMonth":
39
39
  return (temporal as Temporal.PlainYearMonth).toLocaleString(undefined, {
40
- ...(format.resolvedOptions() as Intl.DateTimeFormatOptions),
40
+ ...(format.resolvedOptions() as globalThis.Intl.DateTimeFormatOptions),
41
41
  calendar: (temporal as Temporal.PlainYearMonth).calendarId,
42
42
  });
43
43
  case "Temporal.PlainMonthDay":
44
44
  return (temporal as Temporal.PlainMonthDay).toLocaleString(undefined, {
45
- ...(format.resolvedOptions() as Intl.DateTimeFormatOptions),
45
+ ...(format.resolvedOptions() as globalThis.Intl.DateTimeFormatOptions),
46
46
  calendar: (temporal as Temporal.PlainMonthDay).calendarId,
47
47
  });
48
48
  default: