mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibJS: Port format_iso_time_zone_offset_string() to String
This commit is contained in:
parent
c2656f4ee7
commit
95becb22ef
4 changed files with 7 additions and 7 deletions
|
@ -275,7 +275,7 @@ ThrowCompletionOr<String> temporal_instant_to_string(VM& vm, Instant& instant, V
|
||||||
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
|
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
|
||||||
|
|
||||||
// b. Let timeZoneString be ! FormatISOTimeZoneOffsetString(offsetNs).
|
// b. Let timeZoneString be ! FormatISOTimeZoneOffsetString(offsetNs).
|
||||||
time_zone_string = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(format_iso_time_zone_offset_string(offset_ns)));
|
time_zone_string = MUST_OR_THROW_OOM(format_iso_time_zone_offset_string(vm, offset_ns));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. Return the string-concatenation of dateTimeString and timeZoneString.
|
// 10. Return the string-concatenation of dateTimeString and timeZoneString.
|
||||||
|
|
|
@ -264,7 +264,7 @@ ThrowCompletionOr<String> format_time_zone_offset_string(VM& vm, double offset_n
|
||||||
}
|
}
|
||||||
|
|
||||||
// 11.6.6 FormatISOTimeZoneOffsetString ( offsetNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-formatisotimezoneoffsetstring
|
// 11.6.6 FormatISOTimeZoneOffsetString ( offsetNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-formatisotimezoneoffsetstring
|
||||||
DeprecatedString format_iso_time_zone_offset_string(double offset_nanoseconds)
|
ThrowCompletionOr<String> format_iso_time_zone_offset_string(VM& vm, double offset_nanoseconds)
|
||||||
{
|
{
|
||||||
// 1. Assert: offsetNanoseconds is an integer.
|
// 1. Assert: offsetNanoseconds is an integer.
|
||||||
VERIFY(trunc(offset_nanoseconds) == offset_nanoseconds);
|
VERIFY(trunc(offset_nanoseconds) == offset_nanoseconds);
|
||||||
|
@ -287,7 +287,7 @@ DeprecatedString format_iso_time_zone_offset_string(double offset_nanoseconds)
|
||||||
// 7. Let h be ToZeroPaddedDecimalString(hours, 2).
|
// 7. Let h be ToZeroPaddedDecimalString(hours, 2).
|
||||||
// 8. Let m be ToZeroPaddedDecimalString(minutes, 2).
|
// 8. Let m be ToZeroPaddedDecimalString(minutes, 2).
|
||||||
// 9. Return the string-concatenation of sign, h, the code unit 0x003A (COLON), and m.
|
// 9. Return the string-concatenation of sign, h, the code unit 0x003A (COLON), and m.
|
||||||
return DeprecatedString::formatted("{}{:02}:{:02}", sign, (u32)hours, (u32)minutes);
|
return TRY_OR_THROW_OOM(vm, String::formatted("{}{:02}:{:02}", sign, (u32)hours, (u32)minutes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 11.6.7 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone
|
// 11.6.7 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone
|
||||||
|
|
|
@ -43,7 +43,7 @@ ISODateTime get_iso_parts_from_epoch(VM&, Crypto::SignedBigInteger const& epoch_
|
||||||
BigInt* get_named_time_zone_next_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);
|
BigInt* get_named_time_zone_next_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);
|
||||||
BigInt* get_named_time_zone_previous_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);
|
BigInt* get_named_time_zone_previous_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);
|
||||||
ThrowCompletionOr<String> format_time_zone_offset_string(VM&, double offset_nanoseconds);
|
ThrowCompletionOr<String> format_time_zone_offset_string(VM&, double offset_nanoseconds);
|
||||||
DeprecatedString format_iso_time_zone_offset_string(double offset_nanoseconds);
|
ThrowCompletionOr<String> format_iso_time_zone_offset_string(VM&, double offset_nanoseconds);
|
||||||
ThrowCompletionOr<Object*> to_temporal_time_zone(VM&, Value temporal_time_zone_like);
|
ThrowCompletionOr<Object*> to_temporal_time_zone(VM&, Value temporal_time_zone_like);
|
||||||
ThrowCompletionOr<double> get_offset_nanoseconds_for(VM&, Value time_zone, Instant&);
|
ThrowCompletionOr<double> get_offset_nanoseconds_for(VM&, Value time_zone, Instant&);
|
||||||
ThrowCompletionOr<DeprecatedString> builtin_time_zone_get_offset_string_for(VM&, Value time_zone, Instant&);
|
ThrowCompletionOr<DeprecatedString> builtin_time_zone_get_offset_string_for(VM&, Value time_zone, Instant&);
|
||||||
|
|
|
@ -314,12 +314,12 @@ ThrowCompletionOr<DeprecatedString> temporal_zoned_date_time_to_string(VM& vm, Z
|
||||||
// 9. Let dateTimeString be ! TemporalDateTimeToString(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]], isoCalendar, precision, "never").
|
// 9. Let dateTimeString be ! TemporalDateTimeToString(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]], isoCalendar, precision, "never").
|
||||||
auto date_time_string = MUST_OR_THROW_OOM(temporal_date_time_to_string(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), iso_calendar, precision, "never"sv));
|
auto date_time_string = MUST_OR_THROW_OOM(temporal_date_time_to_string(vm, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), iso_calendar, precision, "never"sv));
|
||||||
|
|
||||||
DeprecatedString offset_string;
|
String offset_string;
|
||||||
|
|
||||||
// 10. If showOffset is "never", then
|
// 10. If showOffset is "never", then
|
||||||
if (show_offset == "never"sv) {
|
if (show_offset == "never"sv) {
|
||||||
// a. Let offsetString be the empty String.
|
// a. Let offsetString be the empty String.
|
||||||
offset_string = DeprecatedString::empty();
|
offset_string = {};
|
||||||
}
|
}
|
||||||
// 11. Else,
|
// 11. Else,
|
||||||
else {
|
else {
|
||||||
|
@ -327,7 +327,7 @@ ThrowCompletionOr<DeprecatedString> temporal_zoned_date_time_to_string(VM& vm, Z
|
||||||
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, &time_zone, *instant));
|
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, &time_zone, *instant));
|
||||||
|
|
||||||
// b. Let offsetString be ! FormatISOTimeZoneOffsetString(offsetNs).
|
// b. Let offsetString be ! FormatISOTimeZoneOffsetString(offsetNs).
|
||||||
offset_string = format_iso_time_zone_offset_string(offset_ns);
|
offset_string = MUST_OR_THROW_OOM(format_iso_time_zone_offset_string(vm, offset_ns));
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString time_zone_string;
|
DeprecatedString time_zone_string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue