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

LibJS: Port calendar / time zone members of Temporal* structs to String

This commit is contained in:
Linus Groh 2023-01-26 15:00:53 +00:00
parent ef389c086d
commit 4a7d6670d8
4 changed files with 25 additions and 25 deletions

View file

@ -657,11 +657,11 @@ 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 = canonicalize_time_zone_name(*time_zone_name);
time_zone_name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(time_zone_name->to_deprecated_string())));
}
// ii. Let timeZone be ! CreateTemporalTimeZone(timeZoneName).
time_zone = MUST(create_temporal_time_zone(vm, *time_zone_name));
time_zone = MUST(create_temporal_time_zone(vm, time_zone_name->to_deprecated_string()));
// iii. If result.[[TimeZone]].[[Z]] is true, then
if (result.time_zone.z) {
@ -1322,7 +1322,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& pa
auto name = parse_result.time_zone_identifier;
// b. Set timeZoneResult.[[Name]] to CodePointsToString(name).
time_zone_result.name = *name;
time_zone_result.name = TRY_OR_THROW_OOM(vm, String::from_utf8(*name));
}
// 21. If parseResult contains a UTCDesignator Parse Node, then
@ -1338,12 +1338,12 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& pa
auto offset = parse_result.time_zone_numeric_utc_offset;
// ii. Set timeZoneResult.[[OffsetString]] to CodePointsToString(offset).
time_zone_result.offset_string = *offset;
time_zone_result.offset_string = TRY_OR_THROW_OOM(vm, String::from_utf8(*offset));
}
}
// 23. Let calendar be undefined.
Optional<DeprecatedString> calendar;
Optional<String> calendar;
// 24. For each Annotation Parse Node annotation contained within parseResult, do
for (auto const& annotation : parse_result.annotations) {
@ -1358,7 +1358,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& pa
auto const& value = annotation.value;
// 2. Let calendar be CodePointsToString(value).
calendar = value;
calendar = TRY_OR_THROW_OOM(vm, String::from_utf8(value));
}
}
// c. Else,
@ -1385,12 +1385,12 @@ ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM& vm, StringV
auto result = TRY(parse_iso_date_time(vm, *parse_result));
// 3. Let offsetString be result.[[TimeZone]].[[OffsetString]].
Optional<DeprecatedString> offset_string = result.time_zone.offset_string;
auto offset_string = result.time_zone.offset_string;
// 4. If result.[[TimeZone]].[[Z]] is true, then
if (result.time_zone.z) {
// a. Set offsetString to "+00:00".
offset_string = "+00:00"sv;
offset_string = TRY_OR_THROW_OOM(vm, String::from_utf8("+00:00"sv));
}
// 6. Assert: offsetString is not undefined.
@ -1428,7 +1428,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, StringView iso_
return TRY_OR_THROW_OOM(vm, String::from_utf8("iso8601"sv));
// c. Else, return calendar.
else
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(*calendar));
return calendar.release_value();
}
// 3. Else,
else {
@ -1686,7 +1686,7 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(VM& vm, Stri
// 2. If parseResult is a Parse Node, then
if (parse_result.has_value()) {
// a. Return the Record { [[Z]]: false, [[OffsetString]]: undefined, [[Name]]: timeZoneString }.
return TemporalTimeZone { .z = false, .offset_string = {}, .name = time_zone_string };
return TemporalTimeZone { .z = false, .offset_string = {}, .name = TRY_OR_THROW_OOM(vm, String::from_utf8(time_zone_string)) };
}
// 3. Let result be ? ParseISODateTime(timeZoneString).

View file

@ -57,14 +57,14 @@ struct TemporalInstant {
u16 millisecond;
u16 microsecond;
u16 nanosecond;
Optional<DeprecatedString> time_zone_offset;
Optional<String> time_zone_offset;
};
struct TemporalDate {
i32 year;
u8 month;
u8 day;
Optional<DeprecatedString> calendar;
Optional<String> calendar;
};
struct TemporalTime {
@ -74,27 +74,27 @@ struct TemporalTime {
u16 millisecond;
u16 microsecond;
u16 nanosecond;
Optional<DeprecatedString> calendar = {};
Optional<String> calendar = {};
};
struct TemporalTimeZone {
bool z;
Optional<DeprecatedString> offset_string;
Optional<DeprecatedString> name;
Optional<String> offset_string;
Optional<String> name;
};
struct TemporalYearMonth {
i32 year;
u8 month;
u8 day;
Optional<DeprecatedString> calendar = {};
Optional<String> calendar = {};
};
struct TemporalMonthDay {
Optional<i32> year;
u8 month;
u8 day;
Optional<DeprecatedString> calendar = {};
Optional<String> calendar = {};
};
struct ISODateTime {
@ -108,7 +108,7 @@ struct ISODateTime {
u16 microsecond;
u16 nanosecond;
TemporalTimeZone time_zone { .z = false, .offset_string = {}, .name = {} };
Optional<DeprecatedString> calendar = {};
Optional<String> calendar = {};
};
struct SecondsStringPrecision {

View file

@ -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
*/
@ -349,11 +349,11 @@ 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 = canonicalize_time_zone_name(name);
name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(name.to_deprecated_string())));
}
// c. Return ! CreateTemporalTimeZone(name).
return MUST(create_temporal_time_zone(vm, name));
return MUST(create_temporal_time_zone(vm, name.to_deprecated_string()));
}
// 5. If parseResult.[[Z]] is true, return ! CreateTemporalTimeZone("UTC").
@ -361,7 +361,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
return MUST(create_temporal_time_zone(vm, "UTC"sv));
// 6. Return ! CreateTemporalTimeZone(parseResult.[[OffsetString]]).
return MUST(create_temporal_time_zone(vm, *parse_result.offset_string));
return MUST(create_temporal_time_zone(vm, parse_result.offset_string->to_deprecated_string()));
}
// 11.6.8 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor

View file

@ -130,7 +130,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
Object* calendar = nullptr;
Object* time_zone = nullptr;
Optional<DeprecatedString> offset_string;
Optional<String> offset_string;
ISODateTime result;
// 5. If Type(item) is Object, then
@ -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 = canonicalize_time_zone_name(*time_zone_name);
time_zone_name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(time_zone_name->to_deprecated_string())));
}
// g. Let offsetString be result.[[TimeZone]].[[OffsetString]].
@ -221,7 +221,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
}
// j. Let timeZone be ! CreateTemporalTimeZone(timeZoneName).
time_zone = MUST(create_temporal_time_zone(vm, *time_zone_name));
time_zone = MUST(create_temporal_time_zone(vm, time_zone_name->to_deprecated_string()));
// k. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
auto temporal_calendar_like = result.calendar.has_value()