summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString')
-rw-r--r--js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/browser.js0
-rw-r--r--js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js30
-rw-r--r--js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/locales-undefined.js21
-rw-r--r--js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-conflict.js50
-rw-r--r--js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-undefined.js21
-rw-r--r--js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/resolved-time-zone.js33
-rw-r--r--js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/shell.js0
7 files changed, 155 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/browser.js b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/browser.js
diff --git a/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js
new file mode 100644
index 0000000000..e50cc4237f
--- /dev/null
+++ b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js
@@ -0,0 +1,30 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2023 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tolocalestring
+description: Calendar must match the locale calendar if not "iso8601"
+features: [Temporal, Intl-enumeration]
+---*/
+
+const localeCalendar = new Intl.DateTimeFormat().resolvedOptions().calendar;
+assert.notSameValue(localeCalendar, "iso8601", "no locale has the ISO calendar");
+
+const sameCalendarInstance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, localeCalendar);
+const result = sameCalendarInstance.toLocaleString();
+assert.sameValue(typeof result, "string", "toLocaleString() succeeds when instance has the same calendar as locale");
+
+const isoInstance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601");
+assert.sameValue(isoInstance.toLocaleString(), result, "toLocaleString() succeeds when instance has the ISO calendar")
+
+// Pick a different calendar that is not ISO and not the locale's calendar
+const calendars = new Set(Intl.supportedValuesOf("calendar"));
+calendars.delete("iso8601");
+calendars.delete(localeCalendar);
+const differentCalendar = calendars.values().next().value;
+
+const differentCalendarInstance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, differentCalendar);
+assert.throws(RangeError, () => differentCalendarInstance.toLocaleString(), "calendar mismatch");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/locales-undefined.js b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/locales-undefined.js
new file mode 100644
index 0000000000..b9e6b75381
--- /dev/null
+++ b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/locales-undefined.js
@@ -0,0 +1,21 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2021 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tolocalestring
+description: Omitting the locales argument defaults to the DateTimeFormat default
+features: [Temporal]
+---*/
+
+const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+const defaultFormatter = new Intl.DateTimeFormat([], Object.create(null));
+const expected = defaultFormatter.format(datetime);
+
+const actualExplicit = datetime.toLocaleString(undefined);
+assert.sameValue(actualExplicit, expected, "default locale is determined by Intl.DateTimeFormat");
+
+const actualImplicit = datetime.toLocaleString();
+assert.sameValue(actualImplicit, expected, "default locale is determined by Intl.DateTimeFormat");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-conflict.js b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-conflict.js
new file mode 100644
index 0000000000..e0bbf809f1
--- /dev/null
+++ b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-conflict.js
@@ -0,0 +1,50 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2021 Kate Miháliková. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sup-temporal.plaindatetime.prototype.tolocalestring
+description: >
+ Conflicting properties of dateStyle must be rejected with a TypeError for the options argument
+info: |
+ Using sec-temporal-getdatetimeformatpattern:
+ GetDateTimeFormatPattern ( dateStyle, timeStyle, matcher, opt, dataLocaleData, hc )
+
+ 1. If dateStyle is not undefined or timeStyle is not undefined, then
+ a. For each row in Table 7, except the header row, do
+ i. Let prop be the name given in the Property column of the row.
+ ii. Let p be opt.[[<prop>]].
+ iii. If p is not undefined, then
+ 1. Throw a TypeError exception.
+features: [Temporal]
+---*/
+
+// Table 14 - Supported fields + example value for each field
+const conflictingOptions = [
+ [ "weekday", "short" ],
+ [ "era", "short" ],
+ [ "year", "numeric" ],
+ [ "month", "numeric" ],
+ [ "day", "numeric" ],
+ [ "hour", "numeric" ],
+ [ "minute", "numeric" ],
+ [ "second", "numeric" ],
+ [ "dayPeriod", "short" ],
+ [ "fractionalSecondDigits", 3 ],
+];
+const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+
+assert.sameValue(typeof datetime.toLocaleString("en", { dateStyle: "short" }), "string");
+assert.sameValue(typeof datetime.toLocaleString("en", { timeStyle: "short" }), "string");
+
+for (const [ option, value ] of conflictingOptions) {
+ assert.throws(TypeError, function() {
+ datetime.toLocaleString("en", { [option]: value, dateStyle: "short" });
+ }, `datetime.toLocaleString("en", { ${option}: "${value}", dateStyle: "short" }) throws TypeError`);
+
+ assert.throws(TypeError, function() {
+ datetime.toLocaleString("en", { [option]: value, timeStyle: "short" });
+ }, `datetime.toLocaleString("en", { ${option}: "${value}", timeStyle: "short" }) throws TypeError`);
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-undefined.js b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-undefined.js
new file mode 100644
index 0000000000..de5988529d
--- /dev/null
+++ b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/options-undefined.js
@@ -0,0 +1,21 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2021 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tolocalestring
+description: Verify that undefined options are handled correctly.
+features: [Temporal]
+---*/
+
+const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
+const defaultFormatter = new Intl.DateTimeFormat('en', Object.create(null));
+const expected = defaultFormatter.format(datetime);
+
+const actualExplicit = datetime.toLocaleString('en', undefined);
+assert.sameValue(actualExplicit, expected, "default locale is determined by Intl.DateTimeFormat");
+
+const actualImplicit = datetime.toLocaleString('en');
+assert.sameValue(actualImplicit, expected, "default locale is determined by Intl.DateTimeFormat");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/resolved-time-zone.js b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/resolved-time-zone.js
new file mode 100644
index 0000000000..5c031fca3d
--- /dev/null
+++ b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/resolved-time-zone.js
@@ -0,0 +1,33 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2021 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.plaindatetime.prototype.tolocalestring
+description: A time zone in resolvedOptions with a large offset still produces the correct string
+locale: [en]
+features: [Temporal]
+---*/
+
+// Using 24-hour clock to avoid format differences between Node 19 (which puts
+// "\u{202f}" before AM/PM) and previous versions that use regular spaces.
+const options = {
+ timeZone: "Pacific/Apia",
+ year: "numeric",
+ month: "numeric",
+ day: "numeric",
+ hour: "numeric",
+ minute: "numeric",
+ second: "numeric",
+ hourCycle: "h23"
+};
+
+const datetime1 = new Temporal.PlainDateTime(2021, 8, 4, 0, 30, 45, 123, 456, 789);
+const result1 = datetime1.toLocaleString("en", options);
+assert.sameValue(result1, "8/4/2021, 00:30:45");
+
+const datetime2 = new Temporal.PlainDateTime(2021, 8, 4, 23, 30, 45, 123, 456, 789);
+const result2 = datetime2.toLocaleString("en", options);
+assert.sameValue(result2, "8/4/2021, 23:30:45");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/shell.js b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/intl402/Temporal/PlainDateTime/prototype/toLocaleString/shell.js