From 459cef718537dd9d20a1682a4b73ac506ea212ac Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 3 Oct 2024 12:17:17 -0700 Subject: [PATCH] Temporal: Add coverage for validating offset string syntax vs suitability Syntax is validated first. Only after the property bag is fully converted into a Calendar Fields Record does the time zone validate whether the UTC offset is correct for that exact time in the time zone. See tc39/proposal-temporal#2962 --- .../from/offset-string-invalid.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/offset-string-invalid.js diff --git a/test/built-ins/Temporal/ZonedDateTime/from/offset-string-invalid.js b/test/built-ins/Temporal/ZonedDateTime/from/offset-string-invalid.js new file mode 100644 index 0000000000..e01aba672a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/offset-string-invalid.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Validation of monthCode +features: [Temporal] +---*/ + +const bag = { year: 2024, monthCode: "M10", day: 3, timeZone: "UTC" }; + +["garbage", "00:00", "+000:00", "-00:000", "-00:00:000", "+00:00.0", "+00:00:00.0000000000"].forEach((offset) => { + assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ offset, year: 2024, monthCode: "M10", day: 3, timeZone: "UTC" }), + `UTC offset '${offset}' is not well-formed`); +}); + +assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from({ offset: "--00:00", year: Symbol(), monthCode: "M10", day: 3, timeZone: "UTC" }), + "UTC offset syntax is validated before year type is validated" +); + +assert.throws( + TypeError, + () => Temporal.ZonedDateTime.from({ offset: "+04:30", year: Symbol(), monthCode: "M10", day: 3, timeZone: "UTC" }), + "UTC offset matching is validated after year type is validated" +);