Split temporal-objects-formatting.js into separate files for each Temporal type

This commit is contained in:
André Bargull 2025-05-22 09:45:41 +02:00 committed by Ms2ger
parent ef71f5e2a6
commit 36c81b9761
5 changed files with 295 additions and 169 deletions

View File

@ -0,0 +1,64 @@
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-datetime-format-functions
description: Different combinations of style options and Temporal.PlainDate format correctly.
locale: [en-US]
features: [Temporal]
---*/
const dateFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeZone: "Pacific/Apia" });
const dateFormatterMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", 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 timeFormatterShort = new Intl.DateTimeFormat("en-US", { timeStyle: "short", timeZone: "Pacific/Apia" });
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 dateTimeFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "short", timeZone: "Pacific/Apia" });
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" });
const date = new Temporal.PlainDate(2021, 8, 4);
const dateShort = dateFormatterShort.format(date);
/*
To avoid requiring an exact format for the output of locale-dependent functions,
don't run these tests, but they're left here as documentation for what the output
should roughly look like.
*/
// assert.sameValue(dateShort, "8/4/21", "plain date, dateStyle=short");
const dateMedium = dateFormatterMedium.format(date);
// assert.sameValue(dateMedium, "Aug 4, 2021", "plain date, dateStyle=medium");
const dateLong = dateFormatterLong.format(date);
// assert.sameValue(dateLong, "August 4, 2021", "plain date, dateStyle=long");
const dateFull = dateFormatterFull.format(date);
// assert.sameValue(dateFull, "Wednesday, August 4, 2021", "plain date, dateStyle=full");
assert.throws(TypeError, () => timeFormatterShort.format(date), "plain date, timeStyle=short");
assert.throws(TypeError, () => timeFormatterMedium.format(date), "plain date, timeStyle=medium");
assert.throws(TypeError, () => timeFormatterLong.format(date), "plain date, timeStyle=long");
assert.throws(TypeError, () => timeFormatterFull.format(date), "plain date, timeStyle=full");
var result = dateTimeFormatterShort.format(date);
assert.sameValue(result, dateShort, "plain date, dateStyle = timeStyle = short");
result = dateTimeFormatterMedium.format(date);
assert.sameValue(result, dateMedium, "plain date, dateStyle = timeStyle = medium");
result = dateTimeFormatterLong.format(date);
assert.sameValue(result, dateLong, "plain date, dateStyle = timeStyle = long");
result = dateTimeFormatterFull.format(date);
assert.sameValue(result, dateFull, "plain date, dateStyle = timeStyle = full");
result = dateTimeFormatterShortLong.format(date);
assert.sameValue(result, dateShort, "plain date, dateStyle = short, timeStyle = long");

View File

@ -3,7 +3,7 @@
/*--- /*---
esid: sec-datetime-format-functions esid: sec-datetime-format-functions
description: Different combinations of style options and Temporal types format correctly. description: Different combinations of style options and Temporal.PlainDateTime format correctly.
locale: [en-US] locale: [en-US]
features: [Temporal] features: [Temporal]
---*/ ---*/
@ -33,40 +33,6 @@ const dateTimeFormatterFullMedium = new Intl.DateTimeFormat("en-US", { dateStyle
const dateTimeFormatterFullShort = new Intl.DateTimeFormat("en-US", { dateStyle: "full", timeStyle: "short", 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" }); const dateTimeFormatterFullLong = new Intl.DateTimeFormat("en-US", { dateStyle: "full", timeStyle: "long", timeZone: "Pacific/Apia" });
// PlainDate
const date = new Temporal.PlainDate(2021, 8, 4);
const dateShort = dateFormatterShort.format(date);
/*
To avoid requiring an exact format for the output of locale-dependent functions,
don't run these tests, but they're left here as documentation for what the output
should roughly look like.
*/
// assert.sameValue(dateShort, "8/4/21", "plain date, dateStyle=short");
const dateMedium = dateFormatterMedium.format(date);
// assert.sameValue(dateMedium, "Aug 4, 2021", "plain date, dateStyle=medium");
const dateLong = dateFormatterLong.format(date);
// assert.sameValue(dateLong, "August 4, 2021", "plain date, dateStyle=long");
const dateFull = dateFormatterFull.format(date);
// assert.sameValue(dateFull, "Wednesday, August 4, 2021", "plain date, dateStyle=full");
assert.throws(TypeError, () => timeFormatterShort.format(date), "plain date, timeStyle=short");
assert.throws(TypeError, () => timeFormatterMedium.format(date), "plain date, timeStyle=medium");
assert.throws(TypeError, () => timeFormatterLong.format(date), "plain date, timeStyle=long");
assert.throws(TypeError, () => timeFormatterFull.format(date), "plain date, timeStyle=full");
var result = dateTimeFormatterShort.format(date);
assert.sameValue(result, dateShort, "plain date, dateStyle = timeStyle = short");
result = dateTimeFormatterMedium.format(date);
assert.sameValue(result, dateMedium, "plain date, dateStyle = timeStyle = medium");
result = dateTimeFormatterLong.format(date);
assert.sameValue(result, dateLong, "plain date, dateStyle = timeStyle = long");
result = dateTimeFormatterFull.format(date);
assert.sameValue(result, dateFull, "plain date, dateStyle = timeStyle = full");
result = dateTimeFormatterShortLong.format(date);
assert.sameValue(result, dateShort, "plain date, dateStyle = short, timeStyle = long");
// PlainDateTime
// Use a PlainDateTime with unique values in each field, so as to make it easier // Use a PlainDateTime with unique values in each field, so as to make it easier
// to test which values appear in the formatted output // to test which values appear in the formatted output
const datetime = new Temporal.PlainDateTime(2222, 3, 4, 5, 6, 7, 888, 999, 111); const datetime = new Temporal.PlainDateTime(2222, 3, 4, 5, 6, 7, 888, 999, 111);
@ -241,137 +207,3 @@ assert.notSameValue(datetimeResult.search("4"), -1, "plain datetime, dateStyle =
assert.notSameValue(datetimeResult.search("6"), -1, "plain datetime, dateStyle = full, timeStyle = long: minutes should appear"); assert.notSameValue(datetimeResult.search("6"), -1, "plain datetime, dateStyle = full, timeStyle = long: minutes should appear");
assert.notSameValue(datetimeResult.search("7"), -1, "plain datetime, dateStyle = full, timeStyle = long: seconds should appear"); assert.notSameValue(datetimeResult.search("7"), -1, "plain datetime, dateStyle = full, timeStyle = long: seconds should appear");
assert.sameValue(datetimeResult.search("888"), -1, "plain datetime, dateStyle = full, timeStyle = long: milliseconds should not appear"); assert.sameValue(datetimeResult.search("888"), -1, "plain datetime, dateStyle = full, timeStyle = long: milliseconds should not appear");
// PlainMonthDay
// 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 monthdayResultShort = dateFormatterShort.format(monthday);
// assert.sameValue(monthdayResultShort, "3/4", "plain monthday, dateStyle=short");
assert.sameValue(monthdayResultShort.search("78"), -1, "plain monthday, dateStyle=short: year should not appear");
assert.notSameValue(monthdayResultShort.search("3"), -1, "plain monthday, dateStyle=short: month should appear");
assert.notSameValue(monthdayResultShort.search("4"), -1, "plain monthday, dateStyle=short: day should appear");
const monthdayResultMedium = dateFormatterMedium.format(monthday);
// assert.sameValue(monthdayResultMedium, "Mar 4", "plain monthday, dateStyle=medium");
assert.sameValue(monthdayResultMedium.search("5678"), -1, "plain monthday, dateStyle=medium: year should not appear");
assert.sameValue(monthdayResultMedium.search("3"), -1, "plain monthday, dateStyle=medium: numeric month should not appear");
assert.notSameValue(monthdayResultMedium.search("4"), -1, "plain monthday, dateStyle=medium: day should appear");
const monthdayResultLong = dateFormatterLong.format(monthday);
// assert.sameValue(monthdayResultLong, "March 4", "plain monthday, dateStyle=long");
assert.sameValue(monthdayResultLong.search("5678"), -1, "plain monthday, dateStyle=long: year should not appear");
assert.sameValue(monthdayResultLong.search("3"), -1, "plain monthday, dateStyle=long: numeric month should not appear");
assert.notSameValue(monthdayResultLong.search("4"), -1, "plain monthday, dateStyle=long: day should appear");
const monthdayResultFull = dateFormatterFull.format(monthday);
// assert.sameValue(monthdayResultFull, "March 4", "plain monthday, dateStyle=full");
assert.sameValue(monthdayResultFull.search("5678"), -1, "plain monthday, dateStyle=full: year should not appear");
assert.sameValue(monthdayResultFull.search("3"), -1, "plain monthday, dateStyle=full: numeric month should not appear");
assert.notSameValue(monthdayResultFull.search("4"), -1, "plain monthday, dateStyle=full: day should appear");
assert.throws(TypeError, () => timeFormatterShort.format(monthday), "plain monthday, timeStyle=short");
assert.throws(TypeError, () => timeFormatterMedium.format(monthday), "plain monthday, timeStyle=medium");
assert.throws(TypeError, () => timeFormatterLong.format(monthday), "plain monthday, timeStyle=long");
assert.throws(TypeError, () => timeFormatterFull.format(monthday), "plain monthday, timeStyle=full");
var monthdayResult = dateTimeFormatterShort.format(monthday);
assert.sameValue(monthdayResult, monthdayResultShort, "plain monthday, dateStyle = timeStyle = short: should match output with dateStyle only");
monthdayResult = dateTimeFormatterMedium.format(monthday);
assert.sameValue(monthdayResult, monthdayResultMedium, "plain monthday, dateStyle = timeStyle = medium: should match output with dateStyle only");
monthdayResult = dateTimeFormatterLong.format(monthday);
assert.sameValue(monthdayResult, monthdayResultLong, "plain monthday, dateStyle = timeStyle = long: should match output with dateStyle only");
monthdayResult = dateTimeFormatterFull.format(monthday);
assert.sameValue(monthdayResult, monthdayResultLong, "plain monthday, dateStyle = timeStyle = full: should match output with dateStyle only");
monthdayResult = dateTimeFormatterShortLong.format(monthday);
assert.sameValue(monthdayResult, monthdayResultShort, "plain monthday, dateStyle short, = timeStyle = long: should match output with dateStyle only");
// PlainYearMonth
// Use a reference day so we can check that it doesn't occur in any string output
const yearmonth = new Temporal.PlainYearMonth(2222, 1, "gregory", 30);
const yearmonthResultShort = dateFormatterShort.format(yearmonth);
// assert.sameValue(yearmonthResultShort, "1/22", "plain yearmonth, dateStyle=short");
assert.sameValue(yearmonthResultShort.search("30"), -1, "plain yearmonth, dateStyle=short: day should not appear");
assert.notSameValue(yearmonthResultShort.search("1"), -1, "plain yearmonth, dateStyle=short: numeric month should appear");
assert.notSameValue(yearmonthResultShort.search("22"), -1, "plain yearmonth, dateStyle=short: 2-digit year should appear");
const yearmonthResultMedium = dateFormatterMedium.format(yearmonth);
// assert.sameValue(yearmonthResultMedium, "Jan 2222", "plain yearmonth, dateStyle=medium");
assert.sameValue(yearmonthResultMedium.search("30"), -1, "plain yearmonth, dateStyle=medium: day should not appear");
assert.sameValue(yearmonthResultMedium.search("1"), -1, "plain yearmonth, dateStyle=medium: numeric month should not appear");
assert.notSameValue(yearmonthResultMedium.search("2222"), -1, "plain yearmonth, dateStyle=medium: 4-digit year should appear");
const yearmonthResultLong = dateFormatterLong.format(yearmonth);
// assert.sameValue(yearmonthResultLong, "January 2222", "plain yearmonth, dateStyle=long");
assert.sameValue(yearmonthResultLong.search("30"), -1, "plain yearmonth, dateStyle=long: day should not appear");
assert.sameValue(yearmonthResultLong.search("1"), -1, "plain yearmonth, dateStyle=long: numeric month should not appear");
assert.notSameValue(yearmonthResultLong.search("2222"), -1, "plain yearmonth, dateStyle=long: 4-digit year should appear");
const yearmonthResultFull = dateFormatterFull.format(yearmonth);
// assert.sameValue(yearmonthResultFull, "January 2222", "plain yearmonth, dateStyle=full");
assert.sameValue(yearmonthResultFull.search("30"), -1, "plain yearmonth, dateStyle=full: day should not appear");
assert.sameValue(yearmonthResultFull.search("1"), -1, "plain yearmonth, dateStyle=full: numeric month should not appear");
assert.notSameValue(yearmonthResultFull.search("2222"), -1, "plain yearmonth, dateStyle=full: 4-digit year should appear");
assert.throws(TypeError, () => timeFormatterShort.format(yearmonth), "plain yearmonth, timeStyle=short");
assert.throws(TypeError, () => timeFormatterMedium.format(yearmonth), "plain yearmonth, timeStyle=medium");
assert.throws(TypeError, () => timeFormatterLong.format(yearmonth), "plain yearmonth, timeStyle=long");
assert.throws(TypeError, () => timeFormatterFull.format(yearmonth), "plain yearmonth, timeStyle=full");
var yearmonthResult = dateTimeFormatterShort.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultShort, "plain yearmonth, dateStyle = timeStyle = short");
yearmonthResult = dateTimeFormatterMedium.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultMedium, "plain yearmonth, dateStyle = timeStyle = medium");
yearmonthResult = dateTimeFormatterLong.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultLong, "plain yearmonth, dateStyle = timeStyle = long");
yearmonthResult = dateTimeFormatterFull.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultFull, "plain yearmonth, dateStyle = timeStyle = full");
yearmonthResult = dateTimeFormatterShortLong.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultShort, "plain yearmonth, dateStyle = short, timeStyle = long");
// PlainTime
const time = new Temporal.PlainTime(0, 34, 56, 777, 888, 999);
assert.throws(TypeError, () => dateFormatterShort.format(time), "plain time, dateStyle=short");
assert.throws(TypeError, () => dateFormatterMedium.format(time), "plain time, dateStyle=medium");
assert.throws(TypeError, () => dateFormatterLong.format(time), "plain time, dateStyle=long");
const timeResultShort = timeFormatterShort.format(time);
// assert.sameValue(timeResultShort, "12:34 AM", "plain time, timeStyle=short");
assert.notSameValue(timeResultShort.search("12"), -1, "plainTime, timeStyle=short: hour should appear");
assert.sameValue(timeResultShort.search("56"), -1, "plainTime, timeStyle=short: seconds should not appear");
const timeResultMedium = timeFormatterMedium.format(time);
// assert.sameValue(timeResultMedium, "12:34:56 AM", "plain time, timeStyle=medium");
assert.notSameValue(timeResultMedium.search("56"), -1, "plainTime, timeStyle=medium: seconds should appear");
assert.sameValue(timeResultMedium.search("777"), -1, "plainTime, timeStyle=medium: milliseconds should not appear");
const timeResultLong = timeFormatterLong.format(time);
// assert.sameValue(timeResultLong, "12:34:56 AM", "plain time, timeStyle=long");
assert.notSameValue(timeResultMedium.search("34"), -1, "plainTime, timeStyle=long: minutes should appear");
assert.sameValue(timeResultMedium.search("888"), -1, "plainTime, timeStyle=long: microseconds should not appear");
var timeResult = dateTimeFormatterShort.format(time);
assert.sameValue(timeResult, timeResultShort, "plain time, dateStyle = timeStyle = short");
timeResult = dateTimeFormatterMedium.format(time);
assert.sameValue(timeResult, timeResultMedium, "plain time, dateStyle = timeStyle = medium");
timeResult = dateTimeFormatterLong.format(time);
assert.sameValue(timeResult, timeResultLong, "plain time, dateStyle = timeStyle = long");
timeResult = dateTimeFormatterFull.format(time);
assert.sameValue(timeResult, timeResultLong, "plain time, dateStyle = timeStyle = full");
timeResult = dateTimeFormatterShortLong.format(time);
assert.sameValue(timeResult, timeResultLong, "plain time, dateStyle = short, timeStyle = long");

View File

@ -0,0 +1,81 @@
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-datetime-format-functions
description: Different combinations of style options and Temporal.PlainMonthDay format correctly.
locale: [en-US]
features: [Temporal]
---*/
const dateFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeZone: "Pacific/Apia" });
const dateFormatterMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", 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 timeFormatterShort = new Intl.DateTimeFormat("en-US", { timeStyle: "short", timeZone: "Pacific/Apia" });
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 dateTimeFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "short", timeZone: "Pacific/Apia" });
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
const monthday = new Temporal.PlainMonthDay(3, 4, "gregory", 5678);
const monthdayResultShort = dateFormatterShort.format(monthday);
// assert.sameValue(monthdayResultShort, "3/4", "plain monthday, dateStyle=short");
assert.sameValue(monthdayResultShort.search("78"), -1, "plain monthday, dateStyle=short: year should not appear");
assert.notSameValue(monthdayResultShort.search("3"), -1, "plain monthday, dateStyle=short: month should appear");
assert.notSameValue(monthdayResultShort.search("4"), -1, "plain monthday, dateStyle=short: day should appear");
const monthdayResultMedium = dateFormatterMedium.format(monthday);
// assert.sameValue(monthdayResultMedium, "Mar 4", "plain monthday, dateStyle=medium");
assert.sameValue(monthdayResultMedium.search("5678"), -1, "plain monthday, dateStyle=medium: year should not appear");
assert.sameValue(monthdayResultMedium.search("3"), -1, "plain monthday, dateStyle=medium: numeric month should not appear");
assert.notSameValue(monthdayResultMedium.search("4"), -1, "plain monthday, dateStyle=medium: day should appear");
const monthdayResultLong = dateFormatterLong.format(monthday);
// assert.sameValue(monthdayResultLong, "March 4", "plain monthday, dateStyle=long");
assert.sameValue(monthdayResultLong.search("5678"), -1, "plain monthday, dateStyle=long: year should not appear");
assert.sameValue(monthdayResultLong.search("3"), -1, "plain monthday, dateStyle=long: numeric month should not appear");
assert.notSameValue(monthdayResultLong.search("4"), -1, "plain monthday, dateStyle=long: day should appear");
const monthdayResultFull = dateFormatterFull.format(monthday);
// assert.sameValue(monthdayResultFull, "March 4", "plain monthday, dateStyle=full");
assert.sameValue(monthdayResultFull.search("5678"), -1, "plain monthday, dateStyle=full: year should not appear");
assert.sameValue(monthdayResultFull.search("3"), -1, "plain monthday, dateStyle=full: numeric month should not appear");
assert.notSameValue(monthdayResultFull.search("4"), -1, "plain monthday, dateStyle=full: day should appear");
assert.throws(TypeError, () => timeFormatterShort.format(monthday), "plain monthday, timeStyle=short");
assert.throws(TypeError, () => timeFormatterMedium.format(monthday), "plain monthday, timeStyle=medium");
assert.throws(TypeError, () => timeFormatterLong.format(monthday), "plain monthday, timeStyle=long");
assert.throws(TypeError, () => timeFormatterFull.format(monthday), "plain monthday, timeStyle=full");
var monthdayResult = dateTimeFormatterShort.format(monthday);
assert.sameValue(monthdayResult, monthdayResultShort, "plain monthday, dateStyle = timeStyle = short: should match output with dateStyle only");
monthdayResult = dateTimeFormatterMedium.format(monthday);
assert.sameValue(monthdayResult, monthdayResultMedium, "plain monthday, dateStyle = timeStyle = medium: should match output with dateStyle only");
monthdayResult = dateTimeFormatterLong.format(monthday);
assert.sameValue(monthdayResult, monthdayResultLong, "plain monthday, dateStyle = timeStyle = long: should match output with dateStyle only");
monthdayResult = dateTimeFormatterFull.format(monthday);
assert.sameValue(monthdayResult, monthdayResultLong, "plain monthday, dateStyle = timeStyle = full: should match output with dateStyle only");
monthdayResult = dateTimeFormatterShortLong.format(monthday);
assert.sameValue(monthdayResult, monthdayResultShort, "plain monthday, dateStyle short, = timeStyle = long: should match output with dateStyle only");

View File

@ -0,0 +1,72 @@
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-datetime-format-functions
description: Different combinations of style options and Temporal.PlainTime format correctly.
locale: [en-US]
features: [Temporal]
---*/
const dateFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeZone: "Pacific/Apia" });
const dateFormatterMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", 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 timeFormatterShort = new Intl.DateTimeFormat("en-US", { timeStyle: "short", timeZone: "Pacific/Apia" });
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 dateTimeFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "short", timeZone: "Pacific/Apia" });
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" });
const time = new Temporal.PlainTime(0, 34, 56, 777, 888, 999);
assert.throws(TypeError, () => dateFormatterShort.format(time), "plain time, dateStyle=short");
assert.throws(TypeError, () => dateFormatterMedium.format(time), "plain time, dateStyle=medium");
assert.throws(TypeError, () => dateFormatterLong.format(time), "plain time, dateStyle=long");
const timeResultShort = timeFormatterShort.format(time);
// assert.sameValue(timeResultShort, "12:34 AM", "plain time, timeStyle=short");
assert.notSameValue(timeResultShort.search("12"), -1, "plainTime, timeStyle=short: hour should appear");
assert.sameValue(timeResultShort.search("56"), -1, "plainTime, timeStyle=short: seconds should not appear");
const timeResultMedium = timeFormatterMedium.format(time);
// assert.sameValue(timeResultMedium, "12:34:56 AM", "plain time, timeStyle=medium");
assert.notSameValue(timeResultMedium.search("56"), -1, "plainTime, timeStyle=medium: seconds should appear");
assert.sameValue(timeResultMedium.search("777"), -1, "plainTime, timeStyle=medium: milliseconds should not appear");
const timeResultLong = timeFormatterLong.format(time);
// assert.sameValue(timeResultLong, "12:34:56 AM", "plain time, timeStyle=long");
assert.notSameValue(timeResultMedium.search("34"), -1, "plainTime, timeStyle=long: minutes should appear");
assert.sameValue(timeResultMedium.search("888"), -1, "plainTime, timeStyle=long: microseconds should not appear");
var timeResult = dateTimeFormatterShort.format(time);
assert.sameValue(timeResult, timeResultShort, "plain time, dateStyle = timeStyle = short");
timeResult = dateTimeFormatterMedium.format(time);
assert.sameValue(timeResult, timeResultMedium, "plain time, dateStyle = timeStyle = medium");
timeResult = dateTimeFormatterLong.format(time);
assert.sameValue(timeResult, timeResultLong, "plain time, dateStyle = timeStyle = long");
timeResult = dateTimeFormatterFull.format(time);
assert.sameValue(timeResult, timeResultLong, "plain time, dateStyle = timeStyle = full");
timeResult = dateTimeFormatterShortLong.format(time);
assert.sameValue(timeResult, timeResultLong, "plain time, dateStyle = short, timeStyle = long");

View File

@ -0,0 +1,77 @@
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-datetime-format-functions
description: Different combinations of style options and Temporal.PlainYearMonth format correctly.
locale: [en-US]
features: [Temporal]
---*/
const dateFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeZone: "Pacific/Apia" });
const dateFormatterMedium = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", 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 timeFormatterShort = new Intl.DateTimeFormat("en-US", { timeStyle: "short", timeZone: "Pacific/Apia" });
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 dateTimeFormatterShort = new Intl.DateTimeFormat("en-US", { dateStyle: "short", timeStyle: "short", timeZone: "Pacific/Apia" });
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 day so we can check that it doesn't occur in any string output
const yearmonth = new Temporal.PlainYearMonth(2222, 1, "gregory", 30);
const yearmonthResultShort = dateFormatterShort.format(yearmonth);
// assert.sameValue(yearmonthResultShort, "1/22", "plain yearmonth, dateStyle=short");
assert.sameValue(yearmonthResultShort.search("30"), -1, "plain yearmonth, dateStyle=short: day should not appear");
assert.notSameValue(yearmonthResultShort.search("1"), -1, "plain yearmonth, dateStyle=short: numeric month should appear");
assert.notSameValue(yearmonthResultShort.search("22"), -1, "plain yearmonth, dateStyle=short: 2-digit year should appear");
const yearmonthResultMedium = dateFormatterMedium.format(yearmonth);
// assert.sameValue(yearmonthResultMedium, "Jan 2222", "plain yearmonth, dateStyle=medium");
assert.sameValue(yearmonthResultMedium.search("30"), -1, "plain yearmonth, dateStyle=medium: day should not appear");
assert.sameValue(yearmonthResultMedium.search("1"), -1, "plain yearmonth, dateStyle=medium: numeric month should not appear");
assert.notSameValue(yearmonthResultMedium.search("2222"), -1, "plain yearmonth, dateStyle=medium: 4-digit year should appear");
const yearmonthResultLong = dateFormatterLong.format(yearmonth);
// assert.sameValue(yearmonthResultLong, "January 2222", "plain yearmonth, dateStyle=long");
assert.sameValue(yearmonthResultLong.search("30"), -1, "plain yearmonth, dateStyle=long: day should not appear");
assert.sameValue(yearmonthResultLong.search("1"), -1, "plain yearmonth, dateStyle=long: numeric month should not appear");
assert.notSameValue(yearmonthResultLong.search("2222"), -1, "plain yearmonth, dateStyle=long: 4-digit year should appear");
const yearmonthResultFull = dateFormatterFull.format(yearmonth);
// assert.sameValue(yearmonthResultFull, "January 2222", "plain yearmonth, dateStyle=full");
assert.sameValue(yearmonthResultFull.search("30"), -1, "plain yearmonth, dateStyle=full: day should not appear");
assert.sameValue(yearmonthResultFull.search("1"), -1, "plain yearmonth, dateStyle=full: numeric month should not appear");
assert.notSameValue(yearmonthResultFull.search("2222"), -1, "plain yearmonth, dateStyle=full: 4-digit year should appear");
assert.throws(TypeError, () => timeFormatterShort.format(yearmonth), "plain yearmonth, timeStyle=short");
assert.throws(TypeError, () => timeFormatterMedium.format(yearmonth), "plain yearmonth, timeStyle=medium");
assert.throws(TypeError, () => timeFormatterLong.format(yearmonth), "plain yearmonth, timeStyle=long");
assert.throws(TypeError, () => timeFormatterFull.format(yearmonth), "plain yearmonth, timeStyle=full");
var yearmonthResult = dateTimeFormatterShort.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultShort, "plain yearmonth, dateStyle = timeStyle = short");
yearmonthResult = dateTimeFormatterMedium.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultMedium, "plain yearmonth, dateStyle = timeStyle = medium");
yearmonthResult = dateTimeFormatterLong.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultLong, "plain yearmonth, dateStyle = timeStyle = long");
yearmonthResult = dateTimeFormatterFull.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultFull, "plain yearmonth, dateStyle = timeStyle = full");
yearmonthResult = dateTimeFormatterShortLong.format(yearmonth);
assert.sameValue(yearmonthResult, yearmonthResultShort, "plain yearmonth, dateStyle = short, timeStyle = long");