Skip to content

Commit a17f223

Browse files
committed
Added test to .from() methods for PlainDate, PlainDateTime,
`PlainYearMonth`, and `ZonedDateTime` verifying era aliases for non-gregorian calendars (in practice, just `"japanese"`).
1 parent 678c434 commit a17f223

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal-calendarsupportsera
6+
description: Calendar era code is canonicalized (non-Gregorian calendars)
7+
features: [Temporal, Intl.Era-monthcode]
8+
---*/
9+
10+
11+
const calendarEraAliases = [
12+
{ calendar: "japanese", canonicalizedEra: "ce", alias: "ad" },
13+
{ calendar: "japanese", canonicalizedEra: "bce", alias: "bc" }
14+
];
15+
16+
17+
for (const calendarEraAlias of calendarEraAliases) {
18+
const calendar = Temporal.PlainDate.from({
19+
calendar: calendarEraAlias.calendar,
20+
era: calendarEraAlias.alias,
21+
eraYear: 1,
22+
month: 1,
23+
day: 1
24+
});
25+
assert.sameValue(calendar.era, calendarEraAlias.canonicalizedEra, calendar.era + " should canonicalize to " + calendarEraAlias.canonicalizedEra)
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindatetime.from
6+
description: Calendar era code is canonicalized (non-Gregorian calendars)
7+
features: [Temporal, Intl.Era-monthcode]
8+
---*/
9+
10+
11+
const calendarEraAliases = [
12+
{ calendar: "japanese", canonicalizedEra: "ce", alias: "ad" },
13+
{ calendar: "japanese", canonicalizedEra: "bce", alias: "bc" }
14+
];
15+
16+
17+
for (const calendarEraAlias of calendarEraAliases) {
18+
const calendar = Temporal.PlainDateTime.from({
19+
calendar: calendarEraAlias.calendar,
20+
era: calendarEraAlias.alias,
21+
eraYear: 1,
22+
month: 1,
23+
day: 1
24+
});
25+
assert.sameValue(calendar.era, calendarEraAlias.canonicalizedEra, calendar.era + " should canonicalize to " + calendarEraAlias.canonicalizedEra)
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal-plainyearmonth.from
6+
description: Calendar era code is canonicalized (non-Gregorian calendars)
7+
features: [Temporal, Intl.Era-monthcode]
8+
---*/
9+
10+
11+
const calendarEraAliases = [
12+
{ calendar: "japanese", canonicalizedEra: "ce", alias: "ad" },
13+
{ calendar: "japanese", canonicalizedEra: "bce", alias: "bc" }
14+
];
15+
16+
17+
for (const calendarEraAlias of calendarEraAliases) {
18+
const calendar = Temporal.PlainYearMonth.from({
19+
calendar: calendarEraAlias.calendar,
20+
era: calendarEraAlias.alias,
21+
eraYear: 1,
22+
month: 1,
23+
day: 1
24+
});
25+
assert.sameValue(calendar.era, calendarEraAlias.canonicalizedEra, calendar.era + " should canonicalize to " + calendarEraAlias.canonicalizedEra)
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zonedatetime.from
6+
description: Calendar era code is canonicalized (non-Gregorian calendars)
7+
features: [Temporal, Intl.Era-monthcode]
8+
---*/
9+
10+
11+
const calendarEraAliases = [
12+
{ calendar: "japanese", canonicalizedEra: "ce", alias: "ad" },
13+
{ calendar: "japanese", canonicalizedEra: "bce", alias: "bc" }
14+
];
15+
16+
17+
for (const calendarEraAlias of calendarEraAliases) {
18+
const calendar = Temporal.ZonedDateTime.from({
19+
calendar: calendarEraAlias.calendar,
20+
era: calendarEraAlias.alias,
21+
eraYear: 1,
22+
month: 1,
23+
day: 1,
24+
timeZone: "UTC"
25+
});
26+
assert.sameValue(calendar.era, calendarEraAlias.canonicalizedEra, calendar.era + " should canonicalize to " + calendarEraAlias.canonicalizedEra)
27+
}

0 commit comments

Comments
 (0)