tor-browser

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

argument-propertybag-timezone-string-datetime.js (2435B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2021 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: Conversion of ISO date-time strings to time zone IDs
      8 features: [Temporal]
      9 ---*/
     10 
     11 const instance = new Temporal.ZonedDateTime(0n, "UTC");
     12 
     13 let timeZone = "2021-08-19T17:30";
     14 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare({ year: 2000, month: 5, day: 2, timeZone }, instance), "bare date-time string is not a time zone (arg 1)");
     15 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(instance, { year: 2000, month: 5, day: 2, timeZone }), "bare date-time string is not a time zone (arg 2)");
     16 
     17 [
     18  "2021-08-19T17:30-07:00:01",
     19  "2021-08-19T17:30-07:00:00",
     20  "2021-08-19T17:30-07:00:00.1",
     21  "2021-08-19T17:30-07:00:00.0",
     22  "2021-08-19T17:30-07:00:00.01",
     23  "2021-08-19T17:30-07:00:00.00",
     24  "2021-08-19T17:30-07:00:00.001",
     25  "2021-08-19T17:30-07:00:00.000",
     26  "2021-08-19T17:30-07:00:00.0001",
     27  "2021-08-19T17:30-07:00:00.0000",
     28  "2021-08-19T17:30-07:00:00.00001",
     29  "2021-08-19T17:30-07:00:00.00000",
     30  "2021-08-19T17:30-07:00:00.000001",
     31  "2021-08-19T17:30-07:00:00.000000",
     32  "2021-08-19T17:30-07:00:00.0000001",
     33  "2021-08-19T17:30-07:00:00.0000000",
     34  "2021-08-19T17:30-07:00:00.00000001",
     35  "2021-08-19T17:30-07:00:00.00000000",
     36  "2021-08-19T17:30-07:00:00.000000001",
     37  "2021-08-19T17:30-07:00:00.000000000",
     38 ].forEach((timeZone) => {
     39  assert.throws(
     40    RangeError,
     41    () => Temporal.ZonedDateTime.compare({ year: 2000, month: 5, day: 2, timeZone }, instance),
     42    `ISO string ${timeZone} with a sub-minute offset is not a valid time zone (arg 1)`
     43  );
     44  assert.throws(
     45    RangeError,
     46    () => Temporal.ZonedDateTime.compare(instance, { year: 2000, month: 5, day: 2, timeZone }),
     47    `ISO string ${timeZone} with a sub-minute offset is not a valid time zone (arg 2)`
     48  );
     49 });
     50 
     51 // The following are all valid strings so should not throw:
     52 
     53 [
     54  "2021-08-19T17:30Z",
     55  "2021-08-19T17:30-07:00",
     56  "2021-08-19T17:30[UTC]",
     57  "2021-08-19T17:30Z[UTC]",
     58  "2021-08-19T17:30-07:00[UTC]",
     59 ].forEach((timeZone) => {
     60  Temporal.ZonedDateTime.compare({ year: 2000, month: 5, day: 2, timeZone }, instance);
     61  Temporal.ZonedDateTime.compare(instance, { year: 2000, month: 5, day: 2, timeZone });
     62 });
     63 
     64 reportCompare(0, 0);