diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index 63bd48aa86..852a055dfb 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -1492,15 +1492,14 @@ ThrowCompletionOr format_date_time_range_to_parts(GlobalObject& global_o } // 11.1.14 ToLocalTime ( t, calendar, timeZone ), https://tc39.es/ecma402/#sec-tolocaltime -ThrowCompletionOr to_local_time(GlobalObject& global_object, double time, StringView calendar, [[maybe_unused]] StringView time_zone) +ThrowCompletionOr to_local_time(GlobalObject& global_object, double time, StringView calendar, StringView time_zone) { // 1. Assert: Type(t) is Number. // 2. If calendar is "gregory", then if (calendar == "gregory"sv) { // a. Let timeZoneOffset be the value calculated according to LocalTZA(t, true) where the local time zone is replaced with timezone timeZone. - // FIXME: Implement LocalTZA when timezones other than UTC are supported. - double time_zone_offset = 0; + double time_zone_offset = local_tza(time, true, time_zone); // b. Let tz be the time value t + timeZoneOffset. double zoned_time = time + time_zone_offset; diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js index da599067b1..06dddb4dd0 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js @@ -389,13 +389,10 @@ describe("timeZoneName", () => { { timeZone: "UTC", timeZoneName: "longOffset", en0: "12/7/2021, 5:40 PM GMT", en1: "1/23/1989, 7:08 AM GMT", ar0: "٧‏/١٢‏/٢٠٢١, ٥:٤٠ م غرينتش", ar1: "٢٣‏/١‏/١٩٨٩, ٧:٠٨ ص غرينتش" }, { timeZone: "UTC", timeZoneName: "shortGeneric", en0: "12/7/2021, 5:40 PM GMT", en1: "1/23/1989, 7:08 AM GMT", ar0: "٧‏/١٢‏/٢٠٢١, ٥:٤٠ م غرينتش", ar1: "٢٣‏/١‏/١٩٨٩, ٧:٠٨ ص غرينتش" }, { timeZone: "UTC", timeZoneName: "longGeneric", en0: "12/7/2021, 5:40 PM GMT", en1: "1/23/1989, 7:08 AM GMT", ar0: "٧‏/١٢‏/٢٠٢١, ٥:٤٠ م غرينتش", ar1: "٢٣‏/١‏/١٩٨٩, ٧:٠٨ ص غرينتش" }, - - // FIXME: The time stamps on the below cases are incorrect as they do not adjust the time based on the GMT offset. - // Update these once the LocalTZA AO is implemented and ToLocalTime uses it. - { timeZone: "America/New_York", timeZoneName: "shortOffset", en0: "12/7/2021, 5:40 PM GMT-5", en1: "1/23/1989, 7:08 AM GMT-5", ar0: "٧‏/١٢‏/٢٠٢١, ٥:٤٠ م غرينتش-٥", ar1: "٢٣‏/١‏/١٩٨٩, ٧:٠٨ ص غرينتش-٥" }, - { timeZone: "America/New_York", timeZoneName: "longOffset", en0: "12/7/2021, 5:40 PM GMT-05:00", en1: "1/23/1989, 7:08 AM GMT-05:00", ar0: "٧‏/١٢‏/٢٠٢١, ٥:٤٠ م غرينتش-٠٥:٠٠", ar1: "٢٣‏/١‏/١٩٨٩, ٧:٠٨ ص غرينتش-٠٥:٠٠" }, - { timeZone: "America/New_York", timeZoneName: "shortGeneric", en0: "12/7/2021, 5:40 PM ET", en1: "1/23/1989, 7:08 AM ET", ar0: "٧‏/١٢‏/٢٠٢١, ٥:٤٠ م غرينتش-٥", ar1: "٢٣‏/١‏/١٩٨٩, ٧:٠٨ ص غرينتش-٥" }, - { timeZone: "America/New_York", timeZoneName: "longGeneric", en0: "12/7/2021, 5:40 PM Eastern Time", en1: "1/23/1989, 7:08 AM Eastern Time", ar0: "٧‏/١٢‏/٢٠٢١, ٥:٤٠ م التوقيت الشرقي لأمريكا الشمالية", ar1: "٢٣‏/١‏/١٩٨٩, ٧:٠٨ ص التوقيت الشرقي لأمريكا الشمالية" }, + { timeZone: "America/New_York", timeZoneName: "shortOffset", en0: "12/7/2021, 12:40 PM GMT-5", en1: "1/23/1989, 2:08 AM GMT-5", ar0: "٧‏/١٢‏/٢٠٢١, ١٢:٤٠ م غرينتش-٥", ar1: "٢٣‏/١‏/١٩٨٩, ٢:٠٨ ص غرينتش-٥" }, + { timeZone: "America/New_York", timeZoneName: "longOffset", en0: "12/7/2021, 12:40 PM GMT-05:00", en1: "1/23/1989, 2:08 AM GMT-05:00", ar0: "٧‏/١٢‏/٢٠٢١, ١٢:٤٠ م غرينتش-٠٥:٠٠", ar1: "٢٣‏/١‏/١٩٨٩, ٢:٠٨ ص غرينتش-٠٥:٠٠" }, + { timeZone: "America/New_York", timeZoneName: "shortGeneric", en0: "12/7/2021, 12:40 PM ET", en1: "1/23/1989, 2:08 AM ET", ar0: "٧‏/١٢‏/٢٠٢١, ١٢:٤٠ م غرينتش-٥", ar1: "٢٣‏/١‏/١٩٨٩, ٢:٠٨ ص غرينتش-٥" }, + { timeZone: "America/New_York", timeZoneName: "longGeneric", en0: "12/7/2021, 12:40 PM Eastern Time", en1: "1/23/1989, 2:08 AM Eastern Time", ar0: "٧‏/١٢‏/٢٠٢١, ١٢:٤٠ م التوقيت الشرقي لأمريكا الشمالية", ar1: "٢٣‏/١‏/١٩٨٩, ٢:٠٨ ص التوقيت الشرقي لأمريكا الشمالية" }, ]; test("all", () => { diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.formatRangeToParts.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.formatRangeToParts.js index 86406a826c..c0d18d2341 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.formatRangeToParts.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.formatRangeToParts.js @@ -347,7 +347,7 @@ describe("timeStyle", () => { // FIXME: These results should include the date, even though it isn't requested, because the start/end dates // are more than just hours apart. See the FIXME in PartitionDateTimeRangePattern. test("full", () => { - const en = new Intl.DateTimeFormat("en", { timeStyle: "full" }); + const en = new Intl.DateTimeFormat("en", { timeStyle: "full", timeZone: "UTC" }); expect(en.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: ":", source: "startRange" }, @@ -370,7 +370,7 @@ describe("timeStyle", () => { { type: "timeZoneName", value: "Coordinated Universal Time", source: "endRange" }, ]); - const ja = new Intl.DateTimeFormat("ja", { timeStyle: "full" }); + const ja = new Intl.DateTimeFormat("ja", { timeStyle: "full", timeZone: "UTC" }); expect(ja.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: "時", source: "startRange" }, @@ -391,7 +391,7 @@ describe("timeStyle", () => { }); test("long", () => { - const en = new Intl.DateTimeFormat("en", { timeStyle: "long" }); + const en = new Intl.DateTimeFormat("en", { timeStyle: "long", timeZone: "UTC" }); expect(en.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: ":", source: "startRange" }, @@ -414,7 +414,7 @@ describe("timeStyle", () => { { type: "timeZoneName", value: "UTC", source: "endRange" }, ]); - const ja = new Intl.DateTimeFormat("ja", { timeStyle: "long" }); + const ja = new Intl.DateTimeFormat("ja", { timeStyle: "long", timeZone: "UTC" }); expect(ja.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: ":", source: "startRange" }, @@ -435,7 +435,7 @@ describe("timeStyle", () => { }); test("medium", () => { - const en = new Intl.DateTimeFormat("en", { timeStyle: "medium" }); + const en = new Intl.DateTimeFormat("en", { timeStyle: "medium", timeZone: "UTC" }); expect(en.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: ":", source: "startRange" }, @@ -454,7 +454,7 @@ describe("timeStyle", () => { { type: "dayPeriod", value: "PM", source: "endRange" }, ]); - const ja = new Intl.DateTimeFormat("ja", { timeStyle: "medium" }); + const ja = new Intl.DateTimeFormat("ja", { timeStyle: "medium", timeZone: "UTC" }); expect(ja.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: ":", source: "startRange" }, @@ -471,7 +471,7 @@ describe("timeStyle", () => { }); test("short", () => { - const en = new Intl.DateTimeFormat("en", { timeStyle: "short" }); + const en = new Intl.DateTimeFormat("en", { timeStyle: "short", timeZone: "UTC" }); expect(en.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: ":", source: "startRange" }, @@ -486,7 +486,7 @@ describe("timeStyle", () => { { type: "dayPeriod", value: "PM", source: "endRange" }, ]); - const ja = new Intl.DateTimeFormat("ja", { timeStyle: "short" }); + const ja = new Intl.DateTimeFormat("ja", { timeStyle: "short", timeZone: "UTC" }); expect(ja.formatRangeToParts(d0, d1)).toEqual([ { type: "hour", value: "7", source: "startRange" }, { type: "literal", value: ":", source: "startRange" }, diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js index dbcd9e5f80..01c6640bf5 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js @@ -86,8 +86,8 @@ describe("correct behavior", () => { }); test("style", () => { - const en = new Intl.DateTimeFormat("en"); - expect(en.resolvedOptions().timeZone).toBe("UTC"); + const en = new Intl.DateTimeFormat("en", { timeZone: "EST" }); + expect(en.resolvedOptions().timeZone).toBe("EST"); const el = new Intl.DateTimeFormat("el", { timeZone: "UTC" }); expect(el.resolvedOptions().timeZone).toBe("UTC");