roundtrip-from-property-bag.js (5560B)
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 Check that various dates created from a property bag have the expected 9 properties 10 includes: [temporalHelpers.js] 11 features: [Temporal, Intl.Era-monthcode] 12 ---*/ 13 14 const options = { overflow: "reject" }; 15 16 const cases = [ 17 ["buddhist", 2543, 1, "M01", "be", 2543, "month containing ISO date 2000-01-01"], 18 ["chinese", 1999, 11, "M11", undefined, undefined, "month containing ISO date 2000-01-01"], 19 ["coptic", 1716, 4, "M04", "am", 1716, "month containing ISO date 2000-01-01"], 20 ["dangi", 1999, 11, "M11", undefined, undefined, "month containing ISO date 2000-01-01"], 21 ["ethioaa", 7492, 4, "M04", "aa", 7492, "month containing ISO date 2000-01-01"], 22 ["ethiopic", 1992, 4, "M04", "am", 1992, "month containing ISO date 2000-01-01"], 23 ["gregory", 2000, 1, "M01", "ce", 2000, "month containing ISO date 2000-01-01"], 24 ["hebrew", 5760, 4, "M04", "am", 5760, "month containing ISO date 2000-01-01"], 25 ["indian", 1921, 10, "M10", "shaka", 1921, "month containing ISO date 2000-01-01"], 26 ["islamic-civil", 1420, 9, "M09", "ah", 1420, "month containing ISO date 2000-01-01"], 27 ["islamic-tbla", 1420, 9, "M09", "ah", 1420, "month containing ISO date 2000-01-01"], 28 ["islamic-umalqura", 1420, 9, "M09", "ah", 1420, "month containing ISO date 2000-01-01"], 29 ["japanese", 2000, 1, "M01", "heisei", 12, "month containing ISO date 2000-01-01"], 30 ["persian", 1378, 10, "M10", "ap", 1378, "month containing ISO date 2000-01-01"], 31 ["roc", 89, 1, "M01", "roc", 89, "month containing ISO date 2000-01-01"], 32 33 ["buddhist", 544, 1, "M01", "be", 544, "month containing ISO date 0001-01-01"], 34 // ["chinese", 0, 12, "M11", undefined, undefined, "month containing ISO date 0001-01-01"], // (out of specified range) 35 ["coptic", -283, 5, "M05", "am", -283, "month containing ISO date 0001-01-01"], 36 // ["dangi", 0, 12, "M11", undefined, undefined, "month containing ISO date 0001-01-01"], // (out of specified range) 37 ["ethioaa", 5493, 5, "M05", "aa", 5493, "month containing ISO date 0001-01-01"], 38 ["ethiopic", -7, 5, "M05", "aa", 5493, "month containing ISO date 0001-01-01"], 39 ["gregory", 1, 1, "M01", "ce", 1, "month containing ISO date 0001-01-01"], 40 ["hebrew", 3761, 4, "M04", "am", 3761, "month containing ISO date 0001-01-01"], 41 ["indian", -78, 10, "M10", "shaka", -78, "month containing ISO date 0001-01-01"], 42 ["islamic-civil", -640, 5, "M05", "bh", 641, "month containing ISO date 0001-01-01"], 43 ["islamic-tbla", -640, 5, "M05", "bh", 641, "month containing ISO date 0001-01-01"], 44 ["islamic-umalqura", -640, 5, "M05", "bh", 641, "month containing ISO date 0001-01-01"], 45 ["japanese", 1, 1, "M01", "ce", 1, "month containing ISO date 0001-01-01"], 46 ["persian", -621, 10, "M10", "ap", -621, "month containing ISO date 0001-01-01"], 47 ["roc", -1910, 1, "M01", "broc", 1911, "month containing ISO date 0001-01-01"], 48 49 // Additional cases that were moved in from staging tests, or that we add to 50 // catch regressions 51 ["chinese", 1900, 1, "M01", undefined, undefined, "start of non-approximated range"], 52 ["chinese", 2099, 13, "M12", undefined, undefined, "end of non-approximated range"], 53 ["dangi", 1900, 1, "M01", undefined, undefined, "start of non-approximated range"], 54 ["dangi", 2049, 12, "M12", undefined, undefined, "end of non-approximated range"], 55 ["islamic-civil", 1445, 1, "M01", "ah", 1445, "recent year"], 56 ["islamic-tbla", 1445, 1, "M01", "ah", 1445, "recent year"], 57 ["islamic-umalqura", 1445, 1, "M01", "ah", 1445, "recent year"], 58 ["islamic-umalqura", -6823, 1, "M01", "bh", 6824, "https://github.com/unicode-org/icu4x/issues/4914"], 59 ["persian", 1395, 1, "M01", "ap", 1395, "leap year 1395"], 60 ["persian", 1396, 1, "M01", "ap", 1396, "common year 1396"], 61 ["persian", 1397, 1, "M01", "ap", 1397, "common year 1397"], 62 ["persian", 1398, 1, "M01", "ap", 1398, "common year 1398"], 63 ["persian", 1399, 1, "M01", "ap", 1399, "leap year 1399"], 64 ["persian", 1400, 1, "M01", "ap", 1400, "common year 1400"], 65 ]; 66 67 for (const [calendar, year, month, monthCode, era, eraYear, descr] of cases) { 68 const dateFromYearMonth = Temporal.PlainYearMonth.from({ year, month, calendar }, options); 69 TemporalHelpers.assertPlainYearMonth( 70 dateFromYearMonth, 71 year, month, monthCode, 72 `${descr} (${calendar}) - created from year and month`, 73 era, eraYear, null); 74 75 const dateFromYearMonthCode = Temporal.PlainYearMonth.from({ year, monthCode, calendar }, options); 76 TemporalHelpers.assertPlainYearMonth( 77 dateFromYearMonthCode, 78 year, month, monthCode, 79 `${descr} (${calendar}) - created from year and month code`, 80 era, eraYear, null); 81 82 if (era === undefined) continue; // skip era-less calendars 83 84 const dateFromEraMonth = Temporal.PlainYearMonth.from({ era, eraYear, month, calendar }, options); 85 TemporalHelpers.assertPlainYearMonth( 86 dateFromEraMonth, 87 year, month, monthCode, 88 `${descr} (${calendar}) - created from era, era year, and month`, 89 era, eraYear, null); 90 91 const dateFromEraMonthCode = Temporal.PlainYearMonth.from({ era, eraYear, monthCode, calendar }, options); 92 TemporalHelpers.assertPlainYearMonth( 93 dateFromEraMonthCode, 94 year, month, monthCode, 95 `${descr} (${calendar}) - created from era, era year, and month code`, 96 era, eraYear, null); 97 } 98 99 reportCompare(0, 0);