Temporal: Add coverage for disallowed seconds in offset time zone identifiers

This was an area missing test coverage.
This commit is contained in:
Philip Chimento 2024-10-03 11:27:57 -07:00 committed by Ms2ger
parent 36f5cad9e0
commit 09c7d33253
21 changed files with 339 additions and 0 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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`
);
}

View File

@ -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`
);
}

View File

@ -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`
);
}

View File

@ -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`
);
}

View File

@ -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`
);
}

View File

@ -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`
);
}

View File

@ -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`
);
}

View File

@ -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)`
);
}

View File

@ -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)`
);

View File

@ -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`
);
}

View File

@ -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`);

View File

@ -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.zoneddatetime.prototype.equals
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(0n, "UTC");
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.equals({ year: 2020, month: 5, day: 2, timeZone }),
`${timeZone} is not a valid time zone string`
);
}

View File

@ -0,0 +1,13 @@
// 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.prototype.equals
description: >
ISO strings cannot have sub-minute UTC offset as a time zone identifier
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(0n, "UTC");
const str = "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]";
assert.throws(RangeError, () => instance.equals(str), `${str} is not a valid ISO string`);

View File

@ -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.zoneddatetime.prototype.since
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(0n, "UTC");
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.since({ year: 2020, month: 5, day: 2, timeZone }),
`${timeZone} is not a valid time zone string`
);
}

View File

@ -0,0 +1,13 @@
// 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.prototype.since
description: >
ISO strings cannot have sub-minute UTC offset as a time zone identifier
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(0n, "UTC");
const str = "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]";
assert.throws(RangeError, () => instance.since(str), `${str} is not a valid ISO string`);

View File

@ -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.zoneddatetime.prototype.until
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(0n, "UTC");
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.until({ year: 2020, month: 5, day: 2, timeZone }),
`${timeZone} is not a valid time zone string`
);
}

View File

@ -0,0 +1,13 @@
// 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.prototype.until
description: >
ISO strings cannot have sub-minute UTC offset as a time zone identifier
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(0n, "UTC");
const str = "2021-08-19T17:30:45.123456789-12:12:59.9[-12:12:59.9]";
assert.throws(RangeError, () => instance.until(str), `${str} is not a valid ISO string`);

View File

@ -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.zoneddatetime.prototype.withtimezone
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(0n, "UTC");
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.withTimeZone(timeZone),
`${timeZone} is not a valid time zone string`
);
}