tor-browser

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

timeZones.js (2187B)


      1 // Copyright (C) 2021 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-intl.supportedvaluesof
      6 description: >
      7  The returned "timeZone" values are sorted, unique, and canonicalised.
      8 info: |
      9  Intl.supportedValuesOf ( key )
     10 
     11  1. Let key be ? ToString(key).
     12  ...
     13  6. Else if key is "timeZone", then
     14    a. Let list be ! AvailableTimeZones( ).
     15  ...
     16  9. Return ! CreateArrayFromList( list ).
     17 
     18  AvailableTimeZones ()
     19    The AvailableTimeZones abstract operation returns a sorted List of supported
     20    Zone and Link names in the IANA Time Zone Database. The following steps are
     21    taken:
     22 
     23    1. Let names be a List of all supported Zone and Link names in the IANA Time
     24       Zone Database.
     25    2. Let result be a new empty List.
     26    3. For each element name of names, do
     27        a. Assert: ! IsValidTimeZoneName( name ) is true.
     28        b. Let canonical be ! CanonicalizeTimeZoneName( name ).
     29        c. If result does not contain an element equal to canonical, then
     30            i. Append canonical to the end of result.
     31    4. Sort result in order as if an Array of the same values had been sorted using
     32       %Array.prototype.sort% using undefined as comparefn.
     33    5. Return result.
     34 includes: [compareArray.js, testIntl.js]
     35 features: [Intl-enumeration]
     36 ---*/
     37 
     38 const timeZones = Intl.supportedValuesOf("timeZone");
     39 
     40 assert(Array.isArray(timeZones), "Returns an Array object.");
     41 assert.sameValue(Object.getPrototypeOf(timeZones), Array.prototype,
     42                 "The array prototype is Array.prototype");
     43 
     44 const otherTimeZones = Intl.supportedValuesOf("timeZone");
     45 assert.notSameValue(otherTimeZones, timeZones,
     46                    "Returns a new array object for each call.");
     47 
     48 assert.compareArray(timeZones, otherTimeZones.sort(),
     49                    "The array is sorted.");
     50 
     51 assert.sameValue(new Set(timeZones).size, timeZones.length,
     52                 "The array doesn't contain duplicates.");
     53 
     54 for (let timeZone of timeZones) {
     55  assert(isCanonicalizedStructurallyValidTimeZoneName(timeZone),
     56         `${timeZone} is a canonicalised and structurally valid time zone name`);
     57 }
     58 
     59 reportCompare(0, 0);