Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporal: Add additional coverage based on issues reported by Anba #4248

Merged
merged 7 commits into from
Oct 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ assert.sameValue(result, 0, "ISO string offset accepted with zero seconds (prope

relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

relativeTo = "1970-01-01T00:00-00:44:59[-00:44:59]";
assert.throws(RangeError, () => action(relativeTo), "sub-minute offset not accepted as time zone identifier");
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ TemporalHelpers.assertDateDuration(result, 1, 0, 0, 1, "ISO string offset accept

relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

relativeTo = "1970-01-01T00:00-00:44:59[-00:44:59]";
assert.throws(RangeError, () => action(relativeTo), "sub-minute offset not accepted as time zone identifier");
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ assert.sameValue(result, 366, "ISO string offset accepted with zero seconds (pro

relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]";
assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone");

relativeTo = "1970-01-01T00:00-00:44:59[-00:44:59]";
assert.throws(RangeError, () => action(relativeTo), "sub-minute offset not accepted as time zone identifier");
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.instant.prototype.tostring
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => instance.toString({ timeZone }),
`${timeZone} is not a valid time zone string`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.instant.prototype.tozoneddatetimeiso
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => instance.toZonedDateTimeISO(timeZone),
`${timeZone} is not a valid time zone string`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.now.plaindateiso
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => Temporal.Now.plainDateISO(timeZone),
`${timeZone} is not a valid time zone string`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.now.plaindatetimeiso
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => Temporal.Now.plainDateTimeISO(timeZone),
`${timeZone} is not a valid time zone string`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.now.plaintimeiso
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => Temporal.Now.plainTimeISO(timeZone),
`${timeZone} is not a valid time zone string`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.now.zoneddatetimeiso
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => Temporal.Now.zonedDateTimeISO(timeZone),
`${timeZone} is not a valid time zone string`
);
}
33 changes: 33 additions & 0 deletions test/built-ins/Temporal/PlainDate/from/monthcode-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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: Validation of monthCode
features: [Temporal]
---*/

["m1", "M1", "m01"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.PlainDate.from({ year: 2021, monthCode, day: 17 }),
`monthCode '${monthCode}' is not well-formed`);
});

assert.throws(RangeError, () => Temporal.PlainDate.from({ year: 2021, month: 12, monthCode: "M11", day: 17 }),
"monthCode and month conflict");

["M00", "M19", "M99", "M13", "M00L", "M05L", "M13L"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.PlainDate.from({ year: 2021, monthCode, day: 17 }),
`monthCode '${monthCode}' is not valid for ISO 8601 calendar`);
});

assert.throws(
RangeError,
() => Temporal.PlainDate.from({ day: 1, monthCode: "L99M", year: Symbol() }),
"Month code syntax is validated before year type is validated"
);

assert.throws(
TypeError,
() => Temporal.PlainDate.from({ day: 1, monthCode: "M99L", year: Symbol() }),
"Month code suitability is validated after year type is validated"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.prototype.tozoneddatetime
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

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

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => instance.toZonedDateTime(timeZone),
`${timeZone} is not a valid time zone string`
);
}
33 changes: 33 additions & 0 deletions test/built-ins/Temporal/PlainDateTime/from/monthcode-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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: Validation of monthCode
features: [Temporal]
---*/

["m1", "M1", "m01"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.PlainDateTime.from({ year: 2021, monthCode, day: 17 }),
`monthCode '${monthCode}' is not well-formed`);
});

assert.throws(RangeError, () => Temporal.PlainDateTime.from({ year: 2021, month: 12, monthCode: "M11", day: 17 }),
"monthCode and month conflict");

["M00", "M19", "M99", "M13", "M00L", "M05L", "M13L"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.PlainDateTime.from({ year: 2021, monthCode, day: 17 }),
`monthCode '${monthCode}' is not valid for ISO 8601 calendar`);
});

assert.throws(
RangeError,
() => Temporal.PlainDateTime.from({ day: 1, monthCode: "L99M", year: Symbol() }),
"Month code syntax is validated before year type is validated"
);

assert.throws(
TypeError,
() => Temporal.PlainDateTime.from({ day: 1, monthCode: "M99L", year: Symbol() }),
"Month code suitability is validated after year type is validated"
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ features: [Temporal]
assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ year: 2021, month: 12, monthCode: "M11", day: 17 }),
"monthCode and month conflict");

["M00", "M19", "M99", "M13"].forEach((monthCode) => {
["M00", "M19", "M99", "M13", "M00L", "M05L", "M13L"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ monthCode, day: 17 }),
`monthCode '${monthCode}' is not valid for ISO 8601 calendar`);
});

assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from({ day: 1, monthCode: "L99M", year: Symbol() }),
"Month code syntax is validated before year type is validated"
);

assert.throws(
TypeError,
() => Temporal.PlainMonthDay.from({ day: 1, monthCode: "M99L", year: Symbol() }),
"Month code suitability is validated after year type is validated"
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ features: [Temporal]
assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ year: 2021, month: 12, monthCode: "M11" }),
"monthCode and month conflict");

["M00", "M19", "M99", "M13"].forEach((monthCode) => {
["M00", "M19", "M99", "M13", "M00L", "M05L", "M13L"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ year: 2021, monthCode }),
`monthCode '${monthCode}' is not valid for year 2021`);
`monthCode '${monthCode}' is not valid for year 2021 in ISO 8601 calendar`);
});

assert.throws(
RangeError,
() => Temporal.PlainYearMonth.from({ monthCode: "L99M", year: Symbol() }),
"Month code syntax is validated before year type is validated"
);

assert.throws(
TypeError,
() => Temporal.PlainYearMonth.from({ monthCode: "M99L", year: Symbol() }),
"Month code suitability is validated after year type is validated"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.compare
description: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

const instance = new Temporal.ZonedDateTime(1588371240_000_000_000n, "+01:46");

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, instance),
`${timeZone} is not a valid time zone string (first argument)`
);
assert.throws(
RangeError,
() => Temporal.ZonedDateTime.compare(instance, { year: 2020, month: 5, day: 2, timeZone }),
`${timeZone} is not a valid time zone string (second argument)`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.compare
description: >
ISO strings cannot have sub-minute UTC offset as a time zone identifier
features: [Temporal]
---*/

const instance = new Temporal.ZonedDateTime(1588371240_000_000_000n, "+01:46");

const str = "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]";

assert.throws(
RangeError,
() => Temporal.ZonedDateTime.compare(str, instance),
`${str} is not a valid ISO string (first argument)`
);
assert.throws(
RangeError,
() => Temporal.ZonedDateTime.compare(instance, str),
`${str} is not a valid ISO string (second argument)`
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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: >
Time zone parsing from ISO strings does not accept sub-minute UTC offset as
time zone identifier
features: [Temporal]
---*/

for (const timeZone of ["-12:12:59.9", "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]"]) {
assert.throws(
RangeError,
() => Temporal.ZonedDateTime.from({ year: 2020, month: 5, day: 2, timeZone }),
`${timeZone} is not a valid time zone string`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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: >
ISO strings cannot have sub-minute UTC offset as a time zone identifier
features: [Temporal]
---*/

const str = "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]";
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(str), `${str} is not a valid ISO string`);
33 changes: 33 additions & 0 deletions test/built-ins/Temporal/ZonedDateTime/from/monthcode-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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: Validation of monthCode
features: [Temporal]
---*/

["m1", "M1", "m01"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ year: 2021, monthCode, day: 17, timeZone: "UTC" }),
`monthCode '${monthCode}' is not well-formed`);
});

assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ year: 2021, month: 12, monthCode: "M11", day: 17, timeZone: "UTC" }),
"monthCode and month conflict");

["M00", "M19", "M99", "M13", "M00L", "M05L", "M13L"].forEach((monthCode) => {
assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ year: 2021, monthCode, day: 17, timeZone: "UTC" }),
`monthCode '${monthCode}' is not valid for ISO 8601 calendar`);
});

assert.throws(
RangeError,
() => Temporal.ZonedDateTime.from({ day: 1, monthCode: "L99M", year: Symbol(), timeZone: "UTC" }),
"Month code syntax is validated before year type is validated"
);

assert.throws(
TypeError,
() => Temporal.ZonedDateTime.from({ day: 1, monthCode: "M99L", year: Symbol(), timeZone: "UTC" }),
"Month code suitability is validated after year type is validated"
);
Loading
Loading