mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:47:45 +00:00
LibJS: Port canonicalize_time_zone_name() to String
This commit is contained in:
parent
96855d53c4
commit
0f5f9acc9c
6 changed files with 17 additions and 17 deletions
|
@ -214,17 +214,17 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
|
|||
|
||||
// 29. Let timeZone be ? Get(options, "timeZone").
|
||||
auto time_zone_value = TRY(options->get(vm.names.timeZone));
|
||||
DeprecatedString time_zone;
|
||||
String time_zone;
|
||||
|
||||
// 30. If timeZone is undefined, then
|
||||
if (time_zone_value.is_undefined()) {
|
||||
// a. Set timeZone to DefaultTimeZone().
|
||||
time_zone = default_time_zone();
|
||||
time_zone = TRY_OR_THROW_OOM(vm, String::from_utf8(default_time_zone()));
|
||||
}
|
||||
// 31. Else,
|
||||
else {
|
||||
// a. Set timeZone to ? ToString(timeZone).
|
||||
time_zone = TRY(time_zone_value.to_deprecated_string(vm));
|
||||
time_zone = TRY(time_zone_value.to_string(vm));
|
||||
|
||||
// b. If IsAvailableTimeZoneName(timeZone) is false, then
|
||||
if (!Temporal::is_available_time_zone_name(time_zone)) {
|
||||
|
@ -233,11 +233,11 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF
|
|||
}
|
||||
|
||||
// c. Set timeZone to ! CanonicalizeTimeZoneName(timeZone).
|
||||
time_zone = Temporal::canonicalize_time_zone_name(time_zone);
|
||||
time_zone = MUST_OR_THROW_OOM(Temporal::canonicalize_time_zone_name(vm, time_zone));
|
||||
}
|
||||
|
||||
// 32. Set dateTimeFormat.[[TimeZone]] to timeZone.
|
||||
date_time_format.set_time_zone(move(time_zone));
|
||||
date_time_format.set_time_zone(time_zone.to_deprecated_string());
|
||||
|
||||
// 33. Let formatOptions be a new Record.
|
||||
::Locale::CalendarPattern format_options {};
|
||||
|
|
|
@ -657,7 +657,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
|
|||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, *time_zone_name);
|
||||
|
||||
// 2. Set timeZoneName to ! CanonicalizeTimeZoneName(timeZoneName).
|
||||
time_zone_name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(time_zone_name->to_deprecated_string())));
|
||||
time_zone_name = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, *time_zone_name));
|
||||
}
|
||||
|
||||
// ii. Let timeZone be ! CreateTemporalTimeZone(timeZoneName).
|
||||
|
|
|
@ -43,7 +43,7 @@ bool is_available_time_zone_name(StringView time_zone)
|
|||
|
||||
// 11.1.2 CanonicalizeTimeZoneName ( timeZone ), https://tc39.es/proposal-temporal/#sec-canonicalizetimezonename
|
||||
// 15.1.2 CanonicalizeTimeZoneName ( timeZone ), https://tc39.es/proposal-temporal/#sup-canonicalizetimezonename
|
||||
DeprecatedString canonicalize_time_zone_name(DeprecatedString const& time_zone)
|
||||
ThrowCompletionOr<String> canonicalize_time_zone_name(VM& vm, StringView time_zone)
|
||||
{
|
||||
// 1. Let ianaTimeZone be the String value of the Zone or Link name of the IANA Time Zone Database that is an ASCII-case-insensitive match of timeZone as described in 6.1.
|
||||
// 2. If ianaTimeZone is a Link name, let ianaTimeZone be the String value of the corresponding Zone name as specified in the file backward of the IANA Time Zone Database.
|
||||
|
@ -53,7 +53,7 @@ DeprecatedString canonicalize_time_zone_name(DeprecatedString const& time_zone)
|
|||
// NOTE: This is already done in canonicalize_time_zone().
|
||||
|
||||
// 4. Return ianaTimeZone.
|
||||
return *iana_time_zone;
|
||||
return TRY_OR_THROW_OOM(vm, String::from_utf8(*iana_time_zone));
|
||||
}
|
||||
|
||||
// 11.6.1 CreateTemporalTimeZone ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaltimezone
|
||||
|
@ -82,7 +82,7 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, DeprecatedString
|
|||
// 4. Else,
|
||||
else {
|
||||
// a. Assert: ! CanonicalizeTimeZoneName(identifier) is identifier.
|
||||
VERIFY(canonicalize_time_zone_name(identifier) == identifier);
|
||||
VERIFY(MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, identifier)) == identifier.view());
|
||||
|
||||
// b. Set object.[[Identifier]] to identifier.
|
||||
object->set_identifier(identifier);
|
||||
|
@ -349,7 +349,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
|
|||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, name);
|
||||
|
||||
// ii. Set name to ! CanonicalizeTimeZoneName(name).
|
||||
name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(name.to_deprecated_string())));
|
||||
name = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, name));
|
||||
}
|
||||
|
||||
// c. Return ! CreateTemporalTimeZone(name).
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -37,7 +37,7 @@ private:
|
|||
};
|
||||
|
||||
bool is_available_time_zone_name(StringView time_zone);
|
||||
DeprecatedString canonicalize_time_zone_name(DeprecatedString const& time_zone);
|
||||
ThrowCompletionOr<String> canonicalize_time_zone_name(VM&, StringView time_zone);
|
||||
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM&, DeprecatedString const& identifier, FunctionObject const* new_target = nullptr);
|
||||
ISODateTime get_iso_parts_from_epoch(VM&, Crypto::SignedBigInteger const& epoch_nanoseconds);
|
||||
BigInt* get_named_time_zone_next_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -48,7 +48,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> TimeZoneConstructor::construct(FunctionO
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 2. Set identifier to ? ToString(identifier).
|
||||
auto identifier = TRY(vm.argument(0).to_deprecated_string(vm));
|
||||
auto identifier = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
// 3. If IsTimeZoneOffsetString(identifier) is false, then
|
||||
if (!is_time_zone_offset_string(identifier)) {
|
||||
|
@ -59,11 +59,11 @@ ThrowCompletionOr<NonnullGCPtr<Object>> TimeZoneConstructor::construct(FunctionO
|
|||
}
|
||||
|
||||
// b. Set identifier to ! CanonicalizeTimeZoneName(identifier).
|
||||
identifier = canonicalize_time_zone_name(identifier);
|
||||
identifier = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, identifier));
|
||||
}
|
||||
|
||||
// 4. Return ? CreateTemporalTimeZone(identifier, NewTarget).
|
||||
return *TRY(create_temporal_time_zone(vm, identifier, &new_target));
|
||||
return *TRY(create_temporal_time_zone(vm, identifier.to_deprecated_string(), &new_target));
|
||||
}
|
||||
|
||||
// 11.3.2 Temporal.TimeZone.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.from
|
||||
|
|
|
@ -203,7 +203,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, *time_zone_name);
|
||||
|
||||
// ii. Set timeZoneName to ! CanonicalizeTimeZoneName(timeZoneName).
|
||||
time_zone_name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(time_zone_name->to_deprecated_string())));
|
||||
time_zone_name = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, *time_zone_name));
|
||||
}
|
||||
|
||||
// g. Let offsetString be result.[[TimeZone]].[[OffsetString]].
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue