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 (2646B)


      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.from
      7 description: Conversion of ISO date-time strings to time zone IDs
      8 features: [Temporal]
      9 ---*/
     10 
     11 let timeZone = "2021-08-19T17:30";
     12 assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone }), "bare date-time string is not a time zone");
     13 
     14 [
     15  "2021-08-19T17:30-07:00:01",
     16  "2021-08-19T17:30-07:00:00",
     17  "2021-08-19T17:30-07:00:00.1",
     18  "2021-08-19T17:30-07:00:00.0",
     19  "2021-08-19T17:30-07:00:00.01",
     20  "2021-08-19T17:30-07:00:00.00",
     21  "2021-08-19T17:30-07:00:00.001",
     22  "2021-08-19T17:30-07:00:00.000",
     23  "2021-08-19T17:30-07:00:00.0001",
     24  "2021-08-19T17:30-07:00:00.0000",
     25  "2021-08-19T17:30-07:00:00.00001",
     26  "2021-08-19T17:30-07:00:00.00000",
     27  "2021-08-19T17:30-07:00:00.000001",
     28  "2021-08-19T17:30-07:00:00.000000",
     29  "2021-08-19T17:30-07:00:00.0000001",
     30  "2021-08-19T17:30-07:00:00.0000000",
     31  "2021-08-19T17:30-07:00:00.00000001",
     32  "2021-08-19T17:30-07:00:00.00000000",
     33  "2021-08-19T17:30-07:00:00.000000001",
     34  "2021-08-19T17:30-07:00:00.000000000",
     35 ].forEach((timeZone) => {
     36  assert.throws(
     37    RangeError,
     38    () => Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone }),
     39    `ISO string ${timeZone} with a sub-minute offset is not a valid time zone`
     40  );
     41 });
     42 
     43 timeZone = "2021-08-19T17:30Z";
     44 const result1 = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone });
     45 assert.sameValue(result1.timeZoneId, "UTC", "date-time + Z is UTC time zone");
     46 
     47 timeZone = "2021-08-19T17:30-07:00";
     48 const result2 = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone });
     49 assert.sameValue(result2.timeZoneId, "-07:00", "date-time + offset is the offset time zone");
     50 
     51 timeZone = "2021-08-19T17:30[UTC]";
     52 const result3 = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone });
     53 assert.sameValue(result3.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone");
     54 
     55 timeZone = "2021-08-19T17:30Z[UTC]";
     56 const result4 = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone });
     57 assert.sameValue(result4.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
     58 
     59 timeZone = "2021-08-19T17:30-07:00[UTC]";
     60 const result5 = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone });
     61 assert.sameValue(result5.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone");
     62 
     63 reportCompare(0, 0);