mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibJS: Use consistent name for offset strings
This is an editorial change in the Temporal spec.
See: 17f8cdb
This commit is contained in:
parent
eb9c8f3895
commit
6d744eb4a7
4 changed files with 19 additions and 19 deletions
|
@ -658,8 +658,8 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
|
||||||
// c. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
|
// c. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
|
||||||
calendar = TRY(to_temporal_calendar_with_iso_default(global_object, parsed_result.date_time.calendar.has_value() ? js_string(vm, *parsed_result.date_time.calendar) : js_undefined()));
|
calendar = TRY(to_temporal_calendar_with_iso_default(global_object, parsed_result.date_time.calendar.has_value() ? js_string(vm, *parsed_result.date_time.calendar) : js_undefined()));
|
||||||
|
|
||||||
// d. Let offsetString be result.[[TimeZoneOffset]].
|
// d. Let offsetString be result.[[TimeZoneOffsetString]].
|
||||||
offset_string = parsed_result.time_zone.offset.has_value() ? js_string(vm, *parsed_result.time_zone.offset) : js_undefined();
|
offset_string = parsed_result.time_zone.offset_string.has_value() ? js_string(vm, *parsed_result.time_zone.offset_string) : js_undefined();
|
||||||
|
|
||||||
// e. Let timeZoneName be result.[[TimeZoneIANAName]].
|
// e. Let timeZoneName be result.[[TimeZoneIANAName]].
|
||||||
auto time_zone_name = parsed_result.time_zone.name;
|
auto time_zone_name = parsed_result.time_zone.name;
|
||||||
|
@ -1244,7 +1244,7 @@ ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(GlobalObject& g
|
||||||
auto time_zone_result = TRY(parse_temporal_time_zone_string(global_object, iso_string));
|
auto time_zone_result = TRY(parse_temporal_time_zone_string(global_object, iso_string));
|
||||||
|
|
||||||
// 5. Let offsetString be timeZoneResult.[[OffsetString]].
|
// 5. Let offsetString be timeZoneResult.[[OffsetString]].
|
||||||
auto offset_string = time_zone_result.offset;
|
auto offset_string = time_zone_result.offset_string;
|
||||||
|
|
||||||
// 6. If timeZoneResult.[[Z]] is true, then
|
// 6. If timeZoneResult.[[Z]] is true, then
|
||||||
if (time_zone_result.z) {
|
if (time_zone_result.z) {
|
||||||
|
@ -1559,7 +1559,7 @@ ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(Globa
|
||||||
auto result = MUST(parse_iso_date_time(global_object, *parse_result));
|
auto result = MUST(parse_iso_date_time(global_object, *parse_result));
|
||||||
|
|
||||||
bool z;
|
bool z;
|
||||||
Optional<String> offset;
|
Optional<String> offset_string;
|
||||||
Optional<String> time_zone;
|
Optional<String> time_zone;
|
||||||
|
|
||||||
// 4. If isoString satisfies the syntax of a TemporalZonedDateTimeString (see 13.33), then
|
// 4. If isoString satisfies the syntax of a TemporalZonedDateTimeString (see 13.33), then
|
||||||
|
@ -1571,8 +1571,8 @@ ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(Globa
|
||||||
// b. Let z be timeZoneResult.[[Z]].
|
// b. Let z be timeZoneResult.[[Z]].
|
||||||
z = time_zone_result.z;
|
z = time_zone_result.z;
|
||||||
|
|
||||||
// c. Let offset be timeZoneResult.[[Offset]].
|
// c. Let offsetString be timeZoneResult.[[OffsetString]].
|
||||||
offset = time_zone_result.offset;
|
offset_string = time_zone_result.offset_string;
|
||||||
|
|
||||||
// d. Let timeZone be timeZoneResult.[[Name]].
|
// d. Let timeZone be timeZoneResult.[[Name]].
|
||||||
time_zone = time_zone_result.name;
|
time_zone = time_zone_result.name;
|
||||||
|
@ -1582,12 +1582,12 @@ ThrowCompletionOr<TemporalZonedDateTime> parse_temporal_relative_to_string(Globa
|
||||||
// a. Let z be false.
|
// a. Let z be false.
|
||||||
z = false;
|
z = false;
|
||||||
|
|
||||||
// b. Let offset be undefined.
|
// b. Let offsetString be undefined.
|
||||||
// c. Let timeZone be undefined.
|
// c. Let timeZone be undefined.
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[Hour]]: result.[[Hour]], [[Minute]]: result.[[Minute]], [[Second]]: result.[[Second]], [[Millisecond]]: result.[[Millisecond]], [[Microsecond]]: result.[[Microsecond]], [[Nanosecond]]: result.[[Nanosecond]], [[Calendar]]: result.[[Calendar]], [[TimeZoneZ]]: z, [[TimeZoneOffset]]: offset, [[TimeZoneIANAName]]: timeZone }.
|
// 6. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[Hour]]: result.[[Hour]], [[Minute]]: result.[[Minute]], [[Second]]: result.[[Second]], [[Millisecond]]: result.[[Millisecond]], [[Microsecond]]: result.[[Microsecond]], [[Nanosecond]]: result.[[Nanosecond]], [[Calendar]]: result.[[Calendar]], [[TimeZoneZ]]: z, [[TimeZoneOffsetString]]: offsetString, [[TimeZoneIANAName]]: timeZone }.
|
||||||
return TemporalZonedDateTime { .date_time = move(result), .time_zone = { .z = z, .offset = move(offset), .name = move(time_zone) } };
|
return TemporalZonedDateTime { .date_time = move(result), .time_zone = { .z = z, .offset_string = move(offset_string), .name = move(time_zone) } };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.42 ParseTemporalTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimestring
|
// 13.42 ParseTemporalTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimestring
|
||||||
|
@ -1647,10 +1647,10 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject
|
||||||
// 4. If z is not undefined, then
|
// 4. If z is not undefined, then
|
||||||
if (z_part.has_value()) {
|
if (z_part.has_value()) {
|
||||||
// a. Return the Record { [[Z]]: true, [[OffsetString]]: undefined, [[Name]]: name }.
|
// a. Return the Record { [[Z]]: true, [[OffsetString]]: undefined, [[Name]]: name }.
|
||||||
return TemporalTimeZone { .z = true, .offset = {}, .name = name_part.has_value() ? String { *name_part } : Optional<String> {} };
|
return TemporalTimeZone { .z = true, .offset_string = {}, .name = name_part.has_value() ? String { *name_part } : Optional<String> {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<String> offset;
|
Optional<String> offset_string;
|
||||||
// 5. If hours is undefined, then
|
// 5. If hours is undefined, then
|
||||||
if (!hours_part.has_value()) {
|
if (!hours_part.has_value()) {
|
||||||
// a. Let offsetString be undefined.
|
// a. Let offsetString be undefined.
|
||||||
|
@ -1704,11 +1704,11 @@ ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject
|
||||||
auto offset_nanoseconds = sign * (((hours * 60 + minutes) * 60 + seconds) * 1000000000.0 + nanoseconds);
|
auto offset_nanoseconds = sign * (((hours * 60 + minutes) * 60 + seconds) * 1000000000.0 + nanoseconds);
|
||||||
|
|
||||||
// j. Let offsetString be ! FormatTimeZoneOffsetString(offsetNanoseconds).
|
// j. Let offsetString be ! FormatTimeZoneOffsetString(offsetNanoseconds).
|
||||||
offset = format_time_zone_offset_string(offset_nanoseconds);
|
offset_string = format_time_zone_offset_string(offset_nanoseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Return the Record { [[Z]]: false, [[OffsetString]]: offsetString, [[Name]]: name }.
|
// 7. Return the Record { [[Z]]: false, [[OffsetString]]: offsetString, [[Name]]: name }.
|
||||||
return TemporalTimeZone { .z = false, .offset = offset, .name = name_part.has_value() ? String { *name_part } : Optional<String> {} };
|
return TemporalTimeZone { .z = false, .offset_string = offset_string, .name = name_part.has_value() ? String { *name_part } : Optional<String> {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.44 ParseTemporalYearMonthString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalyearmonthstring
|
// 13.44 ParseTemporalYearMonthString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalyearmonthstring
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -68,7 +68,7 @@ struct TemporalTime {
|
||||||
|
|
||||||
struct TemporalTimeZone {
|
struct TemporalTimeZone {
|
||||||
bool z;
|
bool z;
|
||||||
Optional<String> offset;
|
Optional<String> offset_string;
|
||||||
Optional<String> name;
|
Optional<String> name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -429,8 +429,8 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
|
||||||
// a. If ParseText(! StringToCodePoints(parseResult.[[Name]], TimeZoneNumericUTCOffset)) is not a List of errors, then
|
// a. If ParseText(! StringToCodePoints(parseResult.[[Name]], TimeZoneNumericUTCOffset)) is not a List of errors, then
|
||||||
if (is_valid_time_zone_numeric_utc_offset_syntax(*parse_result.name)) {
|
if (is_valid_time_zone_numeric_utc_offset_syntax(*parse_result.name)) {
|
||||||
// i. If parseResult.[[OffsetString]] is not undefined, and ! ParseTimeZoneOffsetString(parseResult.[[OffsetString]]) ≠ ! ParseTimeZoneOffsetString(parseResult.[[Name]]), throw a RangeError exception.
|
// i. If parseResult.[[OffsetString]] is not undefined, and ! ParseTimeZoneOffsetString(parseResult.[[OffsetString]]) ≠ ! ParseTimeZoneOffsetString(parseResult.[[Name]]), throw a RangeError exception.
|
||||||
if (parse_result.offset.has_value() && (MUST(parse_time_zone_offset_string(global_object, *parse_result.offset)) != MUST(parse_time_zone_offset_string(global_object, *parse_result.name))))
|
if (parse_result.offset_string.has_value() && (MUST(parse_time_zone_offset_string(global_object, *parse_result.offset_string)) != MUST(parse_time_zone_offset_string(global_object, *parse_result.name))))
|
||||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalTimeZoneOffsetStringMismatch, *parse_result.offset, *parse_result.name);
|
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalTimeZoneOffsetStringMismatch, *parse_result.offset_string, *parse_result.name);
|
||||||
}
|
}
|
||||||
// b. Else,
|
// b. Else,
|
||||||
else {
|
else {
|
||||||
|
@ -448,7 +448,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
|
||||||
return MUST(create_temporal_time_zone(global_object, "UTC"sv));
|
return MUST(create_temporal_time_zone(global_object, "UTC"sv));
|
||||||
|
|
||||||
// 6. Return ! CreateTemporalTimeZone(parseResult.[[OffsetString]]).
|
// 6. Return ! CreateTemporalTimeZone(parseResult.[[OffsetString]]).
|
||||||
return MUST(create_temporal_time_zone(global_object, *parse_result.offset));
|
return MUST(create_temporal_time_zone(global_object, *parse_result.offset_string));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 11.6.11 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor
|
// 11.6.11 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor
|
||||||
|
|
|
@ -215,7 +215,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
|
||||||
}
|
}
|
||||||
|
|
||||||
// g. Let offsetString be result.[[TimeZoneOffsetString]].
|
// g. Let offsetString be result.[[TimeZoneOffsetString]].
|
||||||
offset_string = move(parsed_result.time_zone.offset);
|
offset_string = move(parsed_result.time_zone.offset_string);
|
||||||
|
|
||||||
// h. If result.[[TimeZoneZ]] is true, then
|
// h. If result.[[TimeZoneZ]] is true, then
|
||||||
if (parsed_result.time_zone.z) {
|
if (parsed_result.time_zone.z) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue