tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

relativeto-string-limits.js (1561B)


      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.duration.compare
      7 description: ISO strings at the edges of the representable range
      8 features: [Temporal]
      9 ---*/
     10 
     11 const instance = new Temporal.Duration(0, 0, 0, 0, 0, /* minutes = */ 5);
     12 const blankInstance = new Temporal.Duration();
     13 
     14 const validStrings = [
     15  "-271821-04-20T00:00Z[UTC]",
     16  "+275760-09-13T00:00Z[UTC]",
     17  "+275760-09-13T01:00+01:00[+01:00]",
     18  "+275760-09-13T23:59+23:59[+23:59]",
     19  "-271821-04-19",
     20  "-271821-04-19T01:00",
     21  "+275760-09-13",
     22  "+275760-09-13T23:00",
     23 ];
     24 
     25 for (const relativeTo of validStrings) {
     26  Temporal.Duration.compare(instance, blankInstance, { relativeTo });
     27 }
     28 
     29 const invalidStrings = [
     30  "-271821-04-19T23:00-01:00[-01:00]",
     31  "-271821-04-19T00:01-23:59[-23:59]",
     32  "-271821-04-19T23:59:59.999999999Z[UTC]",
     33  "-271821-04-19T23:00-00:59[-00:59]",
     34  "-271821-04-19T00:00:00-23:59[-23:59]",
     35  "+275760-09-13T00:00:00.000000001Z[UTC]",
     36  "+275760-09-13T01:00+00:59[+00:59]",
     37  "+275760-09-14T00:00+23:59[+23:59]",
     38  "-271821-04-18",
     39  "-271821-04-18T23:00",
     40  "+275760-09-14",
     41  "+275760-09-14T01:00",
     42 ];
     43 
     44 for (const relativeTo of invalidStrings) {
     45  assert.throws(
     46    RangeError,
     47    () => Temporal.Duration.compare(instance, blankInstance, { relativeTo }),
     48    `"${relativeTo}" is outside the representable range for a relativeTo parameter`
     49  );
     50 }
     51 
     52 reportCompare(0, 0);