1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:17:45 +00:00

LibJS: Port to_temporal_offset() to String

This commit is contained in:
Linus Groh 2023-01-26 12:17:54 +00:00
parent 3aa3ab65b1
commit a387b22599
4 changed files with 9 additions and 9 deletions

View file

@ -230,17 +230,17 @@ StringView negate_temporal_rounding_mode(StringView rounding_mode)
}
// 13.8 ToTemporalOffset ( options, fallback ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaloffset
ThrowCompletionOr<DeprecatedString> to_temporal_offset(VM& vm, Object const* options, DeprecatedString const& fallback)
ThrowCompletionOr<String> to_temporal_offset(VM& vm, Object const* options, StringView fallback)
{
// 1. If options is undefined, return fallback.
if (options == nullptr)
return fallback;
return TRY_OR_THROW_OOM(vm, String::from_utf8(fallback));
// 2. Return ? GetOption(options, "offset", "string", « "prefer", "use", "ignore", "reject" », fallback).
auto option = TRY(get_option(vm, *options, vm.names.offset, OptionType::String, { "prefer"sv, "use"sv, "ignore"sv, "reject"sv }, fallback.view()));
auto option = TRY(get_option(vm, *options, vm.names.offset, OptionType::String, { "prefer"sv, "use"sv, "ignore"sv, "reject"sv }, fallback));
VERIFY(option.is_string());
return TRY(option.as_string().deprecated_string());
return option.as_string().utf8_string();
}
// 13.9 ToCalendarNameOption ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-tocalendarnameoption

View file

@ -139,7 +139,7 @@ ThrowCompletionOr<String> to_temporal_overflow(VM&, Object const* options);
ThrowCompletionOr<String> to_temporal_disambiguation(VM&, Object const* options);
ThrowCompletionOr<String> to_temporal_rounding_mode(VM&, Object const& normalized_options, StringView fallback);
StringView negate_temporal_rounding_mode(StringView rounding_mode);
ThrowCompletionOr<DeprecatedString> to_temporal_offset(VM&, Object const* options, DeprecatedString const& fallback);
ThrowCompletionOr<String> to_temporal_offset(VM&, Object const* options, StringView fallback);
ThrowCompletionOr<DeprecatedString> to_calendar_name_option(VM&, Object const& normalized_options);
ThrowCompletionOr<DeprecatedString> to_time_zone_name_option(VM&, Object const& normalized_options);
ThrowCompletionOr<DeprecatedString> to_show_offset_option(VM&, Object const& normalized_options);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -250,7 +250,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
auto disambiguation = TRY(to_temporal_disambiguation(vm, options));
// 10. Let offsetOption be ? ToTemporalOffset(options, "reject").
auto offset_option = TRY(to_temporal_offset(vm, options, "reject"));
auto offset_option = TRY(to_temporal_offset(vm, options, "reject"sv));
// 11. Let epochNanoseconds be ? InterpretISODateTimeOffset(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], offsetBehaviour, offsetNanoseconds, timeZone, disambiguation, offsetOption, matchBehaviour).
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_nanoseconds, time_zone, disambiguation, offset_option, match_behavior));

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -88,7 +88,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimeConstructor::from)
(void)TRY(to_temporal_disambiguation(vm, options));
// c. Perform ? ToTemporalOffset(options, "reject").
(void)TRY(to_temporal_offset(vm, options, "reject"));
(void)TRY(to_temporal_offset(vm, options, "reject"sv));
// d. Return ! CreateTemporalZonedDateTime(item.[[Nanoseconds]], item.[[TimeZone]], item.[[Calendar]]).
return MUST(create_temporal_zoned_date_time(vm, item_object.nanoseconds(), item_object.time_zone(), item_object.calendar()));