tor-browser

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

day-period.js (1276B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 const {
      4    Weekday, DayPeriod, Literal
      5 } = DateTimeFormatParts;
      6 
      7 const tests = [
      8    // https://unicode-org.atlassian.net/browse/ICU-20741
      9    {
     10        date: new Date("2019-01-01T12:00:00"),
     11        options: { dayPeriod: "long", weekday: "long", },
     12        locales: {
     13            "en-001": [Weekday("Tuesday"), Literal(", "), DayPeriod("noon")],
     14        },
     15    },
     16 
     17    // https://unicode-org.atlassian.net/browse/ICU-20740
     18    {
     19        date: new Date("2019-01-01T12:00:00"),
     20        options: { dayPeriod: "narrow", weekday: "long", },
     21        locales: {
     22            "bs-Cyrl": [Weekday("уторак"), Literal(" "), DayPeriod("подне")],
     23        },
     24    },
     25 ];
     26 
     27 for (let {date, options, locales} of tests) {
     28    for (let [locale, parts] of Object.entries(locales)) {
     29        let dtf = new Intl.DateTimeFormat(locale, options);
     30 
     31        assertEq(dtf.format(date), parts.map(({value}) => value).join(""),
     32                 `locale=${locale}, date=${date}, options=${JSON.stringify(options)}`);
     33 
     34        assertDeepEq(dtf.formatToParts(date), parts,
     35                     `locale=${locale}, date=${date}, options=${JSON.stringify(options)}`);
     36    }
     37 }
     38 
     39 if (typeof reportCompare === "function")
     40    reportCompare(0, 0, "ok");