Source code
Revision control
Copy as Markdown
Other Tools
// |reftest| skip-if(!this.hasOwnProperty("Intl"))
// formatRange() returns the same output as format() when the date-time difference between
// the start and end date is too small.
// - Best-fit pattern for the skeleton "MMMMMdd" is "M月dd日".
// - Best-fit pattern for the skeleton "Mdd" is "M/dd".
//
// So in both cases the skeleton characters in the pattern are "Mdd", which means we can't
// retrieve the original input skeleton by simply inspecting the resolved pattern.
//
{
let dtf = new Intl.DateTimeFormat("zh", {month: "narrow", day: "2-digit", timeZone: "UTC"});
assertEq(dtf.formatRange(0, 0), dtf.format(0));
}
// Test that date-/time-style leads to the same output.
{
let dtf = new Intl.DateTimeFormat("en", {dateStyle: "full", timeStyle: "full"});
assertEq(dtf.formatRange(0, 0), dtf.format(0));
}
// Test that the hourCycle option is correctly processed (test with h24).
{
let dtf = new Intl.DateTimeFormat("en-u-hc-h24", {hour: "2-digit", timeZone:"UTC"});
assertEq(dtf.formatRange(0, 0), dtf.format(0));
}
{
let dtf = new Intl.DateTimeFormat("en", {hourCycle: "h24", hour: "2-digit", timeZone:"UTC"});
assertEq(dtf.formatRange(0, 0), dtf.format(0));
}
// Test that the hourCycle option is correctly processed (test with h11).
{
let dt = 60 * 60 * 1000; // one hour
let dtf = new Intl.DateTimeFormat("en-u-hc-h11", {hour: "2-digit", timeZone:"UTC"});
assertEq(dtf.formatRange(dt, dt), dtf.format(dt));
}
{
let dt = 60 * 60 * 1000; // one hour
let dtf = new Intl.DateTimeFormat("en", {hourCycle: "h11", hour: "2-digit", timeZone:"UTC"});
assertEq(dtf.formatRange(dt, dt), dtf.format(dt));
}
// Test that non-default calendars work correctly.
{
let dtf = new Intl.DateTimeFormat("en-001-u-ca-hebrew");
assertEq(dtf.formatRange(0, 0), dtf.format(0));
}
if (typeof reportCompare === "function")
reportCompare(0, 0);