formatRange-gregorian-proleptic.js (1182B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 3 // Ensure formatRange() uses a proleptic Gregorian calendar. 4 // ICU bug: https://unicode-org.atlassian.net/browse/ICU-20705 5 6 let dtf = new Intl.DateTimeFormat("en", {timeZone: "UTC"}); 7 8 // The Gregorian calendar was first introduced in 15 October 1582. 9 const firstGregorian = new Date("1582-10-15"); 10 assertEq(dtf.formatRange(firstGregorian, firstGregorian), dtf.format(firstGregorian)); 11 12 // To deal with the ten days' difference between the Julian and the Gregorian calendar, some days 13 // were skipped, so that 4 October 1582 was followed by 15 October 1582. 14 const lastJulian = new Date("1582-10-04"); 15 assertEq(dtf.formatRange(lastJulian, lastJulian), dtf.format(lastJulian)); 16 17 function rangePart(source, parts) { 18 return parts.filter(x => x.source === source).map(x => x.value).join(""); 19 } 20 21 // Test with non-empty range. 22 assertEq(rangePart("startRange", dtf.formatRangeToParts(lastJulian, firstGregorian)), 23 dtf.format(lastJulian)); 24 assertEq(rangePart("endRange", dtf.formatRangeToParts(lastJulian, firstGregorian)), 25 dtf.format(firstGregorian)); 26 27 if (typeof reportCompare === "function") 28 reportCompare(0, 0);