tor-browser

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

formatRange-timeZoneName.js (6067B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 // Test all "timeZoneName" options with various locales when formatting a
      4 // date-time range.
      5 
      6 const {
      7  Hour, Minute, Literal, TimeZoneName,
      8 } = DateTimeFormatParts;
      9 
     10 function hours(v) {
     11  return v * 60 * 60 * 1000;
     12 }
     13 
     14 function minutes(v) {
     15  return v * 60 * 1000;
     16 }
     17 
     18 const tests = {
     19  "en": [
     20    {
     21      start: 0,
     22      end: minutes(2),
     23      timeZone: "UTC",
     24      options: {hour: "numeric", minute: "numeric", hour12: false},
     25      timeZoneNames: {
     26        short: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("UTC")],
     27        shortOffset: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT+0")],
     28        shortGeneric: "shortOffset",
     29        long: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Coordinated Universal Time")],
     30        longOffset: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT+00:00")],
     31        longGeneric: "longOffset",
     32      },
     33    },
     34    {
     35      start: 0,
     36      end: minutes(2),
     37      timeZone: "America/New_York",
     38      options: {hour: "numeric", minute: "numeric", hour12: false},
     39      timeZoneNames: {
     40        short: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("EST")],
     41        shortOffset: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT-5")],
     42        shortGeneric: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("ET")],
     43        long: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Eastern Standard Time")],
     44        longOffset: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT-05:00")],
     45        longGeneric: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Eastern Time")],
     46      },
     47    },
     48  ],
     49  "fr": [
     50    {
     51      start: 0,
     52      end: hours(2),
     53      timeZone: "UTC",
     54      options: {hour: "numeric", hour12: false},
     55      timeZoneNames: {
     56        short: [Hour("00"), Literal(" – "), Hour("02"), Literal(" "), TimeZoneName("UTC")],
     57        shortOffset: [Hour("00"), Literal(" – "), Hour("02"), Literal(" "), TimeZoneName("UTC+0")],
     58        shortGeneric: "shortOffset",
     59        long: [Hour("00"), Literal(" – "), Hour("02"), Literal(" "), TimeZoneName("temps universel coordonné")],
     60        longOffset: [Hour("00"), Literal(" – "), Hour("02"), Literal(" "), TimeZoneName("UTC+00:00")],
     61        longGeneric: "longOffset",
     62      },
     63    },
     64    {
     65      start: minutes(15),
     66      end: hours(5) + minutes(30),
     67      timeZone: "Europe/Paris",
     68      options: {hour: "numeric", minute: "numeric", hour12: false},
     69      timeZoneNames: {
     70        short: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("UTC+1")],
     71        shortOffset: "short",
     72        shortGeneric: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("heure : France")],
     73        long: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("heure normale d’Europe centrale")],
     74        longOffset: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("UTC+01:00")],
     75        longGeneric: "long",
     76      },
     77    },
     78  ],
     79  "de": [
     80    {
     81      start: 0,
     82      end: hours(2),
     83      timeZone: "UTC",
     84      options: {hour: "numeric", hour12: false},
     85      timeZoneNames: {
     86        short: [Hour("00"), Literal("–"), Hour("02"), Literal(" Uhr "), TimeZoneName("UTC")],
     87        shortOffset: [Hour("00"), Literal("–"), Hour("02"), Literal(" Uhr "), TimeZoneName("GMT+0")],
     88        shortGeneric: "shortOffset",
     89        long: [Hour("00"), Literal("–"), Hour("02"), Literal(" Uhr "), TimeZoneName("Koordinierte Weltzeit")],
     90        longOffset: [Hour("00"), Literal("–"), Hour("02"), Literal(" Uhr "), TimeZoneName("GMT+00:00")],
     91        longGeneric: "longOffset",
     92      },
     93    },
     94    {
     95      start: hours(5) + minutes(15),
     96      end: hours(5) + minutes(30),
     97      timeZone: "Europe/Berlin",
     98      options: {hour: "numeric", minute: "numeric", hour12: false},
     99      timeZoneNames: {
    100        short: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("MEZ")],
    101        shortOffset: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("GMT+1")],
    102        shortGeneric: "short",
    103        long: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("Mitteleuropäische Normalzeit")],
    104        longOffset: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("GMT+01:00")],
    105        longGeneric: "long",
    106      },
    107    },
    108  ],
    109 };
    110 
    111 for (let [locale, formats] of Object.entries(tests)) {
    112  for (let {start, end, timeZone, options, timeZoneNames} of formats) {
    113    for (let [timeZoneName, format] of Object.entries(timeZoneNames)) {
    114      let df = new Intl.DateTimeFormat(locale, {timeZone, timeZoneName, ...options});
    115      if (typeof format === "string") {
    116        format = timeZoneNames[format];
    117      }
    118      assertRangeParts(df, start, end, format);
    119    }
    120  }
    121 }
    122 
    123 if (typeof reportCompare === "function")
    124  reportCompare(0, 0, "ok");