mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Test all combinations in temporal-plainmonthday-formatting-datetime-style
This commit is contained in:
parent
24f6f7a014
commit
a55bf7da9e
@ -8,74 +8,78 @@ locale: [en-US]
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const dateFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeZone: "Pacific/Apia" });
|
const locale = "en-US";
|
||||||
const dateFormatterMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeZone: "Pacific/Apia" });
|
const timeZone = "Pacific/Apia";
|
||||||
const dateFormatterLong = new Intl.DateTimeFormat("en-US", { dateStyle: "long", timeZone: "Pacific/Apia" });
|
|
||||||
const dateFormatterFull = new Intl.DateTimeFormat("en-US", { dateStyle: "full", timeZone: "Pacific/Apia" });
|
const dateStyles = [
|
||||||
const timeFormatterShort = new Intl.DateTimeFormat("en-US", { timeStyle: "short", timeZone: "Pacific/Apia" });
|
"full", "long", "medium", "short",
|
||||||
const timeFormatterMedium = new Intl.DateTimeFormat("en-US", { timeStyle: "medium", timeZone: "Pacific/Apia" });
|
];
|
||||||
const timeFormatterLong = new Intl.DateTimeFormat("en-US", { timeStyle: "long", timeZone: "Pacific/Apia" });
|
|
||||||
const timeFormatterFull = new Intl.DateTimeFormat("en-US", { timeStyle: "full", timeZone: "Pacific/Apia" });
|
const timeStyles = [
|
||||||
const dateTimeFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "short", timeZone: "Pacific/Apia" });
|
"full", "long", "medium", "short",
|
||||||
const dateTimeFormatterMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeStyle: "medium", timeZone: "Pacific/Apia" });
|
];
|
||||||
const dateTimeFormatterLong = new Intl.DateTimeFormat("en-US", { dateStyle: "long", timeStyle: "long", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterFull = new Intl.DateTimeFormat("en-US", { dateStyle: "full", timeStyle: "full", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterShortLong = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "long", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterShortMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "medium", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterShortFull = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "full", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterMediumLong = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeStyle: "long", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterMediumShort = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeStyle: "short", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterMediumFull = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeStyle: "full", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterLongMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "long", timeStyle: "medium", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterLongShort = new Intl.DateTimeFormat("en-US", { dateStyle: "long", timeStyle: "short", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterLongFull = new Intl.DateTimeFormat("en-US", { dateStyle: "long", timeStyle: "full", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterFullMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "full", timeStyle: "medium", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterFullShort = new Intl.DateTimeFormat("en-US", { dateStyle: "full", timeStyle: "short", timeZone: "Pacific/Apia" });
|
|
||||||
const dateTimeFormatterFullLong = new Intl.DateTimeFormat("en-US", { dateStyle: "full", timeStyle: "long", timeZone: "Pacific/Apia" });
|
|
||||||
|
|
||||||
// Use a reference year so we can check that it doesn't occur in any string output
|
// Use a reference year so we can check that it doesn't occur in any string output
|
||||||
const monthday = new Temporal.PlainMonthDay(3, 4, "gregory", 5678);
|
const monthday = new Temporal.PlainMonthDay(3, 4, "gregory", 5678);
|
||||||
|
|
||||||
const monthdayResultShort = dateFormatterShort.format(monthday);
|
const expected = {
|
||||||
// assert.sameValue(monthdayResultShort, "3/4", "plain monthday, dateStyle=short");
|
// "March 4"
|
||||||
assert.sameValue(monthdayResultShort.search("78"), -1, "plain monthday, dateStyle=short: year should not appear");
|
full: {
|
||||||
assert.notSameValue(monthdayResultShort.search("3"), -1, "plain monthday, dateStyle=short: month should appear");
|
year: ["5678", false],
|
||||||
assert.notSameValue(monthdayResultShort.search("4"), -1, "plain monthday, dateStyle=short: day should appear");
|
month: ["3", false],
|
||||||
|
day: ["4", true],
|
||||||
|
},
|
||||||
|
|
||||||
const monthdayResultMedium = dateFormatterMedium.format(monthday);
|
// "March 4"
|
||||||
// assert.sameValue(monthdayResultMedium, "Mar 4", "plain monthday, dateStyle=medium");
|
long: {
|
||||||
assert.sameValue(monthdayResultMedium.search("5678"), -1, "plain monthday, dateStyle=medium: year should not appear");
|
year: ["5678", false],
|
||||||
assert.sameValue(monthdayResultMedium.search("3"), -1, "plain monthday, dateStyle=medium: numeric month should not appear");
|
month: ["3", false],
|
||||||
assert.notSameValue(monthdayResultMedium.search("4"), -1, "plain monthday, dateStyle=medium: day should appear");
|
day: ["4", true],
|
||||||
|
},
|
||||||
|
|
||||||
const monthdayResultLong = dateFormatterLong.format(monthday);
|
// "Mar 4"
|
||||||
// assert.sameValue(monthdayResultLong, "March 4", "plain monthday, dateStyle=long");
|
medium: {
|
||||||
assert.sameValue(monthdayResultLong.search("5678"), -1, "plain monthday, dateStyle=long: year should not appear");
|
year: ["5678", false],
|
||||||
assert.sameValue(monthdayResultLong.search("3"), -1, "plain monthday, dateStyle=long: numeric month should not appear");
|
month: ["3", false],
|
||||||
assert.notSameValue(monthdayResultLong.search("4"), -1, "plain monthday, dateStyle=long: day should appear");
|
day: ["4", true],
|
||||||
|
},
|
||||||
|
|
||||||
const monthdayResultFull = dateFormatterFull.format(monthday);
|
// "3/4"
|
||||||
// assert.sameValue(monthdayResultFull, "March 4", "plain monthday, dateStyle=full");
|
short: {
|
||||||
assert.sameValue(monthdayResultFull.search("5678"), -1, "plain monthday, dateStyle=full: year should not appear");
|
year: ["78", false],
|
||||||
assert.sameValue(monthdayResultFull.search("3"), -1, "plain monthday, dateStyle=full: numeric month should not appear");
|
month: ["3", true],
|
||||||
assert.notSameValue(monthdayResultFull.search("4"), -1, "plain monthday, dateStyle=full: day should appear");
|
day: ["4", true],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
assert.throws(TypeError, () => timeFormatterShort.format(monthday), "plain monthday, timeStyle=short");
|
function ensureDateField(result, field, dateStyle) {
|
||||||
assert.throws(TypeError, () => timeFormatterMedium.format(monthday), "plain monthday, timeStyle=medium");
|
let [searchValue, present] = expected[dateStyle][field];
|
||||||
assert.throws(TypeError, () => timeFormatterLong.format(monthday), "plain monthday, timeStyle=long");
|
let verb = present ? "should" : "should not";
|
||||||
assert.throws(TypeError, () => timeFormatterFull.format(monthday), "plain monthday, timeStyle=full");
|
|
||||||
|
|
||||||
var monthdayResult = dateTimeFormatterShort.format(monthday);
|
assert.sameValue(
|
||||||
assert.sameValue(monthdayResult, monthdayResultShort, "plain monthday, dateStyle = timeStyle = short: should match output with dateStyle only");
|
result.includes(searchValue),
|
||||||
|
present,
|
||||||
|
`dateStyle=${dateStyle}: ${field} ${verb} appear`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
monthdayResult = dateTimeFormatterMedium.format(monthday);
|
// timeStyle throws when no dateStyle is present.
|
||||||
assert.sameValue(monthdayResult, monthdayResultMedium, "plain monthday, dateStyle = timeStyle = medium: should match output with dateStyle only");
|
for (let timeStyle of timeStyles) {
|
||||||
|
let dtf = new Intl.DateTimeFormat(locale, {timeStyle, timeZone});
|
||||||
|
assert.throws(TypeError, () => dtf.format(monthday), `timeStyle=${timeStyle}`);
|
||||||
|
}
|
||||||
|
|
||||||
monthdayResult = dateTimeFormatterLong.format(monthday);
|
for (let dateStyle of dateStyles) {
|
||||||
assert.sameValue(monthdayResult, monthdayResultLong, "plain monthday, dateStyle = timeStyle = long: should match output with dateStyle only");
|
let dtf = new Intl.DateTimeFormat(locale, {dateStyle, timeZone});
|
||||||
|
let result = dtf.format(monthday);
|
||||||
|
|
||||||
monthdayResult = dateTimeFormatterFull.format(monthday);
|
ensureDateField(result, "year", dateStyle);
|
||||||
assert.sameValue(monthdayResult, monthdayResultLong, "plain monthday, dateStyle = timeStyle = full: should match output with dateStyle only");
|
ensureDateField(result, "month", dateStyle);
|
||||||
|
ensureDateField(result, "day", dateStyle);
|
||||||
|
|
||||||
monthdayResult = dateTimeFormatterShortLong.format(monthday);
|
// timeStyle is ignored when dateStyle is present.
|
||||||
assert.sameValue(monthdayResult, monthdayResultShort, "plain monthday, dateStyle short, = timeStyle = long: should match output with dateStyle only");
|
for (let timeStyle of timeStyles) {
|
||||||
|
let dtf = new Intl.DateTimeFormat(locale, {dateStyle, timeStyle, timeZone});
|
||||||
|
assert.sameValue(dtf.format(monthday), result, `dateStyle = ${dateStyle}, timeStyle = ${timeStyle}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user