Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2022 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-temporal.zoneddatetime.from
7 description: Property bag with offset property is rejected if offset is in the wrong format
8 features: [Temporal]
9 ---*/
10
11 const timeZone = "UTC";
12
13 const offsetOptions = ['use', 'prefer', 'ignore', 'reject'];
14
15 const badOffsets = [
16 "00:00", // missing sign
17 "+0", // too short
18 "-000:00", // too long
19 0, // must be a string
20 null, // must be a string
21 true, // must be a string
22 1000n, // must be a string
23 {}, // must be a string
24 Symbol() // must be a string
25 ];
26 offsetOptions.forEach((offsetOption) => {
27 badOffsets.forEach((offset) => {
28 const arg = { year: 2021, month: 10, day: 28, offset, timeZone };
29 assert.throws(
30 typeof(offset) === 'string' || (typeof offset === "object" && offset !== null) ? RangeError : TypeError,
31 () => Temporal.ZonedDateTime.from(arg, { offset: offsetOption }),
32 `"${String(offset)} is not a valid offset string (with offset option ${offsetOption})`
33 );
34 });
35 });
36
37 reportCompare(0, 0);