Disallow sub-minute annotations in Instant strings

Adds tests that verify that Instant strings cannot include offset time
zone annotations with sub-minute units.

Also removes a few staging test cases that, due to a polyfill bug, were
incorrectly passing.
This commit is contained in:
Justin Grant 2023-08-10 04:42:53 -07:00 committed by Ms2ger
parent 2e4e0e6b8e
commit 0c87a86b58
6 changed files with 250 additions and 4 deletions

View File

@ -10,3 +10,53 @@ features: [Temporal]
const str = "1970-01-01T00:19:32.37+00:19:32.37";
const result = Temporal.Instant.from(str);
assert.sameValue(result.epochNanoseconds, 0n, "if present, sub-minute offset is accepted exactly");
[
"2021-08-19T17:30-07:00:01[-07:00:01]",
"2021-08-19T17:30-07:00:00[-07:00:00]",
"2021-08-19T17:30-07:00:00.1[-07:00:00.1]",
"2021-08-19T17:30-07:00:00.0[-07:00:00.0]",
"2021-08-19T17:30-07:00:00.01[-07:00:00.01]",
"2021-08-19T17:30-07:00:00.00[-07:00:00.00]",
"2021-08-19T17:30-07:00:00.001[-07:00:00.001]",
"2021-08-19T17:30-07:00:00.000[-07:00:00.000]",
"2021-08-19T17:30-07:00:00.0001[-07:00:00.0001]",
"2021-08-19T17:30-07:00:00.0000[-07:00:00.0000]",
"2021-08-19T17:30-07:00:00.00001[-07:00:00.00001]",
"2021-08-19T17:30-07:00:00.00000[-07:00:00.00000]",
"2021-08-19T17:30-07:00:00.000001[-07:00:00.000001]",
"2021-08-19T17:30-07:00:00.000000[-07:00:00.000000]",
"2021-08-19T17:30-07:00:00.0000001[-07:00:00.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-07:00:00.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-07:00:00.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-07:00:00.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-07:00:00.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-07:00:00.000000000]",
"2021-08-19T17:30-07:00:01[-070001]",
"2021-08-19T17:30-07:00:00[-070000]",
"2021-08-19T17:30-07:00:00.1[-070000.1]",
"2021-08-19T17:30-07:00:00.0[-070000.0]",
"2021-08-19T17:30-07:00:00.01[-070000.01]",
"2021-08-19T17:30-07:00:00.00[-070000.00]",
"2021-08-19T17:30-07:00:00.001[-070000.001]",
"2021-08-19T17:30-07:00:00.000[-070000.000]",
"2021-08-19T17:30-07:00:00.0001[-070000.0001]",
"2021-08-19T17:30-07:00:00.0000[-070000.0000]",
"2021-08-19T17:30-07:00:00.00001[-070000.00001]",
"2021-08-19T17:30-07:00:00.00000[-070000.00000]",
"2021-08-19T17:30-07:00:00.000001[-070000.000001]",
"2021-08-19T17:30-07:00:00.000000[-070000.000000]",
"2021-08-19T17:30-07:00:00.0000001[-070000.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-070000.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-070000.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-070000.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-070000.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-070000.000000000]"
].forEach((str) => {
assert.throws(
RangeError,
() => Temporal.Instant.from(str),
`ISO strings cannot have sub-minute offsets in time zone annotations: ${str}`
);
});

View File

@ -12,3 +12,53 @@ const instance = new Temporal.Instant(0n);
const str = "1970-01-01T00:19:32.37+00:19:32.37";
const result = instance.equals(str);
assert.sameValue(result, true, "if present, sub-minute offset is accepted exactly");
[
"2021-08-19T17:30-07:00:01[-07:00:01]",
"2021-08-19T17:30-07:00:00[-07:00:00]",
"2021-08-19T17:30-07:00:00.1[-07:00:00.1]",
"2021-08-19T17:30-07:00:00.0[-07:00:00.0]",
"2021-08-19T17:30-07:00:00.01[-07:00:00.01]",
"2021-08-19T17:30-07:00:00.00[-07:00:00.00]",
"2021-08-19T17:30-07:00:00.001[-07:00:00.001]",
"2021-08-19T17:30-07:00:00.000[-07:00:00.000]",
"2021-08-19T17:30-07:00:00.0001[-07:00:00.0001]",
"2021-08-19T17:30-07:00:00.0000[-07:00:00.0000]",
"2021-08-19T17:30-07:00:00.00001[-07:00:00.00001]",
"2021-08-19T17:30-07:00:00.00000[-07:00:00.00000]",
"2021-08-19T17:30-07:00:00.000001[-07:00:00.000001]",
"2021-08-19T17:30-07:00:00.000000[-07:00:00.000000]",
"2021-08-19T17:30-07:00:00.0000001[-07:00:00.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-07:00:00.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-07:00:00.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-07:00:00.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-07:00:00.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-07:00:00.000000000]",
"2021-08-19T17:30-07:00:01[-070001]",
"2021-08-19T17:30-07:00:00[-070000]",
"2021-08-19T17:30-07:00:00.1[-070000.1]",
"2021-08-19T17:30-07:00:00.0[-070000.0]",
"2021-08-19T17:30-07:00:00.01[-070000.01]",
"2021-08-19T17:30-07:00:00.00[-070000.00]",
"2021-08-19T17:30-07:00:00.001[-070000.001]",
"2021-08-19T17:30-07:00:00.000[-070000.000]",
"2021-08-19T17:30-07:00:00.0001[-070000.0001]",
"2021-08-19T17:30-07:00:00.0000[-070000.0000]",
"2021-08-19T17:30-07:00:00.00001[-070000.00001]",
"2021-08-19T17:30-07:00:00.00000[-070000.00000]",
"2021-08-19T17:30-07:00:00.000001[-070000.000001]",
"2021-08-19T17:30-07:00:00.000000[-070000.000000]",
"2021-08-19T17:30-07:00:00.0000001[-070000.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-070000.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-070000.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-070000.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-070000.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-070000.000000000]"
].forEach((str) => {
assert.throws(
RangeError,
() => instance.equals(str),
`ISO strings cannot have sub-minute offsets in time zone annotations: ${str}`
);
});

View File

@ -13,3 +13,53 @@ const instance = new Temporal.Instant(0n);
const str = "1970-01-01T00:19:32.37+00:19:32.37";
const result = instance.since(str);
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "if present, sub-minute offset is accepted exactly");
[
"2021-08-19T17:30-07:00:01[-07:00:01]",
"2021-08-19T17:30-07:00:00[-07:00:00]",
"2021-08-19T17:30-07:00:00.1[-07:00:00.1]",
"2021-08-19T17:30-07:00:00.0[-07:00:00.0]",
"2021-08-19T17:30-07:00:00.01[-07:00:00.01]",
"2021-08-19T17:30-07:00:00.00[-07:00:00.00]",
"2021-08-19T17:30-07:00:00.001[-07:00:00.001]",
"2021-08-19T17:30-07:00:00.000[-07:00:00.000]",
"2021-08-19T17:30-07:00:00.0001[-07:00:00.0001]",
"2021-08-19T17:30-07:00:00.0000[-07:00:00.0000]",
"2021-08-19T17:30-07:00:00.00001[-07:00:00.00001]",
"2021-08-19T17:30-07:00:00.00000[-07:00:00.00000]",
"2021-08-19T17:30-07:00:00.000001[-07:00:00.000001]",
"2021-08-19T17:30-07:00:00.000000[-07:00:00.000000]",
"2021-08-19T17:30-07:00:00.0000001[-07:00:00.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-07:00:00.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-07:00:00.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-07:00:00.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-07:00:00.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-07:00:00.000000000]",
"2021-08-19T17:30-07:00:01[-070001]",
"2021-08-19T17:30-07:00:00[-070000]",
"2021-08-19T17:30-07:00:00.1[-070000.1]",
"2021-08-19T17:30-07:00:00.0[-070000.0]",
"2021-08-19T17:30-07:00:00.01[-070000.01]",
"2021-08-19T17:30-07:00:00.00[-070000.00]",
"2021-08-19T17:30-07:00:00.001[-070000.001]",
"2021-08-19T17:30-07:00:00.000[-070000.000]",
"2021-08-19T17:30-07:00:00.0001[-070000.0001]",
"2021-08-19T17:30-07:00:00.0000[-070000.0000]",
"2021-08-19T17:30-07:00:00.00001[-070000.00001]",
"2021-08-19T17:30-07:00:00.00000[-070000.00000]",
"2021-08-19T17:30-07:00:00.000001[-070000.000001]",
"2021-08-19T17:30-07:00:00.000000[-070000.000000]",
"2021-08-19T17:30-07:00:00.0000001[-070000.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-070000.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-070000.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-070000.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-070000.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-070000.000000000]"
].forEach((str) => {
assert.throws(
RangeError,
() => instance.since(str),
`ISO strings cannot have sub-minute offsets in time zone annotations: ${str}`
);
});

View File

@ -13,3 +13,53 @@ const instance = new Temporal.Instant(0n);
const str = "1970-01-01T00:19:32.37+00:19:32.37";
const result = instance.until(str);
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "if present, sub-minute offset is accepted exactly");
[
"2021-08-19T17:30-07:00:01[-07:00:01]",
"2021-08-19T17:30-07:00:00[-07:00:00]",
"2021-08-19T17:30-07:00:00.1[-07:00:00.1]",
"2021-08-19T17:30-07:00:00.0[-07:00:00.0]",
"2021-08-19T17:30-07:00:00.01[-07:00:00.01]",
"2021-08-19T17:30-07:00:00.00[-07:00:00.00]",
"2021-08-19T17:30-07:00:00.001[-07:00:00.001]",
"2021-08-19T17:30-07:00:00.000[-07:00:00.000]",
"2021-08-19T17:30-07:00:00.0001[-07:00:00.0001]",
"2021-08-19T17:30-07:00:00.0000[-07:00:00.0000]",
"2021-08-19T17:30-07:00:00.00001[-07:00:00.00001]",
"2021-08-19T17:30-07:00:00.00000[-07:00:00.00000]",
"2021-08-19T17:30-07:00:00.000001[-07:00:00.000001]",
"2021-08-19T17:30-07:00:00.000000[-07:00:00.000000]",
"2021-08-19T17:30-07:00:00.0000001[-07:00:00.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-07:00:00.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-07:00:00.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-07:00:00.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-07:00:00.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-07:00:00.000000000]",
"2021-08-19T17:30-07:00:01[-070001]",
"2021-08-19T17:30-07:00:00[-070000]",
"2021-08-19T17:30-07:00:00.1[-070000.1]",
"2021-08-19T17:30-07:00:00.0[-070000.0]",
"2021-08-19T17:30-07:00:00.01[-070000.01]",
"2021-08-19T17:30-07:00:00.00[-070000.00]",
"2021-08-19T17:30-07:00:00.001[-070000.001]",
"2021-08-19T17:30-07:00:00.000[-070000.000]",
"2021-08-19T17:30-07:00:00.0001[-070000.0001]",
"2021-08-19T17:30-07:00:00.0000[-070000.0000]",
"2021-08-19T17:30-07:00:00.00001[-070000.00001]",
"2021-08-19T17:30-07:00:00.00000[-070000.00000]",
"2021-08-19T17:30-07:00:00.000001[-070000.000001]",
"2021-08-19T17:30-07:00:00.000000[-070000.000000]",
"2021-08-19T17:30-07:00:00.0000001[-070000.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-070000.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-070000.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-070000.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-070000.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-070000.000000000]"
].forEach((str) => {
assert.throws(
RangeError,
() => instance.until(str),
`ISO strings cannot have sub-minute offsets in time zone annotations: ${str}`
);
});

View File

@ -13,3 +13,53 @@ const instance = new Temporal.TimeZone("UTC");
const str = "1970-01-01T00:19:32.37+00:19:32.37";
const result = instance.getPlainDateTimeFor(str);
TemporalHelpers.assertPlainDateTime(result, 1970, 1, "M01", 1, 0, 0, 0, 0, 0, 0, "if present, sub-minute offset is accepted exactly");
[
"2021-08-19T17:30-07:00:01[-07:00:01]",
"2021-08-19T17:30-07:00:00[-07:00:00]",
"2021-08-19T17:30-07:00:00.1[-07:00:00.1]",
"2021-08-19T17:30-07:00:00.0[-07:00:00.0]",
"2021-08-19T17:30-07:00:00.01[-07:00:00.01]",
"2021-08-19T17:30-07:00:00.00[-07:00:00.00]",
"2021-08-19T17:30-07:00:00.001[-07:00:00.001]",
"2021-08-19T17:30-07:00:00.000[-07:00:00.000]",
"2021-08-19T17:30-07:00:00.0001[-07:00:00.0001]",
"2021-08-19T17:30-07:00:00.0000[-07:00:00.0000]",
"2021-08-19T17:30-07:00:00.00001[-07:00:00.00001]",
"2021-08-19T17:30-07:00:00.00000[-07:00:00.00000]",
"2021-08-19T17:30-07:00:00.000001[-07:00:00.000001]",
"2021-08-19T17:30-07:00:00.000000[-07:00:00.000000]",
"2021-08-19T17:30-07:00:00.0000001[-07:00:00.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-07:00:00.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-07:00:00.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-07:00:00.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-07:00:00.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-07:00:00.000000000]",
"2021-08-19T17:30-07:00:01[-070001]",
"2021-08-19T17:30-07:00:00[-070000]",
"2021-08-19T17:30-07:00:00.1[-070000.1]",
"2021-08-19T17:30-07:00:00.0[-070000.0]",
"2021-08-19T17:30-07:00:00.01[-070000.01]",
"2021-08-19T17:30-07:00:00.00[-070000.00]",
"2021-08-19T17:30-07:00:00.001[-070000.001]",
"2021-08-19T17:30-07:00:00.000[-070000.000]",
"2021-08-19T17:30-07:00:00.0001[-070000.0001]",
"2021-08-19T17:30-07:00:00.0000[-070000.0000]",
"2021-08-19T17:30-07:00:00.00001[-070000.00001]",
"2021-08-19T17:30-07:00:00.00000[-070000.00000]",
"2021-08-19T17:30-07:00:00.000001[-070000.000001]",
"2021-08-19T17:30-07:00:00.000000[-070000.000000]",
"2021-08-19T17:30-07:00:00.0000001[-070000.0000001]",
"2021-08-19T17:30-07:00:00.0000000[-070000.0000000]",
"2021-08-19T17:30-07:00:00.00000001[-070000.00000001]",
"2021-08-19T17:30-07:00:00.00000000[-070000.00000000]",
"2021-08-19T17:30-07:00:00.000000001[-070000.000000001]",
"2021-08-19T17:30-07:00:00.000000000[-070000.000000000]"
].forEach((str) => {
assert.throws(
RangeError,
() => instance.getPlainDateTimeFor(str),
`ISO strings cannot have sub-minute offsets in time zone annotations: ${str}`
);
});

View File

@ -32,10 +32,6 @@ function generateTest(dateTimeString, zoneString, components) {
"+01:00",
"+01",
"+0100",
"+01:00:00",
"+010000",
"+01:00:00.000000000",
"+010000.0"
].forEach(zoneString => {
generateTest("1976-11-18T15:23", `${ zoneString }[Europe/Vienna]`, [
1976,