argument-string-limits.js (1498B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2024 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: ISO strings at the edges of the representable range 8 features: [Temporal] 9 ---*/ 10 11 const instance = new Temporal.ZonedDateTime(0n, "UTC"); 12 13 const validStrings = [ 14 "-271821-04-20T00:00Z[UTC]", 15 "+275760-09-13T00:00Z[UTC]", 16 "+275760-09-13T01:00+01:00[+01:00]", 17 "+275760-09-13T23:59+23:59[+23:59]", 18 ]; 19 20 for (const arg of validStrings) { 21 Temporal.ZonedDateTime.compare(arg, instance); 22 Temporal.ZonedDateTime.compare(instance, arg); 23 } 24 25 const invalidStrings = [ 26 "-271821-04-19T23:00-01:00[-01:00]", 27 "-271821-04-19T00:01-23:59[-23:59]", 28 "-271821-04-19T23:59:59.999999999Z[UTC]", 29 "-271821-04-19T23:00-00:59[-00:59]", 30 "-271821-04-19T00:00:00-23:59[-23:59]", 31 "+275760-09-13T00:00:00.000000001Z[UTC]", 32 "+275760-09-13T01:00+00:59[+00:59]", 33 "+275760-09-14T00:00+23:59[+23:59]", 34 ]; 35 36 for (const arg of invalidStrings) { 37 assert.throws( 38 RangeError, 39 () => Temporal.ZonedDateTime.compare(arg, instance), 40 `"${arg}" is outside the representable range of ZonedDateTime (first argument)` 41 ); 42 assert.throws( 43 RangeError, 44 () => Temporal.ZonedDateTime.compare(instance, arg), 45 `"${arg}" is outside the representable range of ZonedDateTime (second argument)` 46 ); 47 } 48 49 reportCompare(0, 0);