1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08:13 +00:00

LibJS: Port format_seconds_string_part() to String

This commit is contained in:
Linus Groh 2023-01-26 14:15:13 +00:00
parent 654911444e
commit 82ba940646
6 changed files with 20 additions and 19 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -434,7 +434,7 @@ ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(VM& vm, Object
}
// 4.5.9 TemporalTimeToString ( hour, minute, second, millisecond, microsecond, nanosecond, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporaltimetostring
DeprecatedString temporal_time_to_string(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision)
ThrowCompletionOr<DeprecatedString> temporal_time_to_string(VM& vm, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision)
{
// 1. Assert: hour, minute, second, millisecond, microsecond and nanosecond are integers.
@ -442,7 +442,7 @@ DeprecatedString temporal_time_to_string(u8 hour, u8 minute, u8 second, u16 mill
// 3. Let minute be ToZeroPaddedDecimalString(minute, 2).
// 4. Let seconds be ! FormatSecondsStringPart(second, millisecond, microsecond, nanosecond, precision).
auto seconds = format_seconds_string_part(second, millisecond, microsecond, nanosecond, precision);
auto seconds = MUST_OR_THROW_OOM(format_seconds_string_part(vm, second, millisecond, microsecond, nanosecond, precision));
// 5. Return the string-concatenation of hour, the code unit 0x003A (COLON), minute, and seconds.
return DeprecatedString::formatted("{:02}:{:02}{}", hour, minute, seconds);