| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> | 
					
						
							|  |  |  |  * Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Optional.h>
 | 
					
						
							|  |  |  | #include <AK/StringView.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  | #include <AK/Vector.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Temporal { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  | struct Annotation { | 
					
						
							|  |  |  |     bool critical { false }; | 
					
						
							|  |  |  |     StringView key; | 
					
						
							|  |  |  |     StringView value; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct TimeZoneOffset { | 
					
						
							|  |  |  |     Optional<char> sign; | 
					
						
							|  |  |  |     Optional<StringView> hours; | 
					
						
							|  |  |  |     Optional<StringView> minutes; | 
					
						
							|  |  |  |     Optional<StringView> seconds; | 
					
						
							|  |  |  |     Optional<StringView> fraction; | 
					
						
							|  |  |  |     StringView source_text; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  | struct ParseResult { | 
					
						
							|  |  |  |     Optional<char> sign; | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Optional<StringView> date_year; | 
					
						
							|  |  |  |     Optional<StringView> date_month; | 
					
						
							|  |  |  |     Optional<StringView> date_day; | 
					
						
							|  |  |  |     Optional<StringView> time_hour; | 
					
						
							|  |  |  |     Optional<StringView> time_minute; | 
					
						
							|  |  |  |     Optional<StringView> time_second; | 
					
						
							|  |  |  |     Optional<StringView> time_fraction; | 
					
						
							|  |  |  |     Optional<TimeZoneOffset> date_time_offset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Optional<StringView> utc_designator; | 
					
						
							|  |  |  |     Optional<StringView> time_zone_identifier; | 
					
						
							|  |  |  |     Optional<StringView> time_zone_iana_name; | 
					
						
							|  |  |  |     Optional<TimeZoneOffset> time_zone_offset; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  |     Optional<StringView> duration_years; | 
					
						
							|  |  |  |     Optional<StringView> duration_months; | 
					
						
							|  |  |  |     Optional<StringView> duration_weeks; | 
					
						
							|  |  |  |     Optional<StringView> duration_days; | 
					
						
							|  |  |  |     Optional<StringView> duration_hours; | 
					
						
							|  |  |  |     Optional<StringView> duration_hours_fraction; | 
					
						
							|  |  |  |     Optional<StringView> duration_minutes; | 
					
						
							|  |  |  |     Optional<StringView> duration_minutes_fraction; | 
					
						
							|  |  |  |     Optional<StringView> duration_seconds; | 
					
						
							|  |  |  |     Optional<StringView> duration_seconds_fraction; | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Vector<Annotation> annotations; | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum class Production { | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  |     AnnotationValue, | 
					
						
							|  |  |  |     DateMonth, | 
					
						
							|  |  |  |     TemporalDateTimeString, | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  |     TemporalDurationString, | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  |     TemporalInstantString, | 
					
						
							|  |  |  |     TemporalMonthDayString, | 
					
						
							|  |  |  |     TemporalTimeString, | 
					
						
							|  |  |  |     TemporalYearMonthString, | 
					
						
							|  |  |  |     TemporalZonedDateTimeString, | 
					
						
							|  |  |  |     TimeZoneIdentifier, | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-28 21:39:13 -07:00
										 |  |  | JS_API Optional<ParseResult> parse_iso8601(Production, StringView); | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  | enum class SubMinutePrecision { | 
					
						
							|  |  |  |     No, | 
					
						
							|  |  |  |     Yes, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-28 21:39:13 -07:00
										 |  |  | JS_API Optional<TimeZoneOffset> parse_utc_offset(StringView, SubMinutePrecision); | 
					
						
							| 
									
										
										
										
											2024-11-19 15:15:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-18 11:58:51 -05:00
										 |  |  | } |