Skip to content

Commit 72bce78

Browse files
gibson04212wrigja
authored andcommitted
Polyfill: Align valid strings test with spec
UPSTREAM_COMMIT=5a84124f2b98e06ef806cd7253c17c976b9aa1e5
1 parent 452f91c commit 72bce78

File tree

1 file changed

+8
-49
lines changed

1 file changed

+8
-49
lines changed

test/validStrings.mjs

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,6 @@ function saveSecond(data, result) {
227227
const timeHour = withCode(hour, saveHour);
228228
const timeMinute = withCode(minuteSecond, saveMinute);
229229
const timeSecond = withCode(choice(minuteSecond, '60'), saveSecond);
230-
const timeHourNotValidMonth = withCode(choice('00', zeroPaddedInclusive(13, 23, 2)), saveHour);
231-
const timeHourNot31DayMonth = withCode(choice('02', '04', '06', '09', '11'), saveHour);
232-
const timeHour2Only = withCode('02', saveHour);
233-
const timeMinuteNotValidDay = withCode(choice('00', zeroPaddedInclusive(32, 59, 2)), saveMinute);
234-
const timeMinute30Only = withCode('30', saveMinute);
235-
const timeMinute31Only = withCode('31', saveMinute);
236-
const timeSecondNotValidMonth = withCode(choice('00', zeroPaddedInclusive(13, 60, 2)), saveSecond);
237230
const timeFraction = withCode(fraction, (data, result) => {
238231
result = result.slice(1);
239232
const fraction = result.padEnd(9, '0');
@@ -246,7 +239,6 @@ const timeZoneUTCOffsetSign = withCode(
246239
(data, result) => (data.offsetSign = result === '-' || result === '\u2212' ? '-' : '+')
247240
);
248241
const timeZoneUTCOffsetHour = hour;
249-
const timeZoneUTCOffsetHourNotValidMonth = zeroPaddedInclusive(13, 23, 2);
250242
const timeZoneUTCOffsetMinute = minuteSecond;
251243
const timeZoneUTCOffsetSecond = minuteSecond;
252244
const timeZoneUTCOffsetFraction = fraction;
@@ -264,24 +256,6 @@ const timeZoneNumericUTCOffset = withCode(
264256
),
265257
saveOffset
266258
);
267-
const timeZoneNumericUTCOffsetNotAmbiguous = withCode(
268-
choice(
269-
seq(character('+\u2212'), timeZoneUTCOffsetHour),
270-
seq(
271-
timeZoneUTCOffsetSign,
272-
timeZoneUTCOffsetHour,
273-
choice(
274-
seq(timeZoneUTCOffsetMinute, [timeZoneUTCOffsetSecond, [timeZoneUTCOffsetFraction]]),
275-
seq(':', timeZoneUTCOffsetMinute, [':', timeZoneUTCOffsetSecond, [timeZoneUTCOffsetFraction]])
276-
)
277-
)
278-
),
279-
saveOffset
280-
);
281-
const timeZoneNumericUTCOffsetNotAmbiguousAllowedNegativeHour = withCode(
282-
choice(timeZoneNumericUTCOffsetNotAmbiguous, seq('-', timeZoneUTCOffsetHourNotValidMonth)),
283-
saveOffset
284-
);
285259
const timeZoneUTCOffset = choice(utcDesignator, timeZoneNumericUTCOffset);
286260
const timeZoneUTCOffsetName = seq(
287261
sign,
@@ -307,29 +281,14 @@ const timeSpec = seq(
307281
timeHour,
308282
choice([':', timeMinute, [':', timeSecond, [timeFraction]]], seq(timeMinute, [timeSecond, [timeFraction]]))
309283
);
310-
const timeSpecWithOptionalTimeZoneNotAmbiguous = choice(
311-
seq(timeHour, [timeZoneNumericUTCOffsetNotAmbiguous], [timeZoneBracketedAnnotation]),
312-
seq(timeHourNotValidMonth, timeZone),
313-
seq(
314-
choice(
315-
seq(timeHourNotValidMonth, timeMinute),
316-
seq(timeHour, timeMinuteNotValidDay),
317-
seq(timeHourNot31DayMonth, timeMinute31Only),
318-
seq(timeHour2Only, timeMinute30Only)
319-
),
320-
[timeZoneBracketedAnnotation]
321-
),
322-
seq(
323-
timeHour,
324-
timeMinute,
325-
choice(
326-
seq(timeZoneNumericUTCOffsetNotAmbiguousAllowedNegativeHour, [timeZoneBracketedAnnotation]),
327-
seq(timeSecondNotValidMonth, [timeZone]),
328-
seq(timeSecond, timeFraction, [timeZone])
329-
)
330-
),
331-
seq(timeHour, ':', timeMinute, [':', timeSecond, [timeFraction]], [timeZone])
332-
);
284+
const timeSpecWithOptionalTimeZoneNotAmbiguous = withSyntaxConstraints(seq(timeSpec, [timeZone]), (result) => {
285+
if (/^(?:(?!02-?30)(?:0[1-9]|1[012])-?(?:0[1-9]|[12][0-9]|30)|(?:0[13578]|10|12)-?31)$/.test(result)) {
286+
throw new SyntaxError('valid PlainMonthDay');
287+
}
288+
if (/^(?![-]000000)(?:[0-9]{4}|[+-][0-9]{6})-?(?:0[1-9]|1[012])$/.test(result)) {
289+
throw new SyntaxError('valid PlainYearMonth');
290+
}
291+
});
333292
const timeSpecSeparator = seq(dateTimeSeparator, timeSpec);
334293

335294
function validateDayOfMonth(result, { year, month, day }) {

0 commit comments

Comments
 (0)