diff --git a/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index b91284b94cc..45b5f165056 100644 --- a/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -6,6 +6,8 @@ */ #include +#include +#include #include #include #include @@ -294,15 +296,23 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_string) } // 8.3.12 Temporal.Instant.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tolocalestring -// NOTE: This is the minimum toLocaleString implementation for engines without ECMA-402. +// 15.12.2.1 Temporal.Instant.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sup-temporal.instant.prototype.tolocalestring JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_locale_string) { + auto& realm = *vm.current_realm(); + + auto locales = vm.argument(0); + auto options = vm.argument(1); + // 1. Let instant be the this value. // 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]). auto instant = TRY(typed_this_object(vm)); - // 3. Return TemporalInstantToString(instant, undefined, AUTO). - return PrimitiveString::create(vm, temporal_instant_to_string(instant, {}, Auto {})); + // 3. Let dateFormat be ? CreateDateTimeFormat(%Intl.DateTimeFormat%, locales, options, ANY, ALL). + auto date_format = TRY(Intl::create_date_time_format(vm, realm.intrinsics().intl_date_time_format_constructor(), locales, options, Intl::OptionRequired::Any, Intl::OptionDefaults::All)); + + // 4. Return ? FormatDateTime(dateFormat, instant). + return PrimitiveString::create(vm, TRY(Intl::format_date_time(vm, date_format, instant))); } // 8.3.13 Temporal.Instant.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.tojson diff --git a/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toLocaleString.js b/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toLocaleString.js index 2e3ecd1663b..934391c257d 100644 --- a/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toLocaleString.js +++ b/Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.prototype.toLocaleString.js @@ -5,7 +5,7 @@ describe("correct behavior", () => { test("basic functionality", () => { const instant = new Temporal.Instant(1625614921123456789n); - expect(instant.toLocaleString()).toBe("2021-07-06T23:42:01.123456789Z"); + expect(instant.toLocaleString([], { timeZone: "UTC" })).toBe("7/6/2021, 11:42:01 PM"); }); });