summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-01-26 15:48:03 +0000
committerLinus Groh <mail@linusgroh.de>2023-01-26 20:20:54 +0000
commitd2c10f6bea2b088e98557ccd2ccd252840aa6096 (patch)
treeafaae3148336ebbf640a5863a45adf7354a936e1 /Userland/Libraries
parent28ee331a93681d10415822398d16e3b17c3bdf96 (diff)
downloadserenity-d2c10f6bea2b088e98557ccd2ccd252840aa6096.zip
LibJS: Port temporal_instant_to_string() to String
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Instant.h4
2 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp
index 75f008448b..8f2804aaf2 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp
@@ -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, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -239,7 +239,7 @@ BigInt* round_temporal_instant(VM& vm, BigInt const& nanoseconds, u64 increment,
}
// 8.5.9 TemporalInstantToString ( instant, timeZone, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring
-ThrowCompletionOr<DeprecatedString> temporal_instant_to_string(VM& vm, Instant& instant, Value time_zone, Variant<StringView, u8> const& precision)
+ThrowCompletionOr<String> temporal_instant_to_string(VM& vm, Instant& instant, Value time_zone, Variant<StringView, u8> const& precision)
{
// 1. Assert: Type(instant) is Object.
// 2. Assert: instant has an [[InitializedTemporalInstant]] internal slot.
@@ -262,12 +262,12 @@ ThrowCompletionOr<DeprecatedString> temporal_instant_to_string(VM& vm, Instant&
// 7. Let dateTimeString be ! TemporalDateTimeToString(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], undefined, precision, "never").
auto date_time_string = MUST(temporal_date_time_to_string(vm, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), nullptr, precision, "never"sv));
- DeprecatedString time_zone_string;
+ String time_zone_string;
// 8. If timeZone is undefined, then
if (time_zone.is_undefined()) {
// a. Let timeZoneString be "Z".
- time_zone_string = "Z"sv;
+ time_zone_string = String::from_utf8_short_string("Z"sv);
}
// 9. Else,
else {
@@ -275,11 +275,11 @@ ThrowCompletionOr<DeprecatedString> temporal_instant_to_string(VM& vm, Instant&
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
// b. Let timeZoneString be ! FormatISOTimeZoneOffsetString(offsetNs).
- time_zone_string = format_iso_time_zone_offset_string(offset_ns);
+ time_zone_string = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(format_iso_time_zone_offset_string(offset_ns)));
}
// 10. Return the string-concatenation of dateTimeString and timeZoneString.
- return DeprecatedString::formatted("{}{}", date_time_string, time_zone_string);
+ return TRY_OR_THROW_OOM(vm, String::formatted("{}{}", date_time_string, time_zone_string));
}
// 8.5.10 DifferenceTemporalInstant ( operation, instant, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalinstant
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h
index 0118086808..3881f32963 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.h
@@ -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, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -50,7 +50,7 @@ i32 compare_epoch_nanoseconds(BigInt const&, BigInt const&);
ThrowCompletionOr<BigInt*> add_instant(VM&, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
BigInt* difference_instant(VM&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode);
BigInt* round_temporal_instant(VM&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode);
-ThrowCompletionOr<DeprecatedString> temporal_instant_to_string(VM&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
+ThrowCompletionOr<String> temporal_instant_to_string(VM&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
ThrowCompletionOr<Duration*> difference_temporal_instant(VM&, DifferenceOperation, Instant const&, Value other, Value options);
ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(VM&, ArithmeticOperation, Instant const&, Value temporal_duration_like);