Temporal: Start moving collections of valid/invalid strings into TemporalHelpers

This adds an object, TemporalHelpers.ISO, which has methods that return
arrays of various ISO strings. The idea is to deduplicate more string
tests into methods on this object.
This commit is contained in:
Philip Chimento 2022-08-17 16:55:22 -07:00 committed by Philip Chimento
parent ddef61a106
commit 051631f58b
10 changed files with 233 additions and 443 deletions

View File

@ -1557,4 +1557,56 @@ var TemporalHelpers = {
},
};
},
/*
* An object containing further methods that return arrays of ISO strings, for
* testing parsers.
*/
ISO: {
/*
* PlainTime strings that may be mistaken for PlainMonthDay or
* PlainYearMonth strings, and so require a time designator.
*/
plainTimeStringsAmbiguous() {
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
// Adding a calendar annotation to one of these strings must not cause
// disambiguation in favour of time.
const stringsWithCalendar = ambiguousStrings.map((s) => s + '[u-ca=iso8601]');
return ambiguousStrings.concat(stringsWithCalendar);
},
/*
* PlainTime strings that are of similar form to PlainMonthDay and
* PlainYearMonth strings, but are not ambiguous due to components that
* aren't valid as months or days.
*/
plainTimeStringsUnambiguous() {
return [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
}
}
};

View File

@ -4,60 +4,31 @@
/*---
esid: sec-temporal.plaindate.prototype.toplaindatetime
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const instance = new Temporal.PlainDate(2000, 5, 2);
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toPlainDateTime(arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toPlainDateTime(arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toPlainDateTime(arg),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => instance.toPlainDateTime(arg));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => instance.toPlainDateTime(arg));

View File

@ -4,60 +4,31 @@
/*---
esid: sec-temporal.plaindate.prototype.tozoneddatetime
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const instance = new Temporal.PlainDate(2000, 5, 2);
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" });
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" });
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }));

View File

@ -4,60 +4,31 @@
/*---
esid: sec-temporal.plaindatetime.prototype.withplaintime
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => instance.withPlainTime(arg));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => instance.withPlainTime(arg));

View File

@ -4,74 +4,44 @@
/*---
esid: sec-temporal.plaintime.compare
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const midnight = new Temporal.PlainTime();
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
`${string} is ambiguous and requires T prefix (first argument)`
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
`${string} is ambiguous and requires T prefix (second argument)`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.compare(arg, midnight);
Temporal.PlainTime.compare(midnight, arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
`'${arg}' is ambiguous and requires T prefix (first argument)`
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
`'${arg}' is ambiguous and requires T prefix (second argument)`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.compare(arg, midnight);
Temporal.PlainTime.compare(midnight, arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
'space is not accepted as a substitute for T prefix (first argument)'
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
'space is not accepted as a substitute for T prefix (second argument)'
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(arg, midnight),
`space is not accepted as a substitute for T prefix (first argument): '${arg}'`
);
assert.throws(
RangeError,
() => Temporal.PlainTime.compare(midnight, arg),
`space is not accepted as a substitute for T prefix (second argument): '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => {
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach((arg) => {
Temporal.PlainTime.compare(arg, midnight);
Temporal.PlainTime.compare(midnight, arg);
});

View File

@ -4,58 +4,29 @@
/*---
esid: sec-temporal.plaintime.from
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.from(arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
Temporal.PlainTime.from(arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => Temporal.PlainTime.from(arg),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => Temporal.PlainTime.from(arg));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => Temporal.PlainTime.from(arg));

View File

@ -4,60 +4,31 @@
/*---
esid: sec-temporal.plaintime.prototype.equals
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.equals(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.equals(arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.equals(arg),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.equals(arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.equals(arg),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.equals(arg),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => instance.equals(arg));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => instance.equals(arg));

View File

@ -4,60 +4,31 @@
/*---
esid: sec-temporal.plaintime.prototype.since
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.since(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.since(arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.since(arg),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.since(arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.since(arg),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.since(arg),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => instance.since(arg));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => instance.since(arg));

View File

@ -4,60 +4,31 @@
/*---
esid: sec-temporal.plaintime.prototype.until
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321);
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.until(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.until(arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.until(arg),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.until(arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.until(arg),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.until(arg),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => instance.until(arg));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => instance.until(arg));

View File

@ -4,60 +4,31 @@
/*---
esid: sec-temporal.zoneddatetime.prototype.withplaintime
description: ISO 8601 time designator "T" required in cases of ambiguity
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
const ambiguousStrings = [
"2021-12", // ambiguity between YYYY-MM and HHMM-UU
"1214", // ambiguity between MMDD and HHMM
"0229", // ditto, including MMDD that doesn't occur every year
"1130", // ditto, including DD that doesn't occur in every month
"12-14", // ambiguity between MM-DD and HH-UU
"202112", // ambiguity between YYYYMM and HHMMSS
];
ambiguousStrings.forEach((stringWithoutCalendar) => {
// calendar annotation must not cause disambiguation in favour of time
const stringWithCalendar = stringWithoutCalendar + '[u-ca=iso8601]';
[stringWithoutCalendar, stringWithCalendar].forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`${string} is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);
TemporalHelpers.ISO.plainTimeStringsAmbiguous().forEach((string) => {
let arg = string;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`'${arg}' is ambiguous and requires T prefix`
);
// The same string with a T prefix should not throw:
arg = `T${string}`;
instance.withPlainTime(arg);
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
"space is not accepted as a substitute for T prefix"
);
});
arg = ` ${string}`;
assert.throws(
RangeError,
() => instance.withPlainTime(arg),
`space is not accepted as a substitute for T prefix: '${arg}'`
);
});
// None of these should throw without a T prefix, because they are unambiguously time strings:
const unambiguousStrings = [
"2021-13", // 13 is not a month
"202113", // ditto
"2021-13[-13:00]", // ditto
"202113[-13:00]", // ditto
"0000-00", // 0 is not a month
"000000", // ditto
"0000-00[UTC]", // ditto
"000000[UTC]", // ditto
"1314", // 13 is not a month
"13-14", // ditto
"1232", // 32 is not a day
"0230", // 30 is not a day in February
"0631", // 31 is not a day in June
"0000", // 0 is neither a month nor a day
"00-00", // ditto
"2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates
"202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates
];
unambiguousStrings.forEach((arg) => instance.withPlainTime(arg));
TemporalHelpers.ISO.plainTimeStringsUnambiguous().forEach(
(arg) => instance.withPlainTime(arg));