Skip to content

Commit 462e7b0

Browse files
committed
LibJS: Introduce Time Zone Identifier Parse Records to Temporal
This is an editorial change in the Temporal proposal. See: tc39/proposal-temporal@96bb9b0 Note that we already had a struct for this, but now that it has a proper name and spec link, this renames it to match other Parse Records and places it alongside them.
1 parent ae73280 commit 462e7b0

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

Libraries/LibJS/Forward.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ struct ISOYearMonth;
314314
struct ParseResult;
315315
struct PartialDuration;
316316
struct Time;
317-
struct TimeZone;
318317
struct TimeZoneOffset;
319318

320319
};

Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ Crypto::SignedBigInteger round_number_to_increment_as_if_positive(Crypto::Signed
11171117
return rounded.multiplied_by(increment);
11181118
}
11191119

1120-
// 13.34 ParseISODateTime ( isoString, allowedFormats ), https://tc39.es/proposal-temporal/#sec-temporal-parseisodatetime
1120+
// 13.35 ParseISODateTime ( isoString, allowedFormats ), https://tc39.es/proposal-temporal/#sec-temporal-parseisodatetime
11211121
ThrowCompletionOr<ParsedISODateTime> parse_iso_date_time(VM& vm, StringView iso_string, ReadonlySpan<Production> allowed_formats)
11221122
{
11231123
// 1. Let parseResult be EMPTY.
@@ -1333,7 +1333,7 @@ ThrowCompletionOr<ParsedISODateTime> parse_iso_date_time(VM& vm, StringView iso_
13331333
return ParsedISODateTime { .year = year_return, .month = static_cast<u8>(month_value), .day = static_cast<u8>(day_value), .time = move(time), .time_zone = move(time_zone_result), .calendar = move(calendar) };
13341334
}
13351335

1336-
// 13.35 ParseTemporalCalendarString ( string ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalcalendarstring
1336+
// 13.36 ParseTemporalCalendarString ( string ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalcalendarstring
13371337
ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, String const& string)
13381338
{
13391339
// 1. Let parseResult be Completion(ParseISODateTime(string, « TemporalDateTimeString[+Zoned], TemporalDateTimeString[~Zoned],
@@ -1370,7 +1370,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, String const& s
13701370
return string;
13711371
}
13721372

1373-
// 13.36 ParseTemporalDurationString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldurationstring
1373+
// 13.37 ParseTemporalDurationString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldurationstring
13741374
ThrowCompletionOr<GC::Ref<Duration>> parse_temporal_duration_string(VM& vm, StringView iso_string)
13751375
{
13761376
// 1. Let duration be ParseText(StringToCodePoints(isoString), TemporalDurationString).
@@ -1590,8 +1590,8 @@ ThrowCompletionOr<GC::Ref<Duration>> parse_temporal_duration_string(VM& vm, Stri
15901590
return TRY(create_temporal_duration(vm, years_value, months_value, weeks_value, days_value, hours_value, factored_minutes_value, factored_seconds_value, factored_milliseconds_value, factored_microseconds_value, factored_nanoseconds_value));
15911591
}
15921592

1593-
// 13.37 ParseTemporalTimeZoneString ( timeZoneString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimezonestring
1594-
ThrowCompletionOr<TimeZone> parse_temporal_time_zone_string(VM& vm, StringView time_zone_string)
1593+
// 13.38 ParseTemporalTimeZoneString ( timeZoneString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimezonestring
1594+
ThrowCompletionOr<ParsedTimeZoneIdentifier> parse_temporal_time_zone_string(VM& vm, StringView time_zone_string)
15951595
{
15961596
// 1. Let parseResult be ParseText(StringToCodePoints(timeZoneString), TimeZoneIdentifier).
15971597
auto parse_result = parse_iso8601(Production::TimeZoneIdentifier, time_zone_string);
@@ -1640,7 +1640,7 @@ ThrowCompletionOr<TimeZone> parse_temporal_time_zone_string(VM& vm, StringView t
16401640
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneString, time_zone_string);
16411641
}
16421642

1643-
// 13.40 ToOffsetString ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tooffsetstring
1643+
// 13.41 ToOffsetString ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tooffsetstring
16441644
ThrowCompletionOr<String> to_offset_string(VM& vm, Value argument)
16451645
{
16461646
// 1. Let offset be ? ToPrimitive(argument, STRING).
@@ -1657,7 +1657,7 @@ ThrowCompletionOr<String> to_offset_string(VM& vm, Value argument)
16571657
return offset.as_string().utf8_string();
16581658
}
16591659

1660-
// 13.41 ISODateToFields ( calendar, isoDate, type ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetofields
1660+
// 13.42 ISODateToFields ( calendar, isoDate, type ), https://tc39.es/proposal-temporal/#sec-temporal-isodatetofields
16611661
CalendarFields iso_date_to_fields(StringView calendar, ISODate iso_date, DateType type)
16621662
{
16631663
// 1. Let fields be an empty Calendar Fields Record with all fields set to unset.
@@ -1685,7 +1685,7 @@ CalendarFields iso_date_to_fields(StringView calendar, ISODate iso_date, DateTyp
16851685
return fields;
16861686
}
16871687

1688-
// 13.42 GetDifferenceSettings ( operation, options, unitGroup, disallowedUnits, fallbackSmallestUnit, smallestLargestDefaultUnit ), https://tc39.es/proposal-temporal/#sec-temporal-getdifferencesettings
1688+
// 13.43 GetDifferenceSettings ( operation, options, unitGroup, disallowedUnits, fallbackSmallestUnit, smallestLargestDefaultUnit ), https://tc39.es/proposal-temporal/#sec-temporal-getdifferencesettings
16891689
ThrowCompletionOr<DifferenceSettings> get_difference_settings(VM& vm, DurationOperation operation, Object const& options, UnitGroup unit_group, ReadonlySpan<Unit> disallowed_units, Unit fallback_smallest_unit, Unit smallest_largest_default_unit)
16901690
{
16911691
// 1. NOTE: The following steps read options and perform independent validation in alphabetical order.

Libraries/LibJS/Runtime/Temporal/AbstractOperations.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ Crypto::SignedBigInteger round_number_to_increment_as_if_positive(Crypto::Signed
194194
ThrowCompletionOr<ParsedISODateTime> parse_iso_date_time(VM&, StringView iso_string, ReadonlySpan<Production> allowed_formats);
195195
ThrowCompletionOr<String> parse_temporal_calendar_string(VM&, String const&);
196196
ThrowCompletionOr<GC::Ref<Duration>> parse_temporal_duration_string(VM&, StringView iso_string);
197-
ThrowCompletionOr<TimeZone> parse_temporal_time_zone_string(VM&, StringView time_zone_string);
197+
ThrowCompletionOr<ParsedTimeZoneIdentifier> parse_temporal_time_zone_string(VM&, StringView time_zone_string);
198198
ThrowCompletionOr<String> to_offset_string(VM&, Value argument);
199199
CalendarFields iso_date_to_fields(StringView calendar, ISODate, DateType);
200200
ThrowCompletionOr<DifferenceSettings> get_difference_settings(VM&, DurationOperation, Object const& options, UnitGroup, ReadonlySpan<Unit> disallowed_units, Unit fallback_smallest_unit, Unit smallest_largest_default_unit);
201201

202-
// 13.39 ToIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerwithtruncation
202+
// 13.40 ToIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerwithtruncation
203203
template<typename... Args>
204204
ThrowCompletionOr<double> to_integer_with_truncation(VM& vm, Value argument, ErrorType const& error_type, Args&&... args)
205205
{
@@ -214,7 +214,7 @@ ThrowCompletionOr<double> to_integer_with_truncation(VM& vm, Value argument, Err
214214
return trunc(number.as_double());
215215
}
216216

217-
// 13.39 ToIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerwithtruncation
217+
// 13.40 ToIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-tointegerwithtruncation
218218
// AD-HOC: We often need to use this AO when we have a parsed StringView. This overload allows callers to avoid creating
219219
// a PrimitiveString for the primary definition.
220220
template<typename... Args>
@@ -231,7 +231,7 @@ ThrowCompletionOr<double> to_integer_with_truncation(VM& vm, StringView argument
231231
return trunc(number);
232232
}
233233

234-
// 13.38 ToPositiveIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-topositiveintegerwithtruncation
234+
// 13.39 ToPositiveIntegerWithTruncation ( argument ), https://tc39.es/proposal-temporal/#sec-topositiveintegerwithtruncation
235235
template<typename... Args>
236236
ThrowCompletionOr<double> to_positive_integer_with_truncation(VM& vm, Value argument, ErrorType const& error_type, Args&&... args)
237237
{

Libraries/LibJS/Runtime/Temporal/ISORecords.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ struct ParsedISOTimeZone {
5757
Optional<String> time_zone_annotation;
5858
};
5959

60-
// 13.33 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records
60+
// 13.33 Time Zone Identifier Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-time-zone-identifier-parse-records
61+
struct ParsedTimeZoneIdentifier {
62+
Optional<String> name;
63+
Optional<i64> offset_minutes;
64+
};
65+
66+
// 13.34 ISO Date-Time Parse Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-time-parse-records
6167
struct ParsedISODateTime {
6268
struct StartOfDay { };
6369

Libraries/LibJS/Runtime/Temporal/TimeZone.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ bool time_zone_equals(StringView one, StringView two)
403403
}
404404

405405
// 11.1.16 ParseTimeZoneIdentifier ( identifier ), https://tc39.es/proposal-temporal/#sec-parsetimezoneidentifier
406-
ThrowCompletionOr<TimeZone> parse_time_zone_identifier(VM& vm, StringView identifier)
406+
ThrowCompletionOr<ParsedTimeZoneIdentifier> parse_time_zone_identifier(VM& vm, StringView identifier)
407407
{
408408
// 1. Let parseResult be ParseText(StringToCodePoints(identifier), TimeZoneIdentifier).
409409
auto parse_result = parse_iso8601(Production::TimeZoneIdentifier, identifier);
@@ -416,7 +416,7 @@ ThrowCompletionOr<TimeZone> parse_time_zone_identifier(VM& vm, StringView identi
416416
}
417417

418418
// 11.1.16 ParseTimeZoneIdentifier ( identifier ), https://tc39.es/proposal-temporal/#sec-parsetimezoneidentifier
419-
TimeZone parse_time_zone_identifier(StringView identifier)
419+
ParsedTimeZoneIdentifier parse_time_zone_identifier(StringView identifier)
420420
{
421421
// OPTIMIZATION: Some callers can assume that parsing will succeed.
422422

@@ -428,7 +428,7 @@ TimeZone parse_time_zone_identifier(StringView identifier)
428428
}
429429

430430
// 11.1.16 ParseTimeZoneIdentifier ( identifier ), https://tc39.es/proposal-temporal/#sec-parsetimezoneidentifier
431-
TimeZone parse_time_zone_identifier(ParseResult const& parse_result)
431+
ParsedTimeZoneIdentifier parse_time_zone_identifier(ParseResult const& parse_result)
432432
{
433433
// OPTIMIZATION: Some callers will have already parsed and validated the time zone identifier.
434434

@@ -437,8 +437,8 @@ TimeZone parse_time_zone_identifier(ParseResult const& parse_result)
437437
// a. Let name be the source text matched by the TimeZoneIANAName Parse Node contained within parseResult.
438438
// b. NOTE: name is syntactically valid, but does not necessarily conform to IANA Time Zone Database naming
439439
// guidelines or correspond with an available named time zone identifier.
440-
// c. Return the Record { [[Name]]: CodePointsToString(name), [[OffsetMinutes]]: empty }.
441-
return TimeZone { .name = String::from_utf8_without_validation(parse_result.time_zone_iana_name->bytes()), .offset_minutes = {} };
440+
// c. Return Time Zone Identifier Parse Record { [[Name]]: CodePointsToString(name), [[OffsetMinutes]]: EMPTY }.
441+
return ParsedTimeZoneIdentifier { .name = String::from_utf8_without_validation(parse_result.time_zone_iana_name->bytes()), .offset_minutes = {} };
442442
}
443443
// 4. Else,
444444
else {
@@ -455,8 +455,8 @@ TimeZone parse_time_zone_identifier(ParseResult const& parse_result)
455455
// e. Assert: offsetMinutes is an integer.
456456
VERIFY(trunc(offset_minutes) == offset_minutes);
457457

458-
// f. Return the Record { [[Name]]: empty, [[OffsetMinutes]]: offsetMinutes }.
459-
return TimeZone { .name = {}, .offset_minutes = static_cast<i64>(offset_minutes) };
458+
// f. Return Time Zone Identifier Parse Record { [[Name]]: EMPTY, [[OffsetMinutes]]: offsetMinutes }.
459+
return ParsedTimeZoneIdentifier { .name = {}, .offset_minutes = static_cast<i64>(offset_minutes) };
460460
}
461461
}
462462

Libraries/LibJS/Runtime/Temporal/TimeZone.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
#include <LibCrypto/BigInt/SignedBigInteger.h>
1313
#include <LibJS/Runtime/Completion.h>
1414
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
15+
#include <LibJS/Runtime/Temporal/ISORecords.h>
1516
#include <LibJS/Runtime/Value.h>
1617

1718
namespace JS::Temporal {
1819

19-
struct TimeZone {
20-
Optional<String> name;
21-
Optional<i64> offset_minutes;
22-
};
23-
2420
ISODateTime get_iso_parts_from_epoch(Crypto::SignedBigInteger const& epoch_nanoseconds);
2521
Optional<Crypto::SignedBigInteger> get_named_time_zone_next_transition(StringView time_zone, Crypto::SignedBigInteger const& epoch_nanoseconds);
2622
Optional<Crypto::SignedBigInteger> get_named_time_zone_previous_transition(StringView time_zone, Crypto::SignedBigInteger const& epoch_nanoseconds);
@@ -36,8 +32,8 @@ ThrowCompletionOr<Crypto::SignedBigInteger> disambiguate_possible_epoch_nanoseco
3632
ThrowCompletionOr<Vector<Crypto::SignedBigInteger>> get_possible_epoch_nanoseconds(VM&, StringView time_zone, ISODateTime const&);
3733
ThrowCompletionOr<Crypto::SignedBigInteger> get_start_of_day(VM&, StringView time_zone, ISODate);
3834
bool time_zone_equals(StringView one, StringView two);
39-
ThrowCompletionOr<TimeZone> parse_time_zone_identifier(VM&, StringView identifier);
40-
TimeZone parse_time_zone_identifier(StringView identifier);
41-
TimeZone parse_time_zone_identifier(ParseResult const&);
35+
ThrowCompletionOr<ParsedTimeZoneIdentifier> parse_time_zone_identifier(VM&, StringView identifier);
36+
ParsedTimeZoneIdentifier parse_time_zone_identifier(StringView identifier);
37+
ParsedTimeZoneIdentifier parse_time_zone_identifier(ParseResult const&);
4238

4339
}

0 commit comments

Comments
 (0)