Temporal: Add tests for PlainTime string disambiguation with time zone

This implements the normative change in
https://github.com/tc39/proposal-temporal/pull/2284 which reached
consensus at the July 2022 TC39 meeting.

It adds tests that ensure strings like HHMM-UU[TZ] and HHMMSS[TZ] do not
require a disambiguating T separator, even if HHMM-UU and HHMMSS would by
themselves.
This commit is contained in:
Philip Chimento 2022-08-15 16:33:05 -07:00 committed by Philip Chimento
parent 8dcc0e1955
commit d8e8529e8d
9 changed files with 153 additions and 99 deletions

View File

@ -38,16 +38,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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));

View File

@ -38,16 +38,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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" }));

View File

@ -38,16 +38,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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));

View File

@ -49,17 +49,23 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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.compare(arg, midnight);

View File

@ -36,16 +36,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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));

View File

@ -38,16 +38,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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));

View File

@ -38,16 +38,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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));

View File

@ -38,16 +38,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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));

View File

@ -38,16 +38,22 @@ ambiguousStrings.forEach((string) => {
// 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
"0000-00", // 0 is not a month
"000000", // 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-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));