summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-14 17:33:54 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-15 20:13:48 +0100
commitb2aa3c9f84262c710c78196342652c491493cf7d (patch)
tree58fc13167340d12dcfbf936a1fd19f3e67680c30 /Userland/Libraries
parentd93713b8744c025ff0a8a9a01b0c1b82008ca59c (diff)
downloadserenity-b2aa3c9f84262c710c78196342652c491493cf7d.zip
LibJS: Do not negate offset in LocalTZA for isUTC=false
In commmit 7d2834344a7635ec45aba28a0351feca8e5f1c17, I think I combined the definitions of the LocalTZA and UTC AOs in my head, and thought the offset should be negated within LocalTZA. Instead, the offset should be left untouched, and the UTC AO is responsible for doing the subtraction.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/DateConstructor.cpp2
2 files changed, 4 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index 721131721d..67347545a8 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -317,15 +317,12 @@ u8 week_day(double t)
}
// 21.4.1.7 LocalTZA ( t, isUTC ), https://tc39.es/ecma262/#sec-local-time-zone-adjustment
-double local_tza(double time, bool is_utc, Optional<StringView> time_zone_override)
+double local_tza(double time, [[maybe_unused]] bool is_utc, Optional<StringView> time_zone_override)
{
// The time_zone_override parameter is non-standard, but allows callers to override the system
// time zone with a specific value without setting environment variables.
auto time_zone = time_zone_override.value_or(TimeZone::current_time_zone());
- auto maybe_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_milliseconds(time));
- auto offset = maybe_offset.value_or(0) * 1000;
-
// When isUTC is true, LocalTZA( tUTC, true ) should return the offset of the local time zone from
// UTC measured in milliseconds at time represented by time value tUTC. When the result is added to
// tUTC, it should yield the corresponding Number tlocal.
@@ -334,7 +331,8 @@ double local_tza(double time, bool is_utc, Optional<StringView> time_zone_overri
// UTC measured in milliseconds at local time represented by Number tlocal. When the result is subtracted
// from tlocal, it should yield the corresponding time value tUTC.
- return is_utc ? offset : -offset;
+ auto maybe_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_milliseconds(time));
+ return maybe_offset.value_or(0) * 1000;
}
// 21.4.1.8 LocalTime ( t ), https://tc39.es/ecma262/#sec-localtime
diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp
index 25bc3def0e..a49d74f9b5 100644
--- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp
@@ -106,7 +106,7 @@ static Value parse_simplified_iso8601(GlobalObject& global_object, const String&
// https://tc39.es/ecma262/#sec-date.parse:
// "When the UTC offset representation is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time."
if (!timezone.has_value() && hours.has_value())
- time_ms += local_tza(time_ms, false);
+ time_ms = utc_time(time_ms);
if (timezone == '-')
time_ms += *timezone_hours * 3'600'000 + *timezone_minutes * 60'000;