Skip to content

Commit fa3d0b9

Browse files
committed
Editorial: Move AnnotatedTime early error to a separate parse step
Checks that a successful TemporalTimeString parse does not additionally parse as an AmbiguousTimeString. This moves the validation previously done as an early error, to a second algorithm step. See: #3128
1 parent f8489fb commit fa3d0b9

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

polyfill/test/validStrings.mjs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,7 @@ const dateTime = (z, timeRequired) =>
315315
);
316316
const annotatedTime = choice(
317317
seq(timeDesignator, time, [dateTimeUTCOffset(false)], [timeZoneAnnotation], [annotations]),
318-
seq(
319-
withSyntaxConstraints(seq(time, [dateTimeUTCOffset(false)]), (result) => {
320-
if (/^(?:(?!02-?30)(?:0[1-9]|1[012])-?(?:0[1-9]|[12][0-9]|30)|(?:0[13578]|10|12)-?31)$/.test(result)) {
321-
throw new SyntaxError('valid PlainMonthDay');
322-
}
323-
if (/^(?!-000000)(?:[0-9]{4}|[+-][0-9]{6})-?(?:0[1-9]|1[012])$/.test(result)) {
324-
throw new SyntaxError('valid PlainYearMonth');
325-
}
326-
}),
327-
[timeZoneAnnotation],
328-
[annotations]
329-
)
318+
seq(time, [dateTimeUTCOffset(false)], [timeZoneAnnotation], [annotations])
330319
);
331320
const annotatedDateTime = (zoned, timeRequired) =>
332321
seq(dateTime(zoned, timeRequired), zoned ? timeZoneAnnotation : [timeZoneAnnotation], [annotations]);
@@ -462,7 +451,20 @@ const goals = {
462451
DateTime: annotatedDateTime(false, false),
463452
Duration: duration,
464453
MonthDay: choice(annotatedMonthDay, annotatedDateTime(false, false)),
465-
Time: choice(annotatedTime, annotatedDateTime(false, true)),
454+
Time: withSyntaxConstraints(choice(annotatedTime, annotatedDateTime(false, true)), (result) => {
455+
try {
456+
ES.ParseTemporalMonthDayString(result);
457+
throw new SyntaxError('valid PlainMonthDay');
458+
} catch (e) {
459+
if (e instanceof SyntaxError) throw e;
460+
}
461+
try {
462+
ES.ParseTemporalYearMonthString(result);
463+
throw new SyntaxError('valid PlainYearMonth');
464+
} catch (e) {
465+
if (e instanceof SyntaxError) throw e;
466+
}
467+
}),
466468
TimeZone: choice(timeZoneIdentifier, zonedDateTime, instant),
467469
YearMonth: choice(annotatedYearMonth, annotatedDateTime(false, false)),
468470
ZonedDateTime: zonedDateTime

spec/abstractops.html

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,7 @@ <h1>RFC 9557 / ISO 8601 grammar</h1>
12301230
AnnotatedTime :::
12311231
TimeDesignator Time DateTimeUTCOffset[~Z]? TimeZoneAnnotation? Annotations?
12321232
Time DateTimeUTCOffset[~Z]? TimeZoneAnnotation? Annotations?
1233-
</emu-grammar>
1234-
<p>Note the disambiguation between the second alternative without |TimeDesignator|, and |DateSpecMonthDay|/|DateSpecYearMonth| in <emu-xref href="#sec-temporal-iso8601grammar-static-semantics-early-errors"></emu-xref>.</p>
1235-
<emu-grammar type="definition">
1233+
12361234
AnnotatedDateTime[Zoned, TimeRequired] :::
12371235
[~Zoned] DateTime[~Z, ?TimeRequired] TimeZoneAnnotation? Annotations?
12381236
[+Zoned] DateTime[+Z, ?TimeRequired] TimeZoneAnnotation Annotations?
@@ -1302,6 +1300,10 @@ <h1>RFC 9557 / ISO 8601 grammar</h1>
13021300
AnnotatedTime
13031301
AnnotatedDateTime[~Zoned, +TimeRequired]
13041302

1303+
AmbiguousTemporalTimeString :::
1304+
DateSpecMonthDay TimeZoneAnnotation? Annotations?
1305+
DateSpecYearMonth TimeZoneAnnotation? Annotations?
1306+
13051307
TemporalYearMonthString :::
13061308
AnnotatedYearMonth
13071309
AnnotatedDateTime[~Zoned, ~TimeRequired]
@@ -1342,18 +1344,6 @@ <h1>Static Semantics: IsValidDate ( ): a Boolean</h1>
13421344

13431345
<emu-clause id="sec-temporal-iso8601grammar-static-semantics-early-errors">
13441346
<h1>Static Semantics: Early Errors</h1>
1345-
<emu-grammar>
1346-
AnnotatedTime :::
1347-
Time DateTimeUTCOffset[~Z]? TimeZoneAnnotation? Annotations?
1348-
</emu-grammar>
1349-
<ul>
1350-
<li>
1351-
It is a Syntax Error if ParseText(|Time| |DateTimeUTCOffset[~Z]|, |DateSpecMonthDay|) is a Parse Node.
1352-
</li>
1353-
<li>
1354-
It is a Syntax Error if ParseText(|Time| |DateTimeUTCOffset[~Z]|, |DateSpecYearMonth|) is a Parse Node.
1355-
</li>
1356-
</ul>
13571347
<emu-grammar>
13581348
DateSpec[Extended] :::
13591349
DateYear DateSeparator[?Extended] DateMonth DateSeparator[?Extended] DateDay

spec/plaintime.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ <h1>
573573
1. Else,
574574
1. If _item_ is not a String, throw a *TypeError* exception.
575575
1. Let _parseResult_ be ? ParseISODateTime(_item_, « |TemporalTimeString| »).
576+
1. If ParseText(StringToCodePoints(_item_), |AmbiguousTemporalTimeString|) is a Parse Node, throw a *RangeError* exception.
576577
1. Assert: _parseResult_.[[Time]] is not ~start-of-day~.
577578
1. Set _result_ to _parseResult_.[[Time]].
578-
1. NOTE: A successful parse using |TemporalTimeString| guarantees absence of ambiguity with respect to any ISO 8601 date-only, year-month, or month-day representation.
579579
1. Let _resolvedOptions_ be ? GetOptionsObject(_options_).
580580
1. Perform ? GetTemporalOverflowOption(_resolvedOptions_).
581581
1. Return ! CreateTemporalTime(_result_).

0 commit comments

Comments
 (0)