Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@ features: [Temporal]
const instance = new Temporal.PlainYearMonth(1970, 1);

const maxCases = [
["P273790Y8M12DT23H59M59.999999999S", "string with max years"],
[{ years: 273790, months: 8, days: 12, nanoseconds: 86399999999999 }, "property bag with max years"],
["P3285488M12DT23H59M59.999999999S", "string with max months"],
[{ months: 3285488, days: 12, nanoseconds: 86399999999999 }, "property bag with max months"],
["P14285714W2DT23H59M59.999999999S", "string with max weeks"],
[{ weeks: 14285714, days: 2, nanoseconds: 86399999999999 }, "property bag with max weeks"],
["P100000000DT23H59M59.999999999S", "string with max days"],
[{ days: 100000000, nanoseconds: 86399999999999 }, "property bag with max days"],
["PT2400000023H59M59.999999999S", "string with max hours"],
[{ hours: 2400000023, nanoseconds: 3599999999999 }, "property bag with max hours"],
["PT144000001439M59.999999999S", "string with max minutes"],
[{ minutes: 144000001439, nanoseconds: 59999999999 }, "property bag with max minutes"],
["PT8640000086399.999999999S", "string with max seconds"],
[{ seconds: 8640000086399, nanoseconds: 999999999 }, "property bag with max seconds"],
["P273790Y8M", "string with max years"],
[{ years: 273790, months: 8 }, "property bag with max years"],
["P3285488M", "string with max months"],
[{ months: 3285488 }, "property bag with max months"],
];

for (const [arg, descr] of maxCases) {
Expand All @@ -33,23 +23,13 @@ for (const [arg, descr] of maxCases) {
}

const minCases = [
["-P273790Y8M42DT23H59M59.999999999S", "string with min years"],
[{ years: -273790, months: -8, days: -42, nanoseconds: -86399999999999 }, "property bag with min years"],
["-P3285488M42DT23H59M59.999999999S", "string with min months"],
[{ months: -3285488, days: -42, nanoseconds: -86399999999999 }, "property bag with min months"],
["-P14285718W5DT23H59M59.999999999S", "string with min weeks"],
[{ weeks: -14285718, days: -5, nanoseconds: -86399999999999 }, "property bag with min weeks"],
["-P100000031DT23H59M59.999999999S", "string with min days"],
[{ days: -100000031, nanoseconds: -86399999999999 }, "property bag with min days"],
["-PT2400000767H59M59.999999999S", "string with min hours"],
[{ hours: -2400000767, nanoseconds: -3599999999999 }, "property bag with min hours"],
["-PT144000046079M59.999999999S", "string with min minutes"],
[{ minutes: -144000046079, nanoseconds: -59999999999 }, "property bag with min minutes"],
["-PT8640002764799.999999999S", "string with min seconds"],
[{ seconds: -8640002764799, nanoseconds: -999999999 }, "property bag with min seconds"],
["-P273790Y8M", "string with min years"],
[{ years: -273790, months: -8 }, "property bag with min years"],
["-P3285488M", "string with min months"],
[{ months: -3285488 }, "property bag with min months"],
];

for (const [arg, descr] of minCases) {
const result = instance.add(arg);
TemporalHelpers.assertPlainYearMonth(result, -271821, 4, "M04", `operation succeeds with ${descr}`);
TemporalHelpers.assertPlainYearMonth(result, -271821, 5, "M05", `operation succeeds with ${descr}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,6 @@ const cases = [
[{ weeks: 4294967296 }, "property bag with weeks > max"],
["-P4294967296W", "string with weeks < min"],
[{ weeks: -4294967296 }, "property bag with weeks < min"],

// ceil(max safe integer / 86400) = 104249991375
["P104249991375D", "string with days > max"],
[{ days: 104249991375 }, "property bag with days > max"],
["P104249991374DT24H", "string where hours balance into days > max"],
[{ days: 104249991374, hours: 24 }, "property bag where hours balance into days > max"],
["-P104249991375D", "string with days < min"],
[{ days: -104249991375 }, "property bag with days < min"],
["-P104249991374DT24H", "string where hours balance into days < min"],
[{ days: -104249991374, hours: -24 }, "property bag where hours balance into days < min"],

// ceil(max safe integer / 3600) = 2501999792984
["PT2501999792984H", "string with hours > max"],
[{ hours: 2501999792984 }, "property bag with hours > max"],
["PT2501999792983H60M", "string where minutes balance into hours > max"],
[{ hours: 2501999792983, minutes: 60 }, "property bag where minutes balance into hours > max"],
["-PT2501999792984H", "string with hours < min"],
[{ hours: -2501999792984 }, "property bag with hours < min"],
["-PT2501999792983H60M", "string where minutes balance into hours < min"],
[{ hours: -2501999792983, minutes: -60 }, "property bag where minutes balance into hours < min"],

// ceil(max safe integer / 60) = 150119987579017
["PT150119987579017M", "string with minutes > max"],
[{ minutes: 150119987579017 }, "property bag with minutes > max"],
["PT150119987579016M60S", "string where seconds balance into minutes > max"],
[{ minutes: 150119987579016, seconds: 60 }, "property bag where seconds balance into minutes > max"],
["-PT150119987579017M", "string with minutes < min"],
[{ minutes: -150119987579017 }, "property bag with minutes < min"],
["-PT150119987579016M60S", "string where seconds balance into minutes < min"],
[{ minutes: -150119987579016, seconds: -60 }, "property bag where seconds balance into minutes < min"],

// 2^53 = 9007199254740992
["PT9007199254740992S", "string with seconds > max"],
[{ seconds: 9007199254740992 }, "property bag with seconds > max"],
[{ seconds: 9007199254740991, milliseconds: 1000 }, "property bag where milliseconds balance into seconds > max"],
[{ seconds: 9007199254740991, microseconds: 1000000 }, "property bag where microseconds balance into seconds > max"],
[{ seconds: 9007199254740991, nanoseconds: 1000000000 }, "property bag where nanoseconds balance into seconds > max"],
["-PT9007199254740992S", "string with seconds < min"],
[{ seconds: -9007199254740992 }, "property bag with seconds < min"],
[{ seconds: -9007199254740991, milliseconds: -1000 }, "property bag where milliseconds balance into seconds < min"],
[{ seconds: -9007199254740991, microseconds: -1000000 }, "property bag where microseconds balance into seconds < min"],
[{ seconds: -9007199254740991, nanoseconds: -1000000000 }, "property bag where nanoseconds balance into seconds < min"],
];

for (const [arg, descr] of cases) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@

/*---
esid: sec-temporal.plainyearmonth.prototype.add
description: Using lower units in add() works
includes: [temporalHelpers.js]
description: Using lower units in add() throws
features: [Temporal]
---*/

const ym = Temporal.PlainYearMonth.from("2019-11");

const tests = [
[{ days: 1 }, 2019, 11, "M11"],
[{ days: 29 }, 2019, 11, "M11"],
[{ hours: 1 }, 2019, 11, "M11"],
[{ minutes: 1 }, 2019, 11, "M11"],
[{ seconds: 1 }, 2019, 11, "M11"],
[{ milliseconds: 1 }, 2019, 11, "M11"],
[{ microseconds: 1 }, 2019, 11, "M11"],
[{ nanoseconds: 1 }, 2019, 11, "M11"],
[{ days: 30 }, 2019, 12, "M12"],
[{ days: 31 }, 2019, 12, "M12"],
[{ days: 60 }, 2019, 12, "M12"],
[{ days: 61 }, 2020, 1, "M01"],
[{ hours: 720 }, 2019, 12, "M12"],
[{ minutes: 43200 }, 2019, 12, "M12"],
[{ seconds: 2592000 }, 2019, 12, "M12"],
[{ milliseconds: 2592000_000 }, 2019, 12, "M12"],
[{ microseconds: 2592000_000_000 }, 2019, 12, "M12"],
[{ nanoseconds: 2592000_000_000_000 }, 2019, 12, "M12"],
{ days: 1 },
{ days: 29 },
{ hours: 1 },
{ minutes: 1 },
{ seconds: 1 },
{ milliseconds: 1 },
{ microseconds: 1 },
{ nanoseconds: 1 },
{ days: 30 },
{ days: 31 },
{ days: 60 },
{ days: 61 },
{ hours: 720 },
{ minutes: 43200 },
{ seconds: 2592000 },
{ milliseconds: 2592000_000 },
{ microseconds: 2592000_000_000 },
{ nanoseconds: 2592000_000_000_000 },
];

for (const [argument, ...expected] of tests) {
TemporalHelpers.assertPlainYearMonth(ym.add(argument), ...expected, "no options");
TemporalHelpers.assertPlainYearMonth(ym.add(argument, { overflow: "constrain" }), ...expected, "constrain");
TemporalHelpers.assertPlainYearMonth(ym.add(argument, { overflow: "reject" }), ...expected, "reject");
for (const argument of tests) {
assert.throws(RangeError, function () { ym.add(argument); }, "adding a unit lower than months should throw, no options");
assert.throws(RangeError, function () { ym.add(argument, { overflow: "constrain" }); }, "adding a unit lower than months should throw, constrain");
assert.throws(RangeError, function () { ym.add(argument, { overflow: "reject" }); }, "adding a unit lower than months should throw, reject");
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const instance = new Temporal.PlainYearMonth(2000, 5);
["constrain", "reject"].forEach((overflow) => {
assert.throws(
RangeError,
() => instance.add({ hours: 1, minutes: -30 }, { overflow }),
() => instance.add({ years: 1, months: -3 }, { overflow }),
`mixed positive and negative values always throw (overflow = "${overflow}")`
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
/*---
esid: sec-temporal.plainyearmonth.prototype.add
description: >
A property bag missing optional properties is equivalent to a property bag
with all the optional properties having their default values
A duration property bag with value 0 for disallowed properties is the same as
a property bag with no disallowed properties
features: [Temporal]
---*/

const instance = new Temporal.PlainYearMonth(1970, 1);

const oneProperty = {
hours: 1,
months: 1,
};
const allProperties = {
years: 0,
months: 0,
months: 1,
weeks: 0,
days: 0,
hours: 1,
hours: 0,
minutes: 0,
seconds: 0,
milliseconds: 0,
Expand All @@ -28,4 +28,4 @@ const allProperties = {
};
const resultWithout = instance.add(oneProperty);
const resultWith = instance.add(allProperties);
assert(resultWithout.equals(resultWith), "results should be the same with and without optional properties");
assert(resultWithout.equals(resultWith), "results should be the same with 0 for disallowed properties and without disallowed properties");

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ const instance = new Temporal.PlainYearMonth(2000, 5);
const fields = TemporalHelpers.propertyBagObserver(actual, {
years: 1,
months: 1,
weeks: 1,
days: 1,
hours: 1,
minutes: 1,
seconds: 1,
milliseconds: 1,
microseconds: 1,
nanoseconds: 1,
weeks: 0,
days: 0,
hours: 0,
minutes: 0,
seconds: 0,
milliseconds: 0,
microseconds: 0,
nanoseconds: 0,
}, "fields");

const options = TemporalHelpers.propertyBagObserver(actual, { overflow: "constrain" }, "options");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2026 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.plainyearmonth.prototype.add
description: Overflow option has no effect in ISO 8601 calendar
features: [Temporal]
---*/

const year1 = new Temporal.Duration(1);
const year1n = new Temporal.Duration(-1);
const month1 = new Temporal.Duration(0, 1);
const month1n = new Temporal.Duration(0, -1);

for (const year of [2023, 2024]) {
for (const month of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) {
const yearmonth = new Temporal.PlainYearMonth(year, month);
for (const duration of [year1, year1n, month1, month1n]) {
const resultConstrain = yearmonth.add(duration, { overflow: "constrain" });
const resultReject = yearmonth.add(duration, { overflow: "reject" });
assert.sameValue(resultReject.year, resultConstrain.year, "year should be identical");
assert.sameValue(resultReject.month, resultConstrain.month, "month should be identical");
assert.sameValue(resultReject.toString(), resultConstrain.toString(), "toString should be identical");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@

/*---
esid: sec-temporal.plainyearmonth.prototype.add
description: RangeError thrown when adding negative duration to last representable month.
description: Adding negative duration to last representable month works
features: [Temporal]
includes: [temporalHelpers.js]
---*/

const lastMonth = new Temporal.PlainYearMonth(275760, 9);

// See https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoyearmonth
// (step 10d)
assert.throws(RangeError, () => lastMonth.add({seconds: -1}));
assert.throws(RangeError, () => lastMonth.add({minutes: -1}));
assert.throws(RangeError, () => lastMonth.add({hours: -1}));
assert.throws(RangeError, () => lastMonth.add({days: -1}));
assert.throws(RangeError, () => lastMonth.add({weeks: -1}));
assert.throws(RangeError, () => lastMonth.add({months: -1}));
assert.throws(RangeError, () => lastMonth.add({years: -1}));
TemporalHelpers.assertPlainYearMonth(lastMonth.add({ months: -1 }), 275760, 8, "M08", "-1 month");
TemporalHelpers.assertPlainYearMonth(lastMonth.add({ years: -1 }), 275759, 9, "M09", "-1 year");

Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,22 @@ features: [Temporal]
const instance = new Temporal.PlainYearMonth(1970, 1);

const maxCases = [
["P273790Y8M42DT23H59M59.999999999S", "string with max years"],
[{ years: 273790, months: 8, days: 42, nanoseconds: 86399999999999 }, "property bag with max years"],
["P3285488M42DT23H59M59.999999999S", "string with max months"],
[{ months: 3285488, days: 42, nanoseconds: 86399999999999 }, "property bag with max months"],
["P14285718W5DT23H59M59.999999999S", "string with max weeks"],
[{ weeks: 14285718, days: 5, nanoseconds: 86399999999999 }, "property bag with max weeks"],
["P100000031DT23H59M59.999999999S", "string with max days"],
[{ days: 100000031, nanoseconds: 86399999999999 }, "property bag with max days"],
["PT2400000767H59M59.999999999S", "string with max hours"],
[{ hours: 2400000767, nanoseconds: 3599999999999 }, "property bag with max hours"],
["PT144000046079M59.999999999S", "string with max minutes"],
[{ minutes: 144000046079, nanoseconds: 59999999999 }, "property bag with max minutes"],
["PT8640002764799.999999999S", "string with max seconds"],
[{ seconds: 8640002764799, nanoseconds: 999999999 }, "property bag with max seconds"],
["P273790Y8M", "string with max years"],
[{ years: 273790, months: 8 }, "property bag with max years"],
["P3285488M", "string with max months"],
[{ months: 3285488 }, "property bag with max months"],
];

for (const [arg, descr] of maxCases) {
const result = instance.subtract(arg);
TemporalHelpers.assertPlainYearMonth(result, -271821, 4, "M04", `operation succeeds with ${descr}`);
TemporalHelpers.assertPlainYearMonth(result, -271821, 5, "M05", `operation succeeds with ${descr}`);
}

const minCases = [
["-P273790Y8M12DT23H59M59.999999999S", "string with min years"],
[{ years: -273790, months: -8, days: -12, nanoseconds: -86399999999999 }, "property bag with min years"],
["-P3285488M12DT23H59M59.999999999S", "string with min months"],
[{ months: -3285488, days: -12, nanoseconds: -86399999999999 }, "property bag with min months"],
["-P14285714W2DT23H59M59.999999999S", "string with min weeks"],
[{ weeks: -14285714, days: -2, nanoseconds: -86399999999999 }, "property bag with min weeks"],
["-P100000000DT23H59M59.999999999S", "string with min days"],
[{ days: -100000000, nanoseconds: -86399999999999 }, "property bag with min days"],
["-PT2400000023H59M59.999999999S", "string with min hours"],
[{ hours: -2400000023, nanoseconds: -3599999999999 }, "property bag with min hours"],
["-PT144000001439M59.999999999S", "string with min minutes"],
[{ minutes: -144000001439, nanoseconds: -59999999999 }, "property bag with min minutes"],
["-PT8640000086399.999999999S", "string with min seconds"],
[{ seconds: -8640000086399, nanoseconds: -999999999 }, "property bag with min seconds"],
["-P273790Y8M", "string with min years"],
[{ years: -273790, months: -8 }, "property bag with min years"],
["-P3285488M", "string with min months"],
[{ months: -3285488 }, "property bag with min months"],
];

for (const [arg, descr] of minCases) {
Expand Down
Loading