| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-07-27 00:21:16 +01:00
										 |  |  |  * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-17 21:02:51 +02:00
										 |  |  | #include <LibJS/Runtime/Completion.h>
 | 
					
						
							|  |  |  | #include <LibJS/Runtime/Object.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Temporal { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 00:29:26 +03:00
										 |  |  | class PlainDate final : public Object { | 
					
						
							|  |  |  |     JS_OBJECT(PlainDate, Object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-07-26 16:48:47 +03:00
										 |  |  |     PlainDate(i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, Object& prototype); | 
					
						
							| 
									
										
										
										
											2021-07-19 00:29:26 +03:00
										 |  |  |     virtual ~PlainDate() override = default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] i32 iso_year() const { return m_iso_year; } | 
					
						
							| 
									
										
										
										
											2021-07-26 16:48:47 +03:00
										 |  |  |     [[nodiscard]] u8 iso_month() const { return m_iso_month; } | 
					
						
							|  |  |  |     [[nodiscard]] u8 iso_day() const { return m_iso_day; } | 
					
						
							| 
									
										
										
										
											2021-07-19 00:29:26 +03:00
										 |  |  |     [[nodiscard]] Object const& calendar() const { return m_calendar; } | 
					
						
							|  |  |  |     [[nodiscard]] Object& calendar() { return m_calendar; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     virtual void visit_edges(Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 3.4 Properties of Temporal.PlainDate Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-plaindate-instances
 | 
					
						
							| 
									
										
										
										
											2021-07-26 16:48:47 +03:00
										 |  |  |     i32 m_iso_year { 0 }; // [[ISOYear]]
 | 
					
						
							|  |  |  |     u8 m_iso_month { 1 }; // [[ISOMonth]]
 | 
					
						
							|  |  |  |     u8 m_iso_day { 1 };   // [[ISODay]]
 | 
					
						
							|  |  |  |     Object& m_calendar;   // [[Calendar]]
 | 
					
						
							| 
									
										
										
										
											2021-07-19 00:29:26 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-27 00:21:16 +01:00
										 |  |  | struct ISODate { | 
					
						
							|  |  |  |     i32 year; | 
					
						
							|  |  |  |     u8 month; | 
					
						
							|  |  |  |     u8 day; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-17 21:02:51 +02:00
										 |  |  | ThrowCompletionOr<PlainDate*> create_temporal_date(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target = nullptr); | 
					
						
							|  |  |  | ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject&, Value item, Object* options = nullptr); | 
					
						
							|  |  |  | ThrowCompletionOr<ISODate> regulate_iso_date(GlobalObject&, double year, double month, double day, StringView overflow); | 
					
						
							| 
									
										
										
										
											2021-07-26 16:48:47 +03:00
										 |  |  | bool is_valid_iso_date(i32 year, u8 month, u8 day); | 
					
						
							| 
									
										
										
										
											2021-08-16 00:35:05 +01:00
										 |  |  | ISODate balance_iso_date(double year, double month, double day); | 
					
						
							| 
									
										
										
										
											2021-08-18 21:15:04 +01:00
										 |  |  | String pad_iso_year(i32 y); | 
					
						
							| 
									
										
										
										
											2021-09-17 21:02:51 +02:00
										 |  |  | ThrowCompletionOr<String> temporal_date_to_string(GlobalObject&, PlainDate&, StringView show_calendar); | 
					
						
							|  |  |  | ThrowCompletionOr<ISODate> add_iso_date(GlobalObject&, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow); | 
					
						
							| 
									
										
										
										
											2021-07-26 17:00:42 +03:00
										 |  |  | i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2); | 
					
						
							| 
									
										
										
										
											2021-07-11 21:04:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |