mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibJS: Implement parsing of TemporalDateTimeString
This commit is contained in:
parent
02e7de2cba
commit
b42b7d5f16
Notes:
sideshowbarker
2024-07-18 00:56:34 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/b42b7d5f16e Pull-request: https://github.com/SerenityOS/serenity/pull/10971 Reviewed-by: https://github.com/IdanHo ✅ Reviewed-by: https://github.com/alimpfard
@ -208,6 +208,7 @@
|
||||
M(TemporalInvalidCalendarFunctionResult, "Invalid calendar, {}() function returned {}") \
|
||||
M(TemporalInvalidCalendarIdentifier, "Invalid calendar identifier '{}'") \
|
||||
M(TemporalInvalidDateString, "Invalid date string '{}'") \
|
||||
M(TemporalInvalidDateTimeString, "Invalid date time string '{}'") \
|
||||
M(TemporalInvalidDuration, "Invalid duration") \
|
||||
M(TemporalInvalidDurationLikeObject, "Invalid duration-like object") \
|
||||
M(TemporalInvalidDurationPropertyValueNonIntegral, "Invalid value for duration property '{}': must be an integer, got {}") \
|
||||
|
@ -1261,16 +1261,21 @@ ThrowCompletionOr<TemporalDate> parse_temporal_date_string(GlobalObject& global_
|
||||
}
|
||||
|
||||
// 13.39 ParseTemporalDateTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatetimestring
|
||||
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_string(GlobalObject& global_object, [[maybe_unused]] String const& iso_string)
|
||||
ThrowCompletionOr<ISODateTime> parse_temporal_date_time_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 TemporalDateTimeString (see 13.33), then
|
||||
// a. Throw a RangeError exception.
|
||||
// TODO
|
||||
auto parse_result = parse_iso8601(Production::TemporalDateTimeString, iso_string);
|
||||
if (!parse_result.has_value()) {
|
||||
// a. Throw a RangeError exception.
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDateTimeString, 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. Return result.
|
||||
return result;
|
||||
|
@ -467,10 +467,19 @@ bool ISO8601Parser::parse_temporal_date_string()
|
||||
return parse_calendar_date_time();
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-temporal/#prod-TemporalDateTimeString
|
||||
bool ISO8601Parser::parse_temporal_date_time_string()
|
||||
{
|
||||
// TemporalDateTimeString :
|
||||
// CalendarDateTime
|
||||
return parse_calendar_date_time();
|
||||
}
|
||||
|
||||
#define JS_ENUMERATE_ISO8601_PRODUCTION_PARSERS \
|
||||
__JS_ENUMERATE(TemporalDateString, parse_temporal_date_string)
|
||||
}
|
||||
|
||||
#define JS_ENUMERATE_ISO8601_PRODUCTION_PARSERS \
|
||||
__JS_ENUMERATE(TemporalDateString, parse_temporal_date_string) \
|
||||
__JS_ENUMERATE(TemporalDateTimeString, parse_temporal_date_time_string)
|
||||
|
||||
Optional<ParseResult> parse_iso8601(Production production, StringView input)
|
||||
{
|
||||
|
@ -77,6 +77,7 @@ public:
|
||||
[[nodiscard]] bool parse_date_time();
|
||||
[[nodiscard]] bool parse_calendar_date_time();
|
||||
[[nodiscard]] bool parse_temporal_date_string();
|
||||
[[nodiscard]] bool parse_temporal_date_time_string();
|
||||
|
||||
private:
|
||||
struct State {
|
||||
|
@ -98,7 +98,7 @@ describe("correct behavior", () => {
|
||||
);
|
||||
});
|
||||
|
||||
// FIXME: Enable when time string parsing is implemented.
|
||||
// FIXME: This currently yields an incorrect result (epochNanoseconds = 1635984000000000000)
|
||||
test.skip("from plain time string", () => {
|
||||
const plainDateTime = new Temporal.PlainDateTime(2021, 11, 4, 21, 16, 56, 100, 200, 300);
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
|
Loading…
Reference in New Issue
Block a user