mirror of
https://github.com/tc39/test262.git
synced 2025-12-10 15:29:53 +01:00
Intl Era Monthcode: Tests for constraining leap day in Indian calendar
Adds tests for constraining 31 Chaitra to 30 Chaitra when moving from a leap year to a common year, by the add(), subtract(), or with() methods.
This commit is contained in:
parent
7d21b4acf4
commit
093bc812e0
45
test/intl402/Temporal/PlainDate/prototype/add/leap-year-indian.js
vendored
Normal file
45
test/intl402/Temporal/PlainDate/prototype/add/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.add
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.PlainDate.from({ year: 1946, monthCode: "M01", day: 31, calendar }, options);
|
||||
|
||||
const years1 = new Temporal.Duration(1);
|
||||
const years1n = new Temporal.Duration(-1);
|
||||
const years4 = new Temporal.Duration(4);
|
||||
const years4n = new Temporal.Duration(-4);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.add(years1),
|
||||
1947, 1, "M01", 30, "Adding 1 year to leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.add(years1, options);
|
||||
}, "Adding 1 year to leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.add(years1n),
|
||||
1945, 1, "M01", 30, "Subtracting 1 year from leap day constrains to 30 Chaitra",
|
||||
"shaka", 1945);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.add(years1n, options);
|
||||
}, "Subtracting 1 year from leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.add(years4, options),
|
||||
1950, 1, "M01", 31, "Adding 4 years to leap day goes to the next leap day",
|
||||
"shaka", 1950);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.add(years4n, options),
|
||||
1942, 1, "M01", 31, "Subtracting 4 years from leap day goes to the previous leap day",
|
||||
"shaka", 1942);
|
||||
45
test/intl402/Temporal/PlainDate/prototype/subtract/leap-year-indian.js
vendored
Normal file
45
test/intl402/Temporal/PlainDate/prototype/subtract/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.subtract
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.PlainDate.from({ year: 1946, monthCode: "M01", day: 31, calendar }, options);
|
||||
|
||||
const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years4 = new Temporal.Duration(-4);
|
||||
const years4n = new Temporal.Duration(4);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.subtract(years1),
|
||||
1947, 1, "M01", 30, "Adding 1 year to leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.subtract(years1, options);
|
||||
}, "Adding 1 year to leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.subtract(years1n),
|
||||
1945, 1, "M01", 30, "Subtracting 1 year from leap day constrains to 30 Chaitra",
|
||||
"shaka", 1945);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.subtract(years1n, options);
|
||||
}, "Subtracting 1 year from leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.subtract(years4, options),
|
||||
1950, 1, "M01", 31, "Adding 4 years to leap day goes to the next leap day",
|
||||
"shaka", 1950);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.subtract(years4n, options),
|
||||
1942, 1, "M01", 31, "Subtracting 4 years from leap day goes to the previous leap day",
|
||||
"shaka", 1942);
|
||||
27
test/intl402/Temporal/PlainDate/prototype/with/leap-year-indian.js
vendored
Normal file
27
test/intl402/Temporal/PlainDate/prototype/with/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.with
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.PlainDate.from({ year: 1946, monthCode: "M01", day: 31, calendar }, options);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.with({ year: 1947 }),
|
||||
1947, 1, "M01", 30, "Changing year to a common year on leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.with({ year: 1947 }, options);
|
||||
}, "Changing year to a common year on leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
leapDay.with({ year: 1942 }, options),
|
||||
1942, 1, "M01", 31, "Changing year to another leap year on leap day does not reject",
|
||||
"shaka", 1942);
|
||||
45
test/intl402/Temporal/PlainDateTime/prototype/add/leap-year-indian.js
vendored
Normal file
45
test/intl402/Temporal/PlainDateTime/prototype/add/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.add
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.PlainDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, calendar }, options);
|
||||
|
||||
const years1 = new Temporal.Duration(1);
|
||||
const years1n = new Temporal.Duration(-1);
|
||||
const years4 = new Temporal.Duration(4);
|
||||
const years4n = new Temporal.Duration(-4);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years1),
|
||||
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.add(years1, options);
|
||||
}, "Adding 1 year to leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years1n),
|
||||
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
|
||||
"shaka", 1945);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.add(years1n, options);
|
||||
}, "Subtracting 1 year from leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years4, options),
|
||||
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
|
||||
"shaka", 1950);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years4n, options),
|
||||
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
|
||||
"shaka", 1942);
|
||||
45
test/intl402/Temporal/PlainDateTime/prototype/subtract/leap-year-indian.js
vendored
Normal file
45
test/intl402/Temporal/PlainDateTime/prototype/subtract/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.subtract
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.PlainDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, calendar }, options);
|
||||
|
||||
const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years4 = new Temporal.Duration(-4);
|
||||
const years4n = new Temporal.Duration(4);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years1),
|
||||
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.subtract(years1, options);
|
||||
}, "Adding 1 year to leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years1n),
|
||||
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
|
||||
"shaka", 1945);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.subtract(years1n, options);
|
||||
}, "Subtracting 1 year from leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years4, options),
|
||||
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
|
||||
"shaka", 1950);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years4n, options),
|
||||
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
|
||||
"shaka", 1942);
|
||||
27
test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-indian.js
vendored
Normal file
27
test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.with
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.PlainDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, calendar }, options);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.with({ year: 1947 }),
|
||||
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Changing year to a common year on leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.with({ year: 1947 }, options);
|
||||
}, "Changing year to a common year on leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.with({ year: 1942 }, options),
|
||||
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Changing year to another leap year on leap day does not reject",
|
||||
"shaka", 1942);
|
||||
45
test/intl402/Temporal/ZonedDateTime/prototype/add/leap-year-indian.js
vendored
Normal file
45
test/intl402/Temporal/ZonedDateTime/prototype/add/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.add
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.ZonedDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
|
||||
const years1 = new Temporal.Duration(1);
|
||||
const years1n = new Temporal.Duration(-1);
|
||||
const years4 = new Temporal.Duration(4);
|
||||
const years4n = new Temporal.Duration(-4);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years1).toPlainDateTime(),
|
||||
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.add(years1, options);
|
||||
}, "Adding 1 year to leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years1n).toPlainDateTime(),
|
||||
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
|
||||
"shaka", 1945);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.add(years1n, options);
|
||||
}, "Subtracting 1 year from leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years4, options).toPlainDateTime(),
|
||||
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
|
||||
"shaka", 1950);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.add(years4n, options).toPlainDateTime(),
|
||||
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
|
||||
"shaka", 1942);
|
||||
45
test/intl402/Temporal/ZonedDateTime/prototype/subtract/leap-year-indian.js
vendored
Normal file
45
test/intl402/Temporal/ZonedDateTime/prototype/subtract/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.subtract
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.ZonedDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
|
||||
const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years4 = new Temporal.Duration(-4);
|
||||
const years4n = new Temporal.Duration(4);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years1).toPlainDateTime(),
|
||||
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.subtract(years1, options);
|
||||
}, "Adding 1 year to leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years1n).toPlainDateTime(),
|
||||
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
|
||||
"shaka", 1945);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.subtract(years1n, options);
|
||||
}, "Subtracting 1 year from leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years4, options).toPlainDateTime(),
|
||||
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
|
||||
"shaka", 1950);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.subtract(years4n, options).toPlainDateTime(),
|
||||
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
|
||||
"shaka", 1942);
|
||||
27
test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-indian.js
vendored
Normal file
27
test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-indian.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.with
|
||||
description: Check various basic calculations involving leap years (indian calendar)
|
||||
features: [Temporal, Intl.Era-monthcode]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const calendar = "indian";
|
||||
const options = { overflow: "reject" };
|
||||
|
||||
const leapDay = Temporal.ZonedDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.with({ year: 1947 }).toPlainDateTime(),
|
||||
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Changing year to a common year on leap day constrains to 30 Chaitra",
|
||||
"shaka", 1947);
|
||||
assert.throws(RangeError, function () {
|
||||
leapDay.with({ year: 1947 }, options);
|
||||
}, "Changing year to a common year on leap day rejects");
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
leapDay.with({ year: 1942 }, options).toPlainDateTime(),
|
||||
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Changing year to another leap year on leap day does not reject",
|
||||
"shaka", 1942);
|
||||
Loading…
x
Reference in New Issue
Block a user