argument-duration-max.js (2383B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2023 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.duration.compare 7 description: Maximum allowed duration 8 features: [Temporal] 9 ---*/ 10 11 const maxCases = [ 12 ["P104249991374DT7H36M31.999999999S", "string with max days"], 13 [{ days: 104249991374, nanoseconds: 27391999999999 }, "property bag with max days"], 14 ["PT2501999792983H36M31.999999999S", "string with max hours"], 15 [{ hours: 2501999792983, nanoseconds: 2191999999999 }, "property bag with max hours"], 16 ["PT150119987579016M31.999999999S", "string with max minutes"], 17 [{ minutes: 150119987579016, nanoseconds: 31999999999 }, "property bag with max minutes"], 18 ["PT9007199254740991.999999999S", "string with max seconds"], 19 [{ seconds: 9007199254740991, nanoseconds: 999999999 }, "property bag with max seconds"], 20 ]; 21 22 for (const [arg, descr] of maxCases) { 23 const result1 = Temporal.Duration.compare(arg, new Temporal.Duration()); 24 assert.sameValue(result1, 1, `operation succeeds with ${descr} (first argument)`); 25 const result2 = Temporal.Duration.compare(new Temporal.Duration(), arg); 26 assert.sameValue(result2, -1, `operation succeeds with ${descr} (second argument)`); 27 } 28 29 const minCases = [ 30 ["-P104249991374DT7H36M31.999999999S", "string with min days"], 31 [{ days: -104249991374, nanoseconds: -27391999999999 }, "property bag with min days"], 32 ["-PT2501999792983H36M31.999999999S", "string with min hours"], 33 [{ hours: -2501999792983, nanoseconds: -2191999999999 }, "property bag with min hours"], 34 ["-PT150119987579016M31.999999999S", "string with min minutes"], 35 [{ minutes: -150119987579016, nanoseconds: -31999999999 }, "property bag with min minutes"], 36 ["-PT9007199254740991.999999999S", "string with min seconds"], 37 [{ seconds: -9007199254740991, nanoseconds: -999999999 }, "property bag with min seconds"], 38 ]; 39 40 for (const [arg, descr] of minCases) { 41 const result1 = Temporal.Duration.compare(arg, new Temporal.Duration()); 42 assert.sameValue(result1, -1, `operation succeeds with ${descr} (first argument)`); 43 const result2 = Temporal.Duration.compare(new Temporal.Duration(), arg); 44 assert.sameValue(result2, 1, `operation succeeds with ${descr} (second argument)`); 45 } 46 47 reportCompare(0, 0);