diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index 7a4479b927..fb99452481 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -336,7 +336,7 @@ String format_time_zone_offset_string(double offset_nanoseconds) // a. Let fraction be nanoseconds, formatted as a nine-digit decimal number, padded to the left with zeroes if necessary. // b. Set fraction to the longest possible substring of fraction starting at position 0 and not ending with the code unit 0x0030 (DIGIT ZERO). // c. Let post be the string-concatenation of the code unit 0x003A (COLON), s, the code unit 0x002E (FULL STOP), and fraction. - builder.appendff(":{:02}.{:9}", seconds, nanoseconds); + builder.appendff(":{:02}.{}", seconds, String::formatted("{:09}", nanoseconds).trim("0"sv, TrimMode::Right)); } // 12. Else if seconds ≠ 0, then else if (seconds != 0) { diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toString.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toString.js index bfefb3ac93..2814b13c7e 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toString.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.prototype.toString.js @@ -4,8 +4,20 @@ describe("correct behavior", () => { }); test("basic functionality", () => { - const timeZone = new Temporal.TimeZone("UTC"); - expect(timeZone.toString()).toBe("UTC"); + const values = [ + ["utc", "UTC"], + ["Utc", "UTC"], + ["UTC", "UTC"], + ["+00:00", "+00:00"], + ["+00:00:00", "+00:00"], + ["+00:00:00.000", "+00:00"], + ["+12:34:56.789", "+12:34:56.789"], + ["+12:34:56.789000", "+12:34:56.789"], + ["-01:00", "-01:00"], + ]; + for (const [arg, expected] of values) { + expect(new Temporal.TimeZone(arg).toString()).toBe(expected); + } }); });