mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
LibJS: Implement parsing of TemporalMonthDayString
This commit is contained in:
parent
453c78215c
commit
3ddab2f4fe
5 changed files with 61 additions and 7 deletions
|
@ -1290,23 +1290,30 @@ ThrowCompletionOr<TemporalDuration> parse_temporal_duration_string(GlobalObject&
|
|||
}
|
||||
|
||||
// 13.41 ParseTemporalMonthDayString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporalmonthdaystring
|
||||
ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(GlobalObject& global_object, [[maybe_unused]] String const& iso_string)
|
||||
ThrowCompletionOr<TemporalMonthDay> parse_temporal_month_day_string(GlobalObject& global_object, String const& iso_string)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: Type(isoString) is String.
|
||||
|
||||
// 2. If isoString does not satisfy the syntax of a TemporalMonthDayString (see 13.33), then
|
||||
// a. Throw a RangeError exception.
|
||||
// TODO
|
||||
auto parse_result = parse_iso8601(Production::TemporalMonthDayString, iso_string);
|
||||
if (!parse_result.has_value()) {
|
||||
// a. Throw a RangeError exception.
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidMonthDayString, iso_string);
|
||||
}
|
||||
|
||||
// 3. Let result be ? ParseISODateTime(isoString).
|
||||
auto result = TRY(parse_iso_date_time(global_object, {}));
|
||||
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
|
||||
|
||||
// 4. Let year be result.[[Year]].
|
||||
Optional<i32> year = result.year;
|
||||
|
||||
// 5. If no part of isoString is produced by the DateYear production, then
|
||||
// a. Set year to undefined.
|
||||
// TODO (this is the case when TemporalMonthDayString is a DateSpecMonthDay)
|
||||
if (!parse_result->date_year.has_value()) {
|
||||
// a. Set year to undefined.
|
||||
year = {};
|
||||
}
|
||||
|
||||
// 6. Return the Record { [[Year]]: year, [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[Calendar]]: result.[[Calendar]] }.
|
||||
return TemporalMonthDay { .year = year, .month = result.month, .day = result.day, .calendar = move(result.calendar) };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue