Skip to content

Commit e174021

Browse files
committed
Make formatWithoutLocale implementation simpler
1 parent a03dc8f commit e174021

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/datetime/formatWithoutLocale.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,25 @@ function getNumericMonth(
4747
| Temporal.PlainMonthDay,
4848
) {
4949
if (isPlainMonthDay(dateTime)) {
50-
const table = Object.assign(Object.create(null) as Record<string, number>, {
51-
M01: 1,
52-
M02: 2,
53-
M03: 3,
54-
M04: 4,
55-
M05: 5,
56-
M06: 6,
57-
M07: 7,
58-
M08: 8,
59-
M09: 9,
60-
M10: 10,
61-
M11: 11,
62-
M12: 12,
63-
});
6450
if (dateTime.calendarId === "iso8601") {
65-
const monthNum = table[dateTime.monthCode];
66-
if (monthNum === undefined) {
51+
const index = [
52+
"M01",
53+
"M02",
54+
"M03",
55+
"M04",
56+
"M05",
57+
"M06",
58+
"M07",
59+
"M08",
60+
"M09",
61+
"M10",
62+
"M11",
63+
"M12",
64+
].indexOf(dateTime.monthCode);
65+
if (index === -1) {
6766
throw new Error(`Unknown month code: ${dateTime.monthCode}`);
6867
}
69-
return monthNum;
68+
return index + 1;
7069
}
7170
throw new Error(
7271
`Can't get numeric month of PlainMonthDay with non-ISO calendars`,

0 commit comments

Comments
 (0)