sub-minute-offset.js (2202B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2025 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: ZonedDateTime string accepts an inexact UTC offset rounded to hours and minutes 8 features: [Temporal] 9 includes: [compareArray.js] 10 ---*/ 11 12 let reference = new Temporal.ZonedDateTime(2670_000_000_000n, "Africa/Monrovia"); 13 14 function action(string) { 15 const result1 = Temporal.ZonedDateTime.compare(string, reference); 16 const result2 = Temporal.ZonedDateTime.compare(reference, string); 17 return [result1, result2]; 18 }; 19 20 assert.compareArray( 21 action("1970-01-01T00:00-00:45[Africa/Monrovia]"), [0, 0], 22 "rounded HH:MM is accepted in string offset" 23 ); 24 assert.compareArray( 25 action("1970-01-01T00:00:00-00:44:30[Africa/Monrovia]"), [0, 0], 26 "unrounded HH:MM:SS is accepted in string offset" 27 ); 28 assert.throws( 29 RangeError, () => action("1970-01-01T00:00:00-00:44:40[Africa/Monrovia]"), 30 "wrong :SS not accepted in string offset" 31 ); 32 assert.throws( 33 RangeError, () => action("1970-01-01T00:00:00-00:45:00[Africa/Monrovia]"), 34 "rounded HH:MM:SS not accepted in string offset" 35 ); 36 assert.throws( 37 RangeError, () => action({ year: 1970, month: 1, day: 1, offset: "-00:45", timeZone: "Africa/Monrovia" }), 38 "rounded HH:MM not accepted as offset in property bag" 39 ); 40 41 // Pacific/Niue edge case 42 43 reference = new Temporal.ZonedDateTime(-543069621_000_000_000n, "Pacific/Niue"); 44 45 assert.compareArray( 46 action("1952-10-15T23:59:59-11:19:40[Pacific/Niue]"), [0, 0], 47 "-11:19:40 is accepted as -11:19:40 in Pacific/Niue edge case" 48 ); 49 assert.compareArray( 50 action("1952-10-15T23:59:59-11:20[Pacific/Niue]"), [0, 0], 51 "-11:20 matches the first candidate -11:19:40 in the Pacific/Niue edge case" 52 ); 53 assert.compareArray( 54 action("1952-10-15T23:59:59-11:20:00[Pacific/Niue]"), [1, -1], 55 "-11:20:00 is accepted as -11:20:00 in the Pacific/Niue edge case" 56 ); 57 assert.throws( 58 RangeError, () => action("1952-10-15T23:59:59-11:19:50[Pacific/Niue]"), 59 "wrong :SS not accepted in the Pacific/Niue edge case" 60 ); 61 62 reportCompare(0, 0);