argument-propertybag-invalid-offset-string.js (1273B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 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.compare 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 const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); 13 14 const badOffsets = [ 15 "00:00", // missing sign 16 "+0", // too short 17 "-000:00", // too long 18 0, // must be a string 19 null, // must be a string 20 true, // must be a string 21 1000n, // must be a string 22 ]; 23 badOffsets.forEach((offset) => { 24 const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; 25 assert.throws( 26 typeof(offset) === 'string' ? RangeError : TypeError, 27 () => Temporal.ZonedDateTime.compare(arg, datetime), 28 `"${offset} is not a valid offset string (second argument)` 29 ); 30 assert.throws( 31 typeof(offset) === 'string' ? RangeError : TypeError, 32 () => Temporal.ZonedDateTime.compare(datetime, arg), 33 `"${offset} is not a valid offset string (second argument)` 34 ); 35 }); 36 37 reportCompare(0, 0);