diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2023-03-13 22:35:22 +0100 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-05-24 23:18:07 +0200 |
commit | effcd080ca802515ddce8392c70df512b509f57c (patch) | |
tree | a04e9a7927ddc9103129c4aa0d8b4d88976f4720 /Userland/Libraries/LibJS/Runtime | |
parent | 82c681e44b57563074e5c12dc7e36134b36ae750 (diff) | |
download | serenity-effcd080ca802515ddce8392c70df512b509f57c.zip |
Userland: Remove remaining users of Duration::now_realtime()
This is a clear sign that they want to use a UnixDateTime instead.
This also adds support for placing durations and date times into SQL
databases via their millisecond offset to UTC.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/DateConstructor.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp index 0cadf2dbab..40744af009 100644 --- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -131,8 +131,8 @@ static double parse_simplified_iso8601(DeprecatedString const& iso_8601) // We parsed a valid date simplified ISO 8601 string. VERIFY(year.has_value()); // A valid date string always has at least a year. - auto time = AK::Duration::from_timestamp(*year, month.value_or(1), day.value_or(1), hours.value_or(0), minutes.value_or(0), seconds.value_or(0), milliseconds.value_or(0)); - auto time_ms = static_cast<double>(time.to_milliseconds()); + auto time = AK::UnixDateTime::from_unix_time_parts(*year, month.value_or(1), day.value_or(1), hours.value_or(0), minutes.value_or(0), seconds.value_or(0), milliseconds.value_or(0)); + auto time_ms = static_cast<double>(time.milliseconds_since_epoch()); // 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." @@ -208,7 +208,7 @@ ThrowCompletionOr<Value> DateConstructor::call() { // 1. If NewTarget is undefined, then // a. Let now be the time value (UTC) identifying the current time. - auto now = AK::Duration::now_realtime().to_milliseconds(); + auto now = AK::UnixDateTime::now().milliseconds_since_epoch(); // b. Return ToDateString(now). return PrimitiveString::create(vm(), to_date_string(now)); @@ -225,7 +225,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DateConstructor::construct(FunctionObjec // 3. If numberOfArgs = 0, then if (vm.argument_count() == 0) { // a. Let dv be the time value (UTC) identifying the current time. - auto now = AK::Duration::now_realtime().to_milliseconds(); + auto now = AK::UnixDateTime::now().milliseconds_since_epoch(); date_value = static_cast<double>(now); } // 4. Else if numberOfArgs = 1, then diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp index 97d7477efb..4c81971263 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp @@ -165,7 +165,7 @@ TimeZone* system_time_zone(VM& vm) BigInt* system_utc_epoch_nanoseconds(VM& vm) { // 1. Let ns be the approximate current UTC date and time, in nanoseconds since the epoch. - auto now = AK::Duration::now_realtime().to_nanoseconds(); + auto now = AK::UnixDateTime::now().nanoseconds_since_epoch(); auto ns = Crypto::SignedBigInteger { now }; // 2. Set ns to the result of clamping ns between nsMinInstant and nsMaxInstant. |