summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2023-03-13 22:28:08 +0100
committerJelle Raaijmakers <jelle@gmta.nl>2023-05-24 23:18:07 +0200
commit82c681e44b57563074e5c12dc7e36134b36ae750 (patch)
tree8617fd279fe87bf44fcb65ffc4add8dca394db97 /Userland/Libraries/LibJS/Runtime
parent939600d2d4d2d04524301f4373d76dc3c693923a (diff)
downloadserenity-82c681e44b57563074e5c12dc7e36134b36ae750.zip
LibTimeZone+Userland: Change timezone functions to use UnixDateTime
This incurs a whole host of changes in, among others, JavaScript Intl and Date.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h4
3 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index d5a92b64c5..df1ff90e3f 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -314,7 +314,7 @@ static i64 clip_bigint_to_sane_time(Crypto::SignedBigInteger const& value)
Vector<Crypto::SignedBigInteger> get_named_time_zone_epoch_nanoseconds(StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
{
auto local_nanoseconds = get_utc_epoch_nanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
- auto local_time = Duration::from_nanoseconds(clip_bigint_to_sane_time(local_nanoseconds));
+ auto local_time = UnixDateTime::from_nanoseconds_since_epoch(clip_bigint_to_sane_time(local_nanoseconds));
// FIXME: LibTimeZone does not behave exactly as the spec expects. It does not consider repeated or skipped time points.
auto offset = TimeZone::get_time_zone_offset(time_zone_identifier, local_time);
@@ -332,10 +332,10 @@ i64 get_named_time_zone_offset_nanoseconds(StringView time_zone_identifier, Cryp
auto time_zone = TimeZone::time_zone_from_string(time_zone_identifier);
VERIFY(time_zone.has_value());
- // Since Duration::from_seconds() and Duration::from_nanoseconds() both take an i64, converting to
+ // Since UnixDateTime::from_seconds_since_epoch() and UnixDateTime::from_nanoseconds_since_epoch() both take an i64, converting to
// seconds first gives us a greater range. The TZDB doesn't have sub-second offsets.
auto seconds = epoch_nanoseconds.divided_by(s_one_billion_bigint).quotient;
- auto time = Duration::from_seconds(clip_bigint_to_sane_time(seconds));
+ auto time = UnixDateTime::from_seconds_since_epoch(clip_bigint_to_sane_time(seconds));
auto offset = TimeZone::get_time_zone_offset(*time_zone, time);
VERIFY(offset.has_value());
diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
index 04c952d8cb..d7d5d05fd4 100644
--- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
@@ -1164,7 +1164,7 @@ DeprecatedString time_zone_string(double time)
auto tz_name = TimeZone::current_time_zone();
// Most implementations seem to prefer the long-form display name of the time zone. Not super important, but we may as well match that behavior.
- if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::Duration::from_milliseconds(time)); maybe_offset.has_value()) {
+ if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::UnixDateTime::from_milliseconds_since_epoch(time)); maybe_offset.has_value()) {
if (auto long_name = Locale::get_time_zone_name(Locale::default_locale(), tz_name, Locale::CalendarPatternStyle::Long, maybe_offset->in_dst); long_name.has_value())
tz_name = long_name.release_value();
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h
index 0a36dc1d9a..6f7720c803 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h
@@ -162,9 +162,9 @@ enum class OptionDefaults {
// Table 8: Record returned by ToLocalTime, https://tc39.es/ecma402/#table-datetimeformat-tolocaltime-record
// Note: [[InDST]] is not included here - it is handled by LibUnicode / LibTimeZone.
struct LocalTime {
- AK::Duration time_since_epoch() const
+ AK::UnixDateTime time_since_epoch() const
{
- return AK::Duration::from_timestamp(year, month + 1, day + 1, hour, minute, second, millisecond);
+ return AK::UnixDateTime::from_unix_time_parts(year, month + 1, day + 1, hour, minute, second, millisecond);
}
int weekday { 0 }; // [[Weekday]]