From 1550f7f7e1656cdf45671cf9abd14cbae4b2c9fb Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 7 Oct 2022 18:43:43 -0700 Subject: [PATCH] Temporal: Test that the offset option has the last word in ZDT.from() The programmer always gets the last word over how the string is interpreted, since otherwise it's not possible to make any guarantees about the offset option. (This is the "out-of-band" mechanism mentioned in the IETF draft.) Add a test for this. --- .../from/offset-overrides-critical-flag.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/offset-overrides-critical-flag.js diff --git a/test/built-ins/Temporal/ZonedDateTime/from/offset-overrides-critical-flag.js b/test/built-ins/Temporal/ZonedDateTime/from/offset-overrides-critical-flag.js new file mode 100644 index 0000000000..b303b29d0b --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/offset-overrides-critical-flag.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 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: > + The offset option always overrides the critical flag in a time zone annotation +features: [Temporal] +---*/ + +const useResult = Temporal.ZonedDateTime.from("2022-10-07T18:37-07:00[!UTC]", { offset: "use" }); +assert.sameValue( + useResult.epochNanoseconds, + 1665193020000000000n, + "exact time is unchanged with offset = use, despite critical flag" +); + +const ignoreResult = Temporal.ZonedDateTime.from("2022-10-07T18:37-07:00[!UTC]", { offset: "ignore" }); +assert.sameValue( + ignoreResult.epochNanoseconds, + 1665167820000000000n, + "wall time is unchanged with offset = ignore, despite critical flag" +); + +const preferResult = Temporal.ZonedDateTime.from("2022-10-07T18:37-07:00[!UTC]", { offset: "prefer" }); +assert.sameValue( + useResult.epochNanoseconds, + 1665193020000000000n, + "offset is recalculated with offset = prefer, despite critical flag" +);