Skip to content

Truly independent web browser

LibJS: Give TimeZoneString the time value in Date.prototype.toString

Shannon Booth59c064acc889
diff --git a/Libraries/LibJS/Rust/src/runtime/date_prototype.rs b/Libraries/LibJS/Rust/src/runtime/date_prototype.rs
index d64470b7551..921186b433f 100644
--- a/Libraries/LibJS/Rust/src/runtime/date_prototype.rs
+++ b/Libraries/LibJS/Rust/src/runtime/date_prototype.rs
@@ -1401,14 +1401,13 @@ pub fn to_date_string(time: f64) -> Utf16String {
}
// 2. Let t be LocalTime(tv).
- let time = local_time(time);
+ let local = local_time(time);
// 3. Return the string-concatenation of DateString(t), the code unit 0x0020 (SPACE), TimeString(t), and TimeZoneString(tv).
- // NB: This passes t rather than tv to TimeZoneString.
let mut string = Utf16StringBuilder::new();
- string.append(Utf16View::of_string(&date_string(time)));
+ string.append(Utf16View::of_string(&date_string(local)));
string.append_ascii(" ");
- string.append(Utf16View::of_string(&time_string(time)));
+ string.append(Utf16View::of_string(&time_string(local)));
string.append(Utf16View::of_string(&time_zone_string(time)));
string.to_utf16_string()
}
diff --git a/Tests/LibJS/Runtime/builtins/Date/Date.js b/Tests/LibJS/Runtime/builtins/Date/Date.js
index 9d53864aa1e..c8a9b29af04 100644
--- a/Tests/LibJS/Runtime/builtins/Date/Date.js
+++ b/Tests/LibJS/Runtime/builtins/Date/Date.js
@@ -106,3 +106,14 @@ test("time zone gap", () => {
setTimeZone(originalTimeZone);
});
+
+test("toString shows the UTC offset of the time value, not of the local time", () => {
+ const originalTimeZone = setTimeZone("America/New_York");
+
+ // One hour after the change to daylight saving time.
+ const date = new Date(Date.UTC(2026, 2, 8, 8, 0));
+ expect(date.toString()).toBe("Sun Mar 08 2026 04:00:00 GMT-0400 (Eastern Daylight Time)");
+ expect(Date.parse(date.toString())).toBe(date.getTime());
+
+ setTimeZone(originalTimeZone);
+});