diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-10-14 10:42:02 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-15 18:05:02 +0200 |
commit | 735e1c4e20cbd4502902099bddc7e18fcf705a9b (patch) | |
tree | 03d0c63eb4539fbd38e170aca18f28af09e9d516 /Userland/Libraries/LibJS/Runtime | |
parent | 053cc90dbea7e64669b4cd208ec8c89bda8bb8bf (diff) | |
download | serenity-735e1c4e20cbd4502902099bddc7e18fcf705a9b.zip |
LibJS: Replace GetIANATimeZoneOffset[Ns] with GetNamedTimeZoneOffset[Ns]
This is an editorial change in the Temporal spec. See:
https://github.com/tc39/proposal-temporal/commit/e44d36b
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
3 files changed, 15 insertions, 48 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index 3230448e78..06ffecfe4b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -149,39 +149,7 @@ ISODateTime get_iso_parts_from_epoch(VM& vm, Crypto::SignedBigInteger const& epo return { .year = year, .month = month, .day = day, .hour = hour, .minute = minute, .second = second, .millisecond = millisecond, .microsecond = static_cast<u16>(microsecond), .nanosecond = static_cast<u16>(nanosecond) }; } -// 11.6.3 GetIANATimeZoneOffsetNanoseconds ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneoffsetnanoseconds -i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier) -{ - // The implementation-defined abstract operation GetIANATimeZoneOffsetNanoseconds takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns an integer. - // The returned integer represents the offset of the IANA time zone identified by timeZoneIdentifier from UTC, at the instant corresponding to epochNanoseconds. - // Given the same values of epochNanoseconds and timeZoneIdentifier, the result must be the same for the lifetime of the surrounding agent. - - // Only called with validated TimeZone [[Identifier]] as argument. - auto time_zone = ::TimeZone::time_zone_from_string(time_zone_identifier); - VERIFY(time_zone.has_value()); - - // Since Time::from_seconds() and Time::from_nanoseconds() 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.big_integer().divided_by("1000000000"_bigint).quotient; - - // The provided epoch (nano)seconds value is potentially out of range for AK::Time and subsequently - // get_time_zone_offset(). We can safely assume that the TZDB has no useful information that far - // into the past and future anyway, so clamp it to the i64 range. - Time time; - if (seconds < Crypto::SignedBigInteger { NumericLimits<i64>::min() }) - time = Time::min(); - else if (seconds > Crypto::SignedBigInteger { NumericLimits<i64>::max() }) - time = Time::max(); - else - time = Time::from_seconds(*seconds.to_base(10).to_int<i64>()); - - auto offset = ::TimeZone::get_time_zone_offset(*time_zone, time); - VERIFY(offset.has_value()); - - return offset->seconds * 1'000'000'000; -} - -// 11.6.4 GetIANATimeZoneNextTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezonenexttransition +// 11.6.3 GetIANATimeZoneNextTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezonenexttransition BigInt* get_iana_time_zone_next_transition(VM&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier) { // The implementation-defined abstract operation GetIANATimeZoneNextTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null. @@ -192,7 +160,7 @@ BigInt* get_iana_time_zone_next_transition(VM&, [[maybe_unused]] BigInt const& e return nullptr; } -// 11.6.5 GetIANATimeZonePreviousTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneprevioustransition +// 11.6.4 GetIANATimeZonePreviousTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneprevioustransition BigInt* get_iana_time_zone_previous_transition(VM&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier) { // The implementation-defined abstract operation GetIANATimeZonePreviousTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null. @@ -246,7 +214,7 @@ bool is_valid_time_zone_numeric_utc_offset_syntax(String const& offset_string) return parse_time_zone_numeric_utc_offset_syntax(offset_string, discarded, discarded, optionally_discarded, optionally_discarded, optionally_discarded); } -// 11.6.6 ParseTimeZoneOffsetString ( offsetString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetimezoneoffsetstring +// 11.6.5 ParseTimeZoneOffsetString ( offsetString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetimezoneoffsetstring ThrowCompletionOr<double> parse_time_zone_offset_string(VM& vm, String const& offset_string) { // 1. Let parseResult be ParseText(StringToCodePoints(offsetString), TimeZoneNumericUTCOffset). @@ -319,7 +287,7 @@ ThrowCompletionOr<double> parse_time_zone_offset_string(VM& vm, String const& of return factor * (((hours_mv * 60 + minutes_mv) * 60 + seconds_mv) * 1e9 + nanoseconds_mv); } -// 11.6.7 FormatTimeZoneOffsetString ( offsetNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-formattimezoneoffsetstring +// 11.6.6 FormatTimeZoneOffsetString ( offsetNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-formattimezoneoffsetstring String format_time_zone_offset_string(double offset_nanoseconds) { auto offset = static_cast<i64>(offset_nanoseconds); @@ -373,7 +341,7 @@ String format_time_zone_offset_string(double offset_nanoseconds) return builder.to_string(); } -// 11.6.8 FormatISOTimeZoneOffsetString ( offsetNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-formatisotimezoneoffsetstring +// 11.6.7 FormatISOTimeZoneOffsetString ( offsetNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-formatisotimezoneoffsetstring String format_iso_time_zone_offset_string(double offset_nanoseconds) { // 1. Assert: offsetNanoseconds is an integer. @@ -400,7 +368,7 @@ String format_iso_time_zone_offset_string(double offset_nanoseconds) return String::formatted("{}{:02}:{:02}", sign, (u32)hours, (u32)minutes); } -// 11.6.9 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone +// 11.6.8 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zone_like) { // 1. If Type(temporalTimeZoneLike) is Object, then @@ -458,7 +426,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon return MUST(create_temporal_time_zone(vm, *parse_result.offset_string)); } -// 11.6.10 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor +// 11.6.9 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, Instant& instant) { // 1. Let getOffsetNanosecondsFor be ? GetMethod(timeZone, "getOffsetNanosecondsFor"). @@ -486,7 +454,7 @@ ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, In return offset_nanoseconds; } -// 11.6.11 BuiltinTimeZoneGetOffsetStringFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetoffsetstringfor +// 11.6.10 BuiltinTimeZoneGetOffsetStringFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetoffsetstringfor ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM& vm, Value time_zone, Instant& instant) { // 1. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant). @@ -496,7 +464,7 @@ ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM& vm, Value return format_time_zone_offset_string(offset_nanoseconds); } -// 11.6.12 BuiltinTimeZoneGetPlainDateTimeFor ( timeZone, instant, calendar ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetplaindatetimefor +// 11.6.11 BuiltinTimeZoneGetPlainDateTimeFor ( timeZone, instant, calendar ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetplaindatetimefor ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM& vm, Value time_zone, Instant& instant, Object& calendar) { // 1. Assert: instant has an [[InitializedTemporalInstant]] internal slot. @@ -514,7 +482,7 @@ ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM& return create_temporal_date_time(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar); } -// 11.6.13 BuiltinTimeZoneGetInstantFor ( timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetinstantfor +// 11.6.12 BuiltinTimeZoneGetInstantFor ( timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetinstantfor ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(VM& vm, Value time_zone, PlainDateTime& date_time, StringView disambiguation) { // 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot. @@ -526,7 +494,7 @@ ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(VM& vm, Value time return disambiguate_possible_instants(vm, possible_instants, time_zone, date_time, disambiguation); } -// 11.6.14 DisambiguatePossibleInstants ( possibleInstants, timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-disambiguatepossibleinstants +// 11.6.13 DisambiguatePossibleInstants ( possibleInstants, timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-disambiguatepossibleinstants ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM& vm, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime& date_time, StringView disambiguation) { // 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot. @@ -644,7 +612,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM& vm, MarkedVector< return possible_instants_[n - 1]; } -// 11.6.15 GetPossibleInstantsFor ( timeZone, dateTime ), https://tc39.es/proposal-temporal/#sec-temporal-getpossibleinstantsfor +// 11.6.14 GetPossibleInstantsFor ( timeZone, dateTime ), https://tc39.es/proposal-temporal/#sec-temporal-getpossibleinstantsfor ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Value time_zone, PlainDateTime& date_time) { // 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot. @@ -689,7 +657,7 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu return { move(list) }; } -// 11.6.16 TimeZoneEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-timezoneequals +// 11.6.15 TimeZoneEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-timezoneequals ThrowCompletionOr<bool> time_zone_equals(VM& vm, Object& one, Object& two) { // 1. If one and two are the same Object value, return true. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h index 89c36ad18f..929d662b0f 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h @@ -41,7 +41,6 @@ String canonicalize_time_zone_name(String const& time_zone); String default_time_zone(); ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM&, String const& identifier, FunctionObject const* new_target = nullptr); ISODateTime get_iso_parts_from_epoch(VM&, Crypto::SignedBigInteger const& epoch_nanoseconds); -i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier); BigInt* get_iana_time_zone_next_transition(VM&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier); BigInt* get_iana_time_zone_previous_transition(VM&, BigInt const& epoch_nanoseconds, StringView time_zone_identifier); ThrowCompletionOr<double> parse_time_zone_offset_string(VM&, String const&); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index 1997ee8135..d1995a0247 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp @@ -70,8 +70,8 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_nanoseconds_for) if (time_zone->offset_nanoseconds().has_value()) return Value(*time_zone->offset_nanoseconds()); - // 5. Return 𝔽(GetIANATimeZoneOffsetNanoseconds(instant.[[Nanoseconds]], timeZone.[[Identifier]])). - return Value((double)get_iana_time_zone_offset_nanoseconds(instant->nanoseconds(), time_zone->identifier())); + // 5. Return 𝔽(GetNamedTimeZoneOffsetNanoseconds(timeZone.[[Identifier]], instant.[[Nanoseconds]])). + return Value((double)get_named_time_zone_offset_nanoseconds(time_zone->identifier(), instant->nanoseconds().big_integer())); } // 11.4.5 Temporal.TimeZone.prototype.getOffsetStringFor ( instant ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getoffsetstringfor |