tor-browser

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

era-boundary-japanese.js (7682B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2025 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.plainyearmonth.from
      7 description: >
      8  Dates in same year or years before era starts should resolve to previous era
      9  (Japanese calendar)
     10 includes: [temporalHelpers.js]
     11 features: [Temporal, Intl.Era-monthcode]
     12 ---*/
     13 
     14 const calendar = "japanese";
     15 const options = { overflow: "reject" };
     16 
     17 const reiwa1BeforeStart = Temporal.PlainYearMonth.from({ era: "reiwa", eraYear: 1, monthCode: "M04", calendar }, options);
     18 TemporalHelpers.assertPlainYearMonth(
     19  reiwa1BeforeStart,
     20  2019, 4, "M04", "Reiwa 1 resolves to Heisei 31 before era start date",
     21  "heisei", 31);
     22 
     23 const reiwa0 = Temporal.PlainYearMonth.from({ era: "reiwa", eraYear: 0, monthCode: "M05", calendar }, options);
     24 TemporalHelpers.assertPlainYearMonth(
     25  reiwa0,
     26  2018, 5, "M05", "Reiwa 0 resolves to Heisei 30",
     27  "heisei", 30);
     28 
     29 const reiwa1n = Temporal.PlainYearMonth.from({ era: "reiwa", eraYear: -1, monthCode: "M05", calendar }, options);
     30 TemporalHelpers.assertPlainYearMonth(
     31  reiwa1n,
     32  2017, 5, "M05", "Reiwa -1 resolves to Heisei 29",
     33  "heisei", 29);
     34 
     35 const heisei31AfterStart = Temporal.PlainYearMonth.from({ era: "heisei", eraYear: 31, monthCode: "M05", calendar }, options);
     36 TemporalHelpers.assertPlainYearMonth(
     37  heisei31AfterStart,
     38  2019, 5, "M05", "Heisei 31 resolves to Reiwa 1 after era start date",
     39  "reiwa", 1);
     40 
     41 const heisei1BeforeStart = Temporal.PlainYearMonth.from({ era: "heisei", eraYear: 1, monthCode: "M01", calendar }, options);
     42 TemporalHelpers.assertPlainYearMonth(
     43  heisei1BeforeStart,
     44  1989, 1, "M01", "Heisei 1 resolves to Showa 64 before era start date",
     45  "showa", 64);
     46 
     47 const heisei0 = Temporal.PlainYearMonth.from({ era: "heisei", eraYear: 0, monthCode: "M01", calendar }, options);
     48 TemporalHelpers.assertPlainYearMonth(
     49  heisei0,
     50  1988, 1, "M01", "Heisei 0 resolves to Showa 63",
     51  "showa", 63);
     52 
     53 const heisei1n = Temporal.PlainYearMonth.from({ era: "heisei", eraYear: -1, monthCode: "M01", calendar }, options);
     54 TemporalHelpers.assertPlainYearMonth(
     55  heisei1n,
     56  1987, 1, "M01", "Heisei -1 resolves to Showa 62",
     57  "showa", 62);
     58 
     59 const showa64AfterStart = Temporal.PlainYearMonth.from({ era: "showa", eraYear: 64, monthCode: "M02", calendar }, options);
     60 TemporalHelpers.assertPlainYearMonth(
     61  showa64AfterStart,
     62  1989, 2, "M02", "Showa 64 resolves to Heisei 1 after era start date",
     63  "heisei", 1);
     64 
     65 const showa1BeforeStart = Temporal.PlainYearMonth.from({ era: "showa", eraYear: 1, monthCode: "M12", calendar }, options);
     66 TemporalHelpers.assertPlainYearMonth(
     67  showa1BeforeStart,
     68  1926, 12, "M12", "Showa 1 resolves to Taisho 15 before era start date",
     69  "taisho", 15);
     70 
     71 const showa0 = Temporal.PlainYearMonth.from({ era: "showa", eraYear: 0, monthCode: "M12", calendar }, options);
     72 TemporalHelpers.assertPlainYearMonth(
     73  showa0,
     74  1925, 12, "M12", "Showa 0 resolves to Taisho 14",
     75  "taisho", 14);
     76 
     77 const showa1n = Temporal.PlainYearMonth.from({ era: "showa", eraYear: -1, monthCode: "M12", calendar }, options);
     78 TemporalHelpers.assertPlainYearMonth(
     79  showa1n,
     80  1924, 12, "M12", "Showa -1 resolves to Taisho 13",
     81  "taisho", 13);
     82 
     83 // There is no PlainYearMonth in which Taisho 15 resolves to Showa 1
     84 const taisho16 = Temporal.PlainYearMonth.from({ era: "taisho", eraYear: 16, monthCode: "M01", calendar }, options);
     85 TemporalHelpers.assertPlainYearMonth(
     86  taisho16,
     87  1927, 1, "M01", "Taisho 16 resolves to Showa 2",
     88  "showa", 2);
     89 
     90 const taisho1BeforeStart = Temporal.PlainYearMonth.from({ era: "taisho", eraYear: 1, monthCode: "M07", calendar }, options);
     91 TemporalHelpers.assertPlainYearMonth(
     92  taisho1BeforeStart,
     93  1912, 7, "M07", "Taisho 1 resolves to Meiji 45 before era start date",
     94  "meiji", 45);
     95 
     96 const taisho0 = Temporal.PlainYearMonth.from({ era: "taisho", eraYear: 0, monthCode: "M07", calendar }, options);
     97 TemporalHelpers.assertPlainYearMonth(
     98  taisho0,
     99  1911, 7, "M07", "Taisho 0 resolves to Meiji 44",
    100  "meiji", 44);
    101 
    102 const taisho1n = Temporal.PlainYearMonth.from({ era: "taisho", eraYear: -1, monthCode: "M07", calendar }, options);
    103 TemporalHelpers.assertPlainYearMonth(
    104  taisho1n,
    105  1910, 7, "M07", "Taisho -1 resolves to Meiji 43",
    106  "meiji", 43);
    107 
    108 const meiji45AfterStart = Temporal.PlainYearMonth.from({ era: "meiji", eraYear: 45, monthCode: "M08", calendar }, options);
    109 TemporalHelpers.assertPlainYearMonth(
    110  meiji45AfterStart,
    111  1912, 8, "M08", "Meiji 45 resolves to Taisho 1 after era start date",
    112  "taisho", 1);
    113 
    114 const meiji1BeforeStart = Temporal.PlainYearMonth.from({ era: "meiji", eraYear: 1, monthCode: "M10", calendar }, options);
    115 TemporalHelpers.assertPlainYearMonth(
    116  meiji1BeforeStart,
    117  1868, 10, "M10", "Meiji 1 resolves to CE 1868 before era start date",
    118  "ce", 1868);
    119 
    120 const meiji0 = Temporal.PlainYearMonth.from({ era: "meiji", eraYear: 0, monthCode: "M10", calendar }, options);
    121 TemporalHelpers.assertPlainYearMonth(
    122  meiji0,
    123  1867, 10, "M10", "Meiji 0 resolves to CE 1867",
    124  "ce", 1867);
    125 
    126 const meiji1n = Temporal.PlainYearMonth.from({ era: "meiji", eraYear: -1, monthCode: "M10", calendar }, options);
    127 TemporalHelpers.assertPlainYearMonth(
    128  meiji1n,
    129  1866, 10, "M10", "Meiji -1 resolves to CE 1866",
    130  "ce", 1866);
    131 
    132 const ce1868AfterStart = Temporal.PlainYearMonth.from({ era: "ce", eraYear: 1868, monthCode: "M11", calendar }, options);
    133 TemporalHelpers.assertPlainYearMonth(
    134  ce1868AfterStart,
    135  1868, 11, "M11", "CE 1868 resolves to Meiji 1 after era start date",
    136  "meiji", 1);
    137 
    138 const ce0 = Temporal.PlainYearMonth.from({ era: "ce", eraYear: 0, monthCode: "M01", calendar }, options);
    139 TemporalHelpers.assertPlainYearMonth(
    140  ce0,
    141  0, 1, "M01", "CE 0 resolves to BCE 1",
    142  "bce", 1);
    143 
    144 const ce1n = Temporal.PlainYearMonth.from({ era: "ce", eraYear: -1, monthCode: "M01", calendar }, options);
    145 TemporalHelpers.assertPlainYearMonth(
    146  ce1n,
    147  -1, 1, "M01", "CE -1 resolves to BCE 2",
    148  "bce", 2);
    149 
    150 const bce0 = Temporal.PlainYearMonth.from({ era: "bce", eraYear: 0, monthCode: "M01", calendar }, options);
    151 TemporalHelpers.assertPlainYearMonth(
    152  bce0,
    153  1, 1, "M01", "BCE 0 resolves to CE 1",
    154  "ce", 1);
    155 
    156 const bce1n = Temporal.PlainYearMonth.from({ era: "bce", eraYear: -1, monthCode: "M01", calendar }, options);
    157 TemporalHelpers.assertPlainYearMonth(
    158  bce1n,
    159  2, 1, "M01", "BCE -1 resolves to CE 2",
    160  "ce", 2);
    161 
    162 // Years far after the end of an era
    163 
    164 const heisei100 = Temporal.PlainYearMonth.from({ era: "heisei", eraYear: 100, monthCode: "M12", calendar }, options);
    165 TemporalHelpers.assertPlainYearMonth(
    166  heisei100,
    167  2088, 12, "M12", "Heisei 100 resolves to Reiwa 70",
    168  "reiwa", 70);
    169 
    170 const showa100 = Temporal.PlainYearMonth.from({ era: "showa", eraYear: 100, monthCode: "M12", calendar }, options);
    171 TemporalHelpers.assertPlainYearMonth(
    172  showa100,
    173  2025, 12, "M12", "Showa 100 resolves to Reiwa 7",
    174  "reiwa", 7);
    175 
    176 const taisho100 = Temporal.PlainYearMonth.from({ era: "taisho", eraYear: 100, monthCode: "M12", calendar }, options);
    177 TemporalHelpers.assertPlainYearMonth(
    178  taisho100,
    179  2011, 12, "M12", "Taisho 100 resolves to Heisei 23",
    180  "heisei", 23);
    181 
    182 const meiji100 = Temporal.PlainYearMonth.from({ era: "meiji", eraYear: 100, monthCode: "M12", calendar }, options);
    183 TemporalHelpers.assertPlainYearMonth(
    184  meiji100,
    185  1967, 12, "M12", "Meiji 100 resolves to Showa 42",
    186  "showa", 42);
    187 
    188 const ce2000 = Temporal.PlainYearMonth.from({ era: "ce", eraYear: 2000, monthCode: "M12", calendar }, options);
    189 TemporalHelpers.assertPlainYearMonth(
    190  ce2000,
    191  2000, 12, "M12", "CE 2000 resolves to Heisei 12",
    192  "heisei", 12);
    193 
    194 reportCompare(0, 0);