2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								 *  Copyright  ( c )  2021 ,  Idan  Horowitz  < idan . horowitz @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								 *  Copyright  ( c )  2021 - 2023 ,  Linus  Groh  < linusg @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-23 13:41:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <AK/TypeCasts.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/AbstractOperations.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Array.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Completion.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/GlobalObject.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/AbstractOperations.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/Calendar.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/CalendarConstructor.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/Duration.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/ISO8601.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/PlainDate.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:35:36 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/PlainDateTime.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-15 00:41:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/PlainMonthDay.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-28 19:11:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/PlainTime.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:38:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/PlainYearMonth.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-01 16:07:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/TimeZone.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-01 17:54:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Temporal/ZonedDateTime.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								# include  <LibJS/Runtime/Value.h> 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								namespace  JS : : Temporal  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12 Temporal.Calendar Objects, https://tc39.es/proposal-temporal/#sec-temporal-calendar-objects
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:20:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								Calendar : : Calendar ( String  identifier ,  Object &  prototype ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-14 12:17:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    :  Object ( ConstructWithPrototypeTag : : Tag ,  prototype ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    ,  m_identifier ( move ( identifier ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.1.1 IsBuiltinCalendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal-isbuiltincalendar
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:48:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								bool  is_builtin_calendar ( StringView  identifier ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let calendars be AvailableCalendars().
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  calendars  =  available_calendars ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-24 23:20:44 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If calendars contains the ASCII-lowercase of id, return true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    for  ( auto  calendar  :  calendars )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( calendar . equals_ignoring_case ( identifier ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Return false.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.1.2 AvailableCalendars ( ), https://tc39.es/proposal-temporal/#sec-temporal-availablecalendars
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								Span < StringView  const >  available_calendars ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:07:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let calendars be the List of String values representing calendar types supported by the implementation.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: This can be removed in favor of using `Unicode::get_available_calendars()` once everything is updated to handle non-iso8601 calendars.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    static  constexpr  AK : : Array  calendars  {  " iso8601 " sv  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Assert: calendars contains "iso8601".
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Assert: calendars does not contain any element that does not identify a calendar type in the Unicode Common Locale Data Repository (CLDR).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Sort calendars in order as if an Array of the same values had been sorted using %Array.prototype.sort% with undefined as comparefn.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Return calendars.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  calendars . span ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.1 CreateTemporalCalendar ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalcalendar
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:20:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Calendar * >  create_temporal_calendar ( VM &  vm ,  String  const &  identifier ,  FunctionObject  const *  new_target ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto &  realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: IsBuiltinCalendar(identifier) is true.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( is_builtin_calendar ( identifier ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If newTarget is not provided, set newTarget to %Temporal.Calendar%.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! new_target ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-27 00:54:55 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        new_target  =  realm . intrinsics ( ) . temporal_calendar_constructor ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-24 23:20:44 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Set object.[[Identifier]] to the ASCII-lowercase of identifier.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:20:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  object  =  TRY ( ordinary_create_from_constructor < Calendar > ( vm ,  * new_target ,  & Intrinsics : : temporal_calendar_prototype ,  TRY_OR_THROW_OOM ( vm ,  identifier . to_lowercase ( ) ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Return object.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-14 18:34:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  object . ptr ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-14 21:01:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.2 GetBuiltinCalendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal-getbuiltincalendar
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:22:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Calendar * >  get_builtin_calendar ( VM &  vm ,  String  const &  identifier ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If IsBuiltinCalendar(id) is false, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! is_builtin_calendar ( identifier ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarIdentifier ,  identifier ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-10 19:51:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ! CreateTemporalCalendar(id).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:22:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  MUST_OR_THROW_OOM ( create_temporal_calendar ( vm ,  identifier ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.3 GetISO8601Calendar ( ), https://tc39.es/proposal-temporal/#sec-temporal-getiso8601calendar
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								Calendar *  get_iso8601_calendar ( VM &  vm ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-28 23:48:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Return ! GetBuiltinCalendar("iso8601").
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:22:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  MUST ( get_builtin_calendar ( vm ,  String : : from_utf8 ( " iso8601 " sv ) . release_value_but_fixme_should_propagate_errors ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.4 CalendarFields ( calendar, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarfields
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Vector < String > >  calendar_fields ( VM &  vm ,  Object &  calendar ,  Vector < StringView >  const &  field_names ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto &  realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let fields be ? GetMethod(calendar, "fields").
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  fields  =  TRY ( Value ( & calendar ) . get_method ( vm ,  vm . names . fields ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-19 22:41:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If fields is undefined, return fieldNames.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! fields )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        Vector < String >  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        TRY_OR_THROW_OOM ( vm ,  result . try_ensure_capacity ( field_names . size ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-19 22:41:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        for  ( auto &  value  :  field_names ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            result . unchecked_append ( TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( value ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-19 22:41:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-19 22:41:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let fieldsArray be ? Call(fields, calendar, « CreateArrayFromList(fieldNames) »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:17:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  fields_array  =  TRY ( call ( vm ,  * fields ,  & calendar ,  Array : : create_from < StringView > ( realm ,  field_names ,  [ & ] ( auto  value )  {  return  PrimitiveString : : create ( vm ,  value ) ;  } ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-19 22:41:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return ? IterableToListOfType(fieldsArray, « String »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  list  =  TRY ( iterable_to_list_of_type ( vm ,  fields_array ,  {  OptionType : : String  } ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    Vector < String >  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    TRY_OR_THROW_OOM ( vm ,  result . try_ensure_capacity ( list . size ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    for  ( auto &  value  :  list ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        result . unchecked_append ( TRY ( value . as_string ( ) . utf8_string ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.5 CalendarMergeFields ( calendar, fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmergefields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Object * >  calendar_merge_fields ( VM &  vm ,  Object &  calendar ,  Object &  fields ,  Object &  additional_fields ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-10 21:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let mergeFields be ? GetMethod(calendar, "mergeFields").
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  merge_fields  =  TRY ( Value ( & calendar ) . get_method ( vm ,  vm . names . mergeFields ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-10 21:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If mergeFields is undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! merge_fields )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-09 19:45:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. Return ? DefaultMergeCalendarFields(fields, additionalFields).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  TRY ( default_merge_calendar_fields ( vm ,  fields ,  additional_fields ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-10 21:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let result be ? Call(mergeFields, calendar, « fields, additionalFields »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 19:24:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( call ( vm ,  merge_fields ,  & calendar ,  & fields ,  & additional_fields ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-10 21:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. If Type(result) is not Object, throw a TypeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! result . is_object ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < TypeError > ( ErrorType : : NotAnObject ,  result . to_string_without_side_effects ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-10 21:30:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Return result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  & result . as_object ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.6 CalendarDateAdd ( calendar, date, duration [ , options [ , dateAdd ] ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateadd
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < PlainDate * >  calendar_date_add ( VM &  vm ,  Object &  calendar ,  Value  date ,  Duration &  duration ,  Object *  options ,  FunctionObject *  date_add ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-06 17:38:51 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: `date` is a `Value` because we sometimes need to pass a PlainDate, sometimes a PlainDateTime, and sometimes undefined.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: Type(calendar) is Object.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-06 23:56:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If options is not present, set options to undefined.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Assert: Type(options) is Object or Undefined.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-06 23:56:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. If dateAdd is not present, set dateAdd to ? GetMethod(calendar, "dateAdd").
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! date_add ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        date_add  =  TRY ( Value ( & calendar ) . get_method ( vm ,  vm . names . dateAdd ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-06 23:56:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Let addedDate be ? Call(dateAdd, calendar, « date, duration, options »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 19:24:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  added_date  =  TRY ( call ( vm ,  date_add  ? :  js_undefined ( ) ,  & calendar ,  date ,  & duration ,  options  ? :  js_undefined ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-06 23:56:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. Perform ? RequireInternalSlot(addedDate, [[InitializedTemporalDate]]).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  added_date_object  =  TRY ( added_date . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! is < PlainDate > ( added_date_object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < TypeError > ( ErrorType : : NotAnObjectOfType ,  " Temporal.PlainDate " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-06 23:56:57 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 7. Return addedDate.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-01 14:20:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  static_cast < PlainDate * > ( added_date_object ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.7 CalendarDateUntil ( calendar, one, two, options [ , dateUntil ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateuntil
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Duration * >  calendar_date_until ( VM &  vm ,  Object &  calendar ,  Value  one ,  Value  two ,  Object &  options ,  FunctionObject *  date_until ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-02 00:14:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: Type(calendar) is Object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If dateUntil is not present, set dateUntil to ? GetMethod(calendar, "dateUntil").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! date_until ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        date_until  =  TRY ( Value ( & calendar ) . get_method ( vm ,  vm . names . dateUntil ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-02 00:14:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let duration be ? Call(dateUntil, calendar, « one, two, options »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 19:24:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  duration  =  TRY ( call ( vm ,  date_until  ? :  js_undefined ( ) ,  & calendar ,  one ,  two ,  & options ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-02 00:14:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  duration_object  =  TRY ( duration . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-02 00:14:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! is < Duration > ( duration_object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < TypeError > ( ErrorType : : NotAnObjectOfType ,  " Temporal.Duration " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-02 00:14:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Return duration.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  static_cast < Duration * > ( duration_object ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.8 CalendarYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryear
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_year ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:39:58 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "year", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . year ,  & date_like ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:39:58 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If result is undefined, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . year . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:39:58 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-06 03:31:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Return ? ToIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_integer_with_truncation ( vm ,  result ,  ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . year . as_string ( ) ,  vm . names . Infinity . as_string ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:39:58 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.9 CalendarMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonth
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_month ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:48:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "month", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . month ,  & date_like ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:48:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-05 19:20:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . month . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:48:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:48:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.10 CalendarMonthCode ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthcode
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:23:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < String >  calendar_month_code ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:58:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "monthCode", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . monthCode ,  & date_like ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:58:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If result is undefined, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . monthCode . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:58:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Return ? ToString(result).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:23:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  result . to_string ( vm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 16:58:48 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.11 CalendarDay ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarday
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_day ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 17:08:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "day", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . day ,  & date_like ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 17:08:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-05 19:20:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . day . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 17:08:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 17:08:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.12 CalendarDayOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofweek
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-05 03:32:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_day_of_week ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 17:50:35 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "dayOfWeek", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . dayOfWeek ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . dayOfWeek . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 17:50:35 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.13 CalendarDayOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardayofyear
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-05 03:32:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_day_of_year ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:00:12 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "dayOfYear", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . dayOfYear ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . dayOfYear . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:00:12 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.14 CalendarWeekOfYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarweekofyear
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-05 03:32:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_week_of_year ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:21:47 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "weekOfYear", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . weekOfYear ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . weekOfYear . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:21:47 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.15 CalendarYearOfWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearofweek
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-05 03:32:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_year_of_week ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "yearOfWeek", « dateLike »).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . yearOfWeek ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If result is undefined, throw a RangeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . yearOfWeek . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Return ? ToIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-06 03:31:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_integer_with_truncation ( vm ,  result ,  ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . yearOfWeek . as_string ( ) ,  vm . names . Infinity . to_string ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.16 CalendarDaysInWeek ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinweek
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-05 03:32:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_days_in_week ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:30:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "daysInWeek", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . daysInWeek ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . daysInWeek . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:30:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.17 CalendarDaysInMonth ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinmonth
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-30 05:05:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_days_in_month ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:38:28 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "daysInMonth", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . daysInMonth ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . daysInMonth . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:38:28 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.18 CalendarDaysInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendardaysinyear
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-05 03:32:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_days_in_year ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:48:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "daysInYear", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . daysInYear ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . daysInYear . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:48:07 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.19 CalendarMonthsInYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthsinyear
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-05 03:32:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  calendar_months_in_year ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:54:16 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "monthsInYear", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . monthsInYear ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // NOTE: Explicitly handled for a better error message similar to the other calendar property AOs
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( result . is_undefined ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . monthsInYear . as_string ( ) ,  vm . names . undefined . as_string ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 03:17:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToPositiveIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY ( to_positive_integer_with_truncation ( vm ,  result ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:54:16 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.20 CalendarInLeapYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarinleapyear
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Value >  calendar_in_leap_year ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 19:04:43 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let result be ? Invoke(calendar, "inLeapYear", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . inLeapYear ,  & date_like ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-31 02:26:23 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ToBoolean(result).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 09:49:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  result . to_boolean ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 19:04:43 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 15.6.1.1 CalendarEra ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarera
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Value >  calendar_era ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-27 20:03:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: Type(calendar) is Object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let result be ? Invoke(calendar, "era", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . era ,  & date_like ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-27 20:03:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. If result is not undefined, set result to ? ToString(result).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-12 17:49:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! result . is_undefined ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-28 22:54:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        result  =  PrimitiveString : : create ( vm ,  TRY ( result . to_string ( vm ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-27 20:03:41 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:42:56 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 15.6.1.2 CalendarEraYear ( calendar, dateLike ), https://tc39.es/proposal-temporal/#sec-temporal-calendarerayear
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Value >  calendar_era_year ( VM &  vm ,  Object &  calendar ,  Object &  date_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-27 20:09:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: Type(calendar) is Object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let result be ? Invoke(calendar, "eraYear", « dateLike »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . eraYear ,  & date_like ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-27 20:09:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-06 03:31:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. If result is not undefined, set result to ? ToIntegerWithTruncation(result).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-15 23:03:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! result . is_undefined ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-06 03:31:29 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        result  =  Value ( TRY ( to_integer_with_truncation ( vm ,  result ,  ErrorType : : TemporalInvalidCalendarFunctionResult ,  vm . names . eraYear . as_string ( ) ,  " Infinity " sv ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-27 20:09:15 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return result.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.21 ToTemporalCalendar ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Object * >  to_temporal_calendar ( VM &  vm ,  Value  temporal_calendar_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If Type(temporalCalendarLike) is Object, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( temporal_calendar_like . is_object ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto &  temporal_calendar_like_object  =  temporal_calendar_like . as_object ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 00:01:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. If temporalCalendarLike has an [[InitializedTemporalCalendar]] internal slot, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < Calendar > ( temporal_calendar_like_object ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Return temporalCalendarLike.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & temporal_calendar_like_object ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // b. If temporalCalendarLike has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalTime]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-25 19:41:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // i. Return temporalCalendarLike.[[Calendar]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < PlainDate > ( temporal_calendar_like_object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & static_cast < PlainDate & > ( temporal_calendar_like_object ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-25 19:41:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < PlainDateTime > ( temporal_calendar_like_object ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & static_cast < PlainDateTime & > ( temporal_calendar_like_object ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-15 00:41:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < PlainMonthDay > ( temporal_calendar_like_object ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & static_cast < PlainMonthDay & > ( temporal_calendar_like_object ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-28 19:11:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < PlainTime > ( temporal_calendar_like_object ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & static_cast < PlainTime & > ( temporal_calendar_like_object ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:38:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < PlainYearMonth > ( temporal_calendar_like_object ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & static_cast < PlainYearMonth & > ( temporal_calendar_like_object ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-01 17:54:28 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < ZonedDateTime > ( temporal_calendar_like_object ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & static_cast < ZonedDateTime & > ( temporal_calendar_like_object ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-01 16:07:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // c. If temporalCalendarLike has an [[InitializedTemporalTimeZone]] internal slot, throw a RangeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( is < TimeZone > ( temporal_calendar_like_object ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  vm . throw_completion < RangeError > ( ErrorType : : TemporalUnexpectedTimeZoneObject ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // d. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-03 02:00:39 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( ! TRY ( temporal_calendar_like_object . has_property ( vm . names . calendar ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  & temporal_calendar_like_object ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-01 16:07:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // e. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-02 23:52:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        temporal_calendar_like  =  TRY ( temporal_calendar_like_object . get ( vm . names . calendar ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-01 16:07:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // f. If Type(temporalCalendarLike) is Object, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( temporal_calendar_like . is_object ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. If temporalCalendarLike has an [[InitializedTemporalTimeZone]] internal slot, throw a RangeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            if  ( is < TimeZone > ( temporal_calendar_like . as_object ( ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								                return  vm . throw_completion < RangeError > ( ErrorType : : TemporalUnexpectedTimeZoneObject ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // ii. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            if  ( ! TRY ( temporal_calendar_like . as_object ( ) . has_property ( vm . names . calendar ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								                return  & temporal_calendar_like . as_object ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let identifier be ? ToString(temporalCalendarLike).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:48:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  identifier  =  TRY ( temporal_calendar_like . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-30 17:43:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Set identifier to ? ParseTemporalCalendarString(identifier).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    identifier  =  TRY ( parse_temporal_calendar_string ( vm ,  identifier ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. If IsBuiltinCalendar(identifier) is false, throw a RangeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! is_builtin_calendar ( identifier ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendarIdentifier ,  identifier ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-30 17:43:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Return ! CreateTemporalCalendar(identifier).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:20:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  MUST_OR_THROW_OOM ( create_temporal_calendar ( vm ,  identifier ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Object * >  to_temporal_calendar_with_iso_default ( VM &  vm ,  Value  temporal_calendar_like ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If temporalCalendarLike is undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( temporal_calendar_like . is_undefined ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-28 23:48:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. Return ! GetISO8601Calendar().
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  get_iso8601_calendar ( vm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return ? ToTemporalCalendar(temporalCalendarLike).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  to_temporal_calendar ( vm ,  temporal_calendar_like ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-19 00:29:26 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.23 GetTemporalCalendarWithISODefault ( item ), https://tc39.es/proposal-temporal/#sec-temporal-gettemporalcalendarwithisodefault
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Object * >  get_temporal_calendar_with_iso_default ( VM &  vm ,  Object &  item ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If item has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalTime]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-25 19:42:14 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // a. Return item.[[Calendar]].
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( is < PlainDate > ( item ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & static_cast < PlainDate & > ( item ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-25 19:42:14 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( is < PlainDateTime > ( item ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & static_cast < PlainDateTime & > ( item ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-15 00:42:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( is < PlainMonthDay > ( item ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & static_cast < PlainMonthDay & > ( item ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-28 19:12:24 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( is < PlainTime > ( item ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & static_cast < PlainTime & > ( item ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-07 23:38:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( is < PlainYearMonth > ( item ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & static_cast < PlainYearMonth & > ( item ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-01 17:55:06 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( is < ZonedDateTime > ( item ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & static_cast < ZonedDateTime & > ( item ) . calendar ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-04 19:29:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let calendarLike be ? Get(item, "calendar").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  calendar_like  =  TRY ( item . get ( vm . names . calendar ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-04 19:29:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Return ? ToTemporalCalendarWithISODefault(calendarLike).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  to_temporal_calendar_with_iso_default ( vm ,  calendar_like ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.24 CalendarDateFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardatefromfields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < PlainDate * >  calendar_date_from_fields ( VM &  vm ,  Object &  calendar ,  Object  const &  fields ,  Object  const *  options ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If options is not present, set options to undefined.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let date be ? Invoke(calendar, "dateFromFields", « fields, options »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  date  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . dateFromFields ,  & fields ,  options  ? :  js_undefined ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Perform ? RequireInternalSlot(date, [[InitializedTemporalDate]]).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  date_object  =  TRY ( date . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! is < PlainDate > ( date_object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < TypeError > ( ErrorType : : NotAnObjectOfType ,  " Temporal.PlainDate " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return date.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:20:57 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  static_cast < PlainDate * > ( date_object ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.25 CalendarYearMonthFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearmonthfromfields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < PlainYearMonth * >  calendar_year_month_from_fields ( VM &  vm ,  Object &  calendar ,  Object  const &  fields ,  Object  const *  options ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If options is not present, set options to undefined.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let yearMonth be ? Invoke(calendar, "yearMonthFromFields", « fields, options »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  year_month  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . yearMonthFromFields ,  & fields ,  options  ? :  js_undefined ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  year_month_object  =  TRY ( year_month . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! is < PlainYearMonth > ( year_month_object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < TypeError > ( ErrorType : : NotAnObjectOfType ,  " Temporal.PlainYearMonth " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return yearMonth.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  static_cast < PlainYearMonth * > ( year_month_object ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.26 CalendarMonthDayFromFields ( calendar, fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthdayfromfields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < PlainMonthDay * >  calendar_month_day_from_fields ( VM &  vm ,  Object &  calendar ,  Object  const &  fields ,  Object  const *  options ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:13:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If options is not present, set options to undefined.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:13:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let monthDay be ? Invoke(calendar, "monthDayFromFields", « fields, options »).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_day  =  TRY ( Value ( & calendar ) . invoke ( vm ,  vm . names . monthDayFromFields ,  & fields ,  options  ? :  js_undefined ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:13:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  month_day_object  =  TRY ( month_day . to_object ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! is < PlainMonthDay > ( month_day_object ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < TypeError > ( ErrorType : : NotAnObjectOfType ,  " Temporal.PlainMonthDay " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:13:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-29 18:34:16 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return monthDay.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:13:47 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  static_cast < PlainMonthDay * > ( month_day_object ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.27 MaybeFormatCalendarAnnotation ( calendarObject, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-maybeformatcalendarannotation
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:24:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < String >  maybe_format_calendar_annotation ( VM &  vm ,  Object  const *  calendar_object ,  StringView  show_calendar ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-08 14:48:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If showCalendar is "never", return the empty String.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( show_calendar  = =  " never " sv ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:24:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  String  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-08 14:48:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Assert: Type(calendarObject) is Object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( calendar_object ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-08 14:48:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let calendarID be ? ToString(calendarObject).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:24:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  calendar_id  =  TRY ( Value ( calendar_object ) . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return FormatCalendarAnnotation(calendarID, showCalendar).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:27:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  format_calendar_annotation ( vm ,  calendar_id ,  show_calendar ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-08 14:48:48 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.28 FormatCalendarAnnotation ( id, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-formatcalendarannotation
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:27:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < String >  format_calendar_annotation ( VM &  vm ,  StringView  id ,  StringView  show_calendar ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-18 21:15:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-02 19:24:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( show_calendar  = =  " auto " sv  | |  show_calendar  = =  " always " sv  | |  show_calendar  = =  " never " sv  | |  show_calendar  = =  " critical " sv ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-18 21:15:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-02 19:24:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If showCalendar is "never", return the empty String.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-18 21:15:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( show_calendar  = =  " never " sv ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:27:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  String  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-18 21:15:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-02 19:24:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If showCalendar is "auto" and id is "iso8601", return the empty String.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-18 21:15:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( show_calendar  = =  " auto " sv  & &  id  = =  " iso8601 " sv ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:27:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  String  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-18 21:15:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-02 19:24:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. If showCalendar is "critical", let flag be "!"; else, let flag be the empty String.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  flag  =  show_calendar  = =  " critical " sv  ?  " ! " sv  :  " " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Return the string-concatenation of "[", flag, "u-ca=", id, and "]".
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:27:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY_OR_THROW_OOM ( vm ,  String : : formatted ( " [{}u-ca={}] " ,  flag ,  id ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-18 21:15:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.29 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < bool >  calendar_equals ( VM &  vm ,  Object &  one ,  Object &  two ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:21:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If one and two are the same Object value, return true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( & one  = =  & two ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let calendarOne be ? ToString(one).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-28 22:54:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  calendar_one  =  TRY ( Value ( & one ) . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:21:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let calendarTwo be ? ToString(two).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-28 22:54:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  calendar_two  =  TRY ( Value ( & two ) . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:21:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. If calendarOne is calendarTwo, return true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( calendar_one  = =  calendar_two ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:21:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Return false.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.30 ConsolidateCalendars ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-consolidatecalendars
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Object * >  consolidate_calendars ( VM &  vm ,  Object &  one ,  Object &  two ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-31 01:39:36 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If one and two are the same Object value, return two.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( & one  = =  & two ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & two ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let calendarOne be ? ToString(one).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-28 22:54:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  calendar_one  =  TRY ( Value ( & one ) . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-31 01:39:36 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let calendarTwo be ? ToString(two).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-28 22:54:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  calendar_two  =  TRY ( Value ( & two ) . to_string ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-31 01:39:36 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. If calendarOne is calendarTwo, return two.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( calendar_one  = =  calendar_two ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & two ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. If calendarOne is "iso8601", return two.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( calendar_one  = =  " iso8601 " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & two ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. If calendarTwo is "iso8601", return one.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( calendar_two  = =  " iso8601 " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  & one ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 7. Throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidCalendar ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-31 01:39:36 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.31 ISODaysInMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-isodaysinmonth
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-26 16:48:47 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								u8  iso_days_in_month ( i32  year ,  u8  month ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-10 03:58:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. If month is 1, 3, 5, 7, 8, 10, or 12, return 31.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( month  = =  1  | |  month  = =  3  | |  month  = =  5  | |  month  = =  7  | |  month  = =  8  | |  month  = =  10  | |  month  = =  12 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  31 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-10 03:58:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. If month is 4, 6, 9, or 11, return 30.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( month  = =  4  | |  month  = =  6  | |  month  = =  9  | |  month  = =  11 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  30 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-10 03:58:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Assert: month is 2.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( month  = =  2 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 4. Return 28 + ℝ  (InLeapYear(TimeFromYear(𝔽  (year)))).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-07 00:03:19 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  28  +  JS : : in_leap_year ( time_from_year ( year ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.32 ToISOWeekOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisoweekofyear
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								YearWeekRecord  to_iso_week_of_year ( i32  year ,  u8  month ,  u8  day ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:19:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: IsValidISODate(year, month, day) is true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( is_valid_iso_date ( year ,  month ,  day ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let wednesday be 3.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    constexpr  auto  wednesday  =  3 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let thursday be 4.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    constexpr  auto  thursday  =  4 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Let friday be 5.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    constexpr  auto  friday  =  5 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Let saturday be 6.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    constexpr  auto  saturday  =  6 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. Let daysInWeek be 7.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    constexpr  auto  days_in_week  =  7 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 7. Let maxWeekNumber be 53.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    constexpr  auto  max_week_number  =  53 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 8. Let dayOfYear be ToISODayOfYear(year, month, day).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  day_of_year  =  to_iso_day_of_year ( year ,  month ,  day ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 9. Let dayOfWeek be ToISODayOfWeek(year, month, day).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  day_of_week  =  to_iso_day_of_week ( year ,  month ,  day ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:19:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 10. Let week be floor((dayOfYear + daysInWeek - dayOfWeek + wednesday ) / daysInWeek).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  week  =  static_cast < i32 > ( floor ( static_cast < double > ( day_of_year  +  days_in_week  -  day_of_week  +  wednesday )  /  days_in_week ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 11. If week < 1, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:19:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( week  <  1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. NOTE: This is the last week of the previous year.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // b. Let dayOfJan1st be ToISODayOfWeek(year, 1, 1).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  day_of_jan_1st  =  to_iso_day_of_week ( year ,  1 ,  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // c. If dayOfJan1st is friday, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( day_of_jan_1st  = =  friday )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Return the Year-Week Record { [[Week]]: maxWeekNumber, [[Year]]: year - 1 }.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  YearWeekRecord  {  . week  =  max_week_number ,  . year  =  year  -  1  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								        // d. If dayOfJan1st is saturday, and InLeapYear(TimeFromYear(𝔽  (year - 1))) is 1𝔽  , then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( day_of_jan_1st  = =  saturday  & &  in_leap_year ( time_from_year ( year  -  1 ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Return the Year-Week Record { [[Week]]: maxWeekNumber. [[Year]]: year - 1 }.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  YearWeekRecord  {  . week  =  max_week_number ,  . year  =  year  -  1  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // e. Return the Year-Week Record { [[Week]]: maxWeekNumber - 1, [[Year]]: year - 1 }.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  YearWeekRecord  {  . week  =  max_week_number  -  1 ,  . year  =  year  -  1  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 12. If week is maxWeekNumber, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( week  = =  max_week_number )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								        // a. Let daysInYear be DaysInYear(𝔽  (year)).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-06 23:59:27 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  days_in_year  =  JS : : days_in_year ( year ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // b. Let daysLaterInYear be daysInYear - dayOfYear.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  days_later_in_year  =  days_in_year  -  day_of_year ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // c. Let daysAfterThursday be thursday - dayOfWeek.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  days_after_thursday  =  thursday  -  day_of_week ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // d. If daysLaterInYear < daysAfterThursday, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( days_later_in_year  <  days_after_thursday )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Return the Year-Week Record { [[Week]]: 1, [[Year]]: year + 1 }.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  YearWeekRecord  {  . week  =  1 ,  . year  =  year  +  1  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:19:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 13. Return the Year-Week Record { [[Week]]: week, [[Year]]: year }.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  YearWeekRecord  {  . week  =  static_cast < u8 > ( week ) ,  . year  =  year  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 18:19:45 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.33 ISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:31:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < String >  iso_month_code ( VM &  vm ,  u8  month ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-12 22:20:33 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let numberPart be ToZeroPaddedDecimalString(month, 2).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Return the string-concatenation of "M" and numberPart.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:31:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  TRY_OR_THROW_OOM ( vm ,  String : : formatted ( " M{:02} " ,  month ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.34 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < double >  resolve_iso_month ( VM &  vm ,  Object  const &  fields ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: fields is an ordinary object with no more and no less than the own data properties listed in Table 13.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let month be ! Get(fields, "month").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month  =  MUST ( fields . get ( vm . names . month ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Assert: month is undefined or month is a Number.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( month . is_undefined ( )  | |  month . is_number ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Let monthCode be ! Get(fields, "monthCode").
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_code  =  MUST ( fields . get ( vm . names . monthCode ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. If monthCode is undefined, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( month_code . is_undefined ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. If month is undefined, throw a TypeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( month . is_undefined ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            return  vm . throw_completion < TypeError > ( ErrorType : : MissingRequiredProperty ,  vm . names . month . as_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								        // b. Return ℝ  (month).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  month . as_double ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. Assert: Type(monthCode) is String.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( month_code . is_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-13 15:33:31 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_code_string  =  TRY ( month_code . as_string ( ) . deprecated_string ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 7. If the length of monthCode is not 3, throw a RangeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_length  =  month_code_string . length ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( month_length  ! =  3 ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidMonthCode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 8. If the first code unit of monthCode is not 0x004D (LATIN CAPITAL LETTER M), throw a RangeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( month_code_string [ 0 ]  ! =  0x4D ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidMonthCode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:41:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 9. Let monthCodeDigits be the substring of monthCode from 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_code_digits  =  month_code_string . substring ( 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:41:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 10. If ParseText(StringToCodePoints(monthCodeDigits), DateMonth) is a List of errors, throw a RangeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  parse_result  =  parse_iso8601 ( Production : : DateMonth ,  month_code_digits ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! parse_result . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidMonthCode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:41:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 11. Let monthCodeNumber be ! ToIntegerOrInfinity(monthCodeDigits).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:17:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_code_number  =  MUST ( Value ( PrimitiveString : : create ( vm ,  move ( month_code_digits ) ) ) . to_integer_or_infinity ( vm ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:26:12 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 13:25:35 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 12. Assert: SameValue(monthCode, ISOMonthCode(monthCodeNumber)) is true.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 15:31:44 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( month_code_string . view ( )  = =  TRY ( iso_month_code ( vm ,  month_code_number ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:41:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 13. If month is not undefined and SameValue(month, monthCodeNumber) is false, throw a RangeError exception.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! month . is_undefined ( )  & &  month . as_double ( )  ! =  month_code_number ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < RangeError > ( ErrorType : : TemporalInvalidMonthCode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 21:42:01 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-16 12:41:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 14. Return monthCodeNumber.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  month_code_number ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.35 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < ISODateRecord >  iso_date_from_fields ( VM &  vm ,  Object  const &  fields ,  Object  const &  options ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: Type(fields) is Object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 16:10:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "year", "day" »).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  prepared_fields  =  TRY ( prepare_temporal_fields ( vm ,  fields , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        {  String : : from_utf8_short_string ( " day " sv ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " month " sv ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " monthCode " sv ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " year " sv ) )  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        Vector < StringView >  {  " year " sv ,  " day " sv  } ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 16:10:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let overflow be ? ToTemporalOverflow(options).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  overflow  =  TRY ( to_temporal_overflow ( vm ,  & options ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Let year be ! Get(fields, "year").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  year  =  MUST ( prepared_fields - > get ( vm . names . year ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Assert: Type(year) is Number.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( year . is_number ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. Let month be ? ResolveISOMonth(fields).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month  =  TRY ( resolve_iso_month ( vm ,  * prepared_fields ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 7. Let day be ! Get(fields, "day").
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  day  =  MUST ( prepared_fields - > get ( vm . names . day ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 8. Assert: Type(day) is Number.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( day . is_number ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 9. Return ? RegulateISODate(ℝ  (year), month, ℝ  (day), overflow).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  regulate_iso_date ( vm ,  year . as_double ( ) ,  month ,  day . as_double ( ) ,  overflow ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-21 22:17:40 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.36 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < ISOYearMonth >  iso_year_month_from_fields ( VM &  vm ,  Object  const &  fields ,  Object  const &  options ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:35:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: Type(fields) is Object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 16:10:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », « "year" »).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  prepared_fields  =  TRY ( prepare_temporal_fields ( vm ,  fields , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        {  TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " month " sv ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " monthCode " sv ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " year " sv ) )  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        Vector < StringView >  {  " year " sv  } ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:35:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 16:10:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let overflow be ? ToTemporalOverflow(options).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  overflow  =  TRY ( to_temporal_overflow ( vm ,  & options ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Let year be ! Get(fields, "year").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  year  =  MUST ( prepared_fields - > get ( vm . names . year ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:35:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Assert: Type(year) is Number.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( year . is_number ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. Let month be ? ResolveISOMonth(fields).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month  =  TRY ( resolve_iso_month ( vm ,  * prepared_fields ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:35:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 7. Let result be ? RegulateISOYearMonth(ℝ  (year), month, overflow).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  result  =  TRY ( regulate_iso_year_month ( vm ,  year . as_double ( ) ,  month ,  overflow ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:35:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 8. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[ReferenceISODay]]: 1 }.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-09-16 01:57:24 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  ISOYearMonth  {  . year  =  result . year ,  . month  =  result . month ,  . reference_iso_day  =  1  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 00:35:05 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.37 ISOMonthDayFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < ISOMonthDay >  iso_month_day_from_fields ( VM &  vm ,  Object  const &  fields ,  Object  const &  options ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: Type(fields) is Object.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 16:10:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-26 14:37:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto *  prepared_fields  =  TRY ( prepare_temporal_fields ( vm ,  fields , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        {  String : : from_utf8_short_string ( " day " sv ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " month " sv ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " monthCode " sv ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            TRY_OR_THROW_OOM ( vm ,  String : : from_utf8 ( " year " sv ) )  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        Vector < StringView >  {  " day " sv  } ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 16:10:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Let overflow be ? ToTemporalOverflow(options).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  overflow  =  TRY ( to_temporal_overflow ( vm ,  & options ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Let month be ! Get(fields, "month").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_value  =  MUST ( prepared_fields - > get ( vm . names . month ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. Let monthCode be ! Get(fields, "monthCode").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month_code  =  MUST ( prepared_fields - > get ( vm . names . monthCode ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. Let year be ! Get(fields, "year").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  year  =  MUST ( prepared_fields - > get ( vm . names . year ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 7. If month is not undefined, and monthCode and year are both undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! month_value . is_undefined ( )  & &  month_code . is_undefined ( )  & &  year . is_undefined ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. Throw a TypeError exception.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-16 20:33:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  vm . throw_completion < TypeError > ( ErrorType : : MissingRequiredProperty ,  " monthCode or year " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 8. Set month to ? ResolveISOMonth(fields).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  month  =  TRY ( resolve_iso_month ( vm ,  * prepared_fields ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-16 18:54:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 9. Let day be ! Get(fields, "day").
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  day  =  MUST ( prepared_fields - > get ( vm . names . day ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 10. Assert: Type(day) is Number.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( day . is_number ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 11. Let referenceISOYear be 1972 (the first leap year after the Unix epoch).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    i32  reference_iso_year  =  1972 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-16 20:46:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    Optional < ISODateRecord >  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 12. If monthCode is undefined, then
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( month_code . is_undefined ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. Assert: Type(year) is Number.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        VERIFY ( year . is_number ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								        // b. Let result be ? RegulateISODate(ℝ  (year), month, ℝ  (day), overflow).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        result  =  TRY ( regulate_iso_date ( vm ,  year . as_double ( ) ,  month ,  day . as_double ( ) ,  overflow ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 13. Else,
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 19:58:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								        // a. Let result be ? RegulateISODate(referenceISOYear, month, ℝ  (day), overflow).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        result  =  TRY ( regulate_iso_date ( vm ,  reference_iso_year ,  month ,  day . as_double ( ) ,  overflow ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:45:31 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 14. Return the Record { [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[ReferenceISOYear]]: referenceISOYear }.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 18:04:58 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  ISOMonthDay  {  . month  =  result - > month ,  . day  =  result - > day ,  . reference_iso_year  =  reference_iso_year  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.38 DefaultMergeCalendarFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergecalendarfields
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								ThrowCompletionOr < Object * >  default_merge_calendar_fields ( VM &  vm ,  Object  const &  fields ,  Object  const &  additional_fields ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-20 08:52:42 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto &  realm  =  * vm . current_realm ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-10 18:05:50 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Let merged be OrdinaryObjectCreate(%Object.prototype%).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-13 20:49:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  merged  =  Object : : create ( realm ,  realm . intrinsics ( ) . object_prototype ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 2. Let fieldsKeys be ? EnumerableOwnPropertyNames(fields, key).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  fields_keys  =  TRY ( fields . enumerable_own_property_names ( Object : : PropertyKind : : Key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. For each element key of fieldsKeys, do
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    for  ( auto &  key  :  fields_keys )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. If key is not "month" or "monthCode", then
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( ! TRY ( key . as_string ( ) . deprecated_string ( ) ) . is_one_of ( vm . names . month . as_string ( ) ,  vm . names . monthCode . as_string ( ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            auto  property_key  =  MUST ( PropertyKey : : from_value ( vm ,  key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Let propValue be ? Get(fields, key).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-06 15:59:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            auto  prop_value  =  TRY ( fields . get ( property_key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // ii. If propValue is not undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            if  ( ! prop_value . is_undefined ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								                // 1. Perform ! CreateDataPropertyOrThrow(merged, key, propValue).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-06 15:59:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								                MUST ( merged - > create_data_property_or_throw ( property_key ,  prop_value ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 4. Let additionalFieldsKeys be ? EnumerableOwnPropertyNames(additionalFields, key).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  additional_fields_keys  =  TRY ( additional_fields . enumerable_own_property_names ( Object : : PropertyKind : : Key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // IMPLEMENTATION DEFINED: This is an optimization, so we don't have to iterate new_keys three times (worst case), but only once.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    bool  additional_fields_keys_contains_month_or_month_code_property  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 5. For each element key of additionalFieldsKeys, do
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    for  ( auto &  key  :  additional_fields_keys )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-21 14:00:56 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  property_key  =  MUST ( PropertyKey : : from_value ( vm ,  key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. Let propValue be ? Get(additionalFields, key).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-06 15:59:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  prop_value  =  TRY ( additional_fields . get ( property_key ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // b. If propValue is not undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( ! prop_value . is_undefined ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Perform ! CreateDataPropertyOrThrow(merged, key, propValue).
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-06 15:59:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            MUST ( merged - > create_data_property_or_throw ( property_key ,  prop_value ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // See comment above.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 12:24:05 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        additional_fields_keys_contains_month_or_month_code_property  | =  TRY ( key . as_string ( ) . deprecated_string ( ) )  = =  vm . names . month . as_string ( )  | |  TRY ( key . as_string ( ) . deprecated_string ( ) )  = =  vm . names . monthCode . as_string ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-15 00:19:04 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 6. If additionalFieldsKeys does not contain either "month" or "monthCode", then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( ! additional_fields_keys_contains_month_or_month_code_property )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // a. Let month be ? Get(fields, "month").
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-02 23:52:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  month  =  TRY ( fields . get ( vm . names . month ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // b. If month is not undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( ! month . is_undefined ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Perform ! CreateDataPropertyOrThrow(merged, "month", month).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-03 01:18:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            MUST ( merged - > create_data_property_or_throw ( vm . names . month ,  month ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // c. Let monthCode be ? Get(fields, "monthCode").
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-02 23:52:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        auto  month_code  =  TRY ( fields . get ( vm . names . monthCode ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        // d. If monthCode is not undefined, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        if  ( ! month_code . is_undefined ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								            // i. Perform ! CreateDataPropertyOrThrow(merged, "monthCode", monthCode).
 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-03 01:18:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								            MUST ( merged - > create_data_property_or_throw ( vm . names . monthCode ,  month_code ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 7. Return merged.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-13 20:49:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  merged . ptr ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-16 22:23:52 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.39 ToISODayOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofyear
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								u16  to_iso_day_of_year ( i32  year ,  u8  month ,  u8  day ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: IsValidISODate(year, month, day) is true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( is_valid_iso_date ( year ,  month ,  day ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 2. Let epochDays be MakeDay(𝔽  (year), 𝔽  (month - 1), 𝔽  (day)).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  epoch_days  =  make_day ( year ,  month  -  1 ,  day ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Assert: epochDays is finite.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( isfinite ( epoch_days ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 4. Return ℝ  (DayWithinYear(MakeDate(epochDays, +0𝔽  ))) + 1.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  day_within_year ( make_date ( epoch_days ,  0 ) )  +  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-26 00:58:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								// 12.2.40 ToISODayOfWeek ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofweek
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 22:28:11 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
								
									
								 
							
							
								u8  to_iso_day_of_week ( i32  year ,  u8  month ,  u8  day ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 1. Assert: IsValidISODate(year, month, day) is true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( is_valid_iso_date ( year ,  month ,  day ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 2. Let epochDays be MakeDay(𝔽  (year), 𝔽  (month - 1), 𝔽  (day)).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  epoch_days  =  make_day ( year ,  month  -  1 ,  day ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    // 3. Assert: epochDays is finite.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    VERIFY ( isfinite ( epoch_days ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 4. Let dayOfWeek be WeekDay(MakeDate(epochDays, +0𝔽  )).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    auto  day_of_week  =  week_day ( make_date ( epoch_days ,  0 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 5. If dayOfWeek = +0𝔽  , return 7.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    if  ( day_of_week  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								        return  7 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
										 
									
								 
							
							
								    // 6. Return ℝ  (dayOfWeek).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								    return  day_of_week ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-11 21:04:11 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
								
									
								 
							
							
								}