mirror of
https://github.com/tc39/test262.git
synced 2025-07-24 22:45:10 +02:00
Temporal: Tests for ignoring era and eraYear in calendars without eras
This tests some of the prose requirements of CalendarResolveFields. See https://github.com/tc39/proposal-temporal/issues/2870
This commit is contained in:
parent
cff5a6012f
commit
6f8f6b5261
@ -0,0 +1,48 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.from
|
||||||
|
description: era and eraYear are ignored (for calendars not using eras)
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = Temporal.PlainDate.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 1970,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "iso8601",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainDate(result, 1970, 1, "M01", 1,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.PlainDate.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "iso8601",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
const resultHebrew = Temporal.PlainDate.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 5780,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "hebrew",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainDate(resultHebrew, 5780, 1, "M01", 1,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||||
|
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.PlainDate.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "hebrew",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
@ -0,0 +1,48 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindatetime.from
|
||||||
|
description: era and eraYear are ignored (for calendars not using eras)
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = Temporal.PlainDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 1970,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "iso8601",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainDateTime(result, 1970, 1, "M01", 1, 0, 0, 0, 0, 0, 0,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.PlainDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "iso8601",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
const resultHebrew = Temporal.PlainDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 5780,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "hebrew",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainDateTime(resultHebrew, 5780, 1, "M01", 1, 0, 0, 0, 0, 0, 0,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||||
|
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.PlainDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "hebrew",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plainmonthday.from
|
||||||
|
description: era and eraYear are ignored (for calendars not using eras)
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = Temporal.PlainMonthDay.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "iso8601",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainMonthDay(result, "M01", 1,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
const resultHebrew = Temporal.PlainMonthDay.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "hebrew",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainMonthDay(resultHebrew, "M01", 1,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||||
|
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plainyearmonth.from
|
||||||
|
description: era and eraYear are ignored (for calendars not using eras)
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = Temporal.PlainYearMonth.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 1970,
|
||||||
|
monthCode: "M01",
|
||||||
|
calendar: "iso8601",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainYearMonth(result, 1970, 1, "M01",
|
||||||
|
"era and eraYear are ignored for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.PlainYearMonth.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
calendar: "iso8601",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
const resultHebrew = Temporal.PlainYearMonth.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 5780,
|
||||||
|
monthCode: "M01",
|
||||||
|
calendar: "hebrew",
|
||||||
|
});
|
||||||
|
TemporalHelpers.assertPlainYearMonth(resultHebrew, 5780, 1, "M01",
|
||||||
|
"era and eraYear are ignored for calendar not using eras (Hebrew)",
|
||||||
|
undefined, undefined, 30);
|
||||||
|
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.PlainYearMonth.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
calendar: "hebrew",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.from
|
||||||
|
description: era and eraYear are ignored (for calendars not using eras)
|
||||||
|
features: [BigInt, Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const result = Temporal.ZonedDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 1970,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
timeZone: "UTC",
|
||||||
|
calendar: "iso8601",
|
||||||
|
});
|
||||||
|
assert.sameValue(result.epochNanoseconds, 0n,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
timeZone: "UTC",
|
||||||
|
calendar: "iso8601",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (iso8601)");
|
||||||
|
|
||||||
|
const resultHebrew = Temporal.ZonedDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
year: 5730,
|
||||||
|
monthCode: "M04",
|
||||||
|
day: 23,
|
||||||
|
timeZone: "UTC",
|
||||||
|
calendar: "hebrew",
|
||||||
|
});
|
||||||
|
assert.sameValue(resultHebrew.epochNanoseconds, 0n,
|
||||||
|
"era and eraYear are ignored for calendar not using eras (Hebrew)");
|
||||||
|
assert.sameValue(resultHebrew.calendarId, "hebrew");
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||||
|
era: "foobar",
|
||||||
|
eraYear: 1,
|
||||||
|
monthCode: "M01",
|
||||||
|
day: 1,
|
||||||
|
timeZone: "UTC",
|
||||||
|
calendar: "hebrew",
|
||||||
|
}), "era and eraYear cannot replace year for calendar not using eras (Hebrew)");
|
Loading…
x
Reference in New Issue
Block a user