2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
									
										
										
										
											2023-01-22 11:55:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2021 - 2023 ,  Tim  Flynn  < trflynn89 @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:52:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <AK/Array.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <AK/StringBuilder.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:11:30 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibLocale/DateTimeFormat.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibLocale/Locale.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibLocale/NumberFormat.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <stdlib.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								namespace  Locale  {  
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HourCycle  hour_cycle_from_string ( StringView  hour_cycle )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( hour_cycle  = =  " h11 " sv ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  HourCycle : : H11 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:27:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( hour_cycle  = =  " h12 " sv ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  HourCycle : : H12 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:27:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( hour_cycle  = =  " h23 " sv ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  HourCycle : : H23 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:27:33 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( hour_cycle  = =  " h24 " sv ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-02 12:01:10 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  HourCycle : : H24 ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								StringView  hour_cycle_to_string ( HourCycle  hour_cycle )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( hour_cycle )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  HourCycle : : H11 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " h11 " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  HourCycle : : H12 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " h12 " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  HourCycle : : H23 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " h23 " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  HourCycle : : H24 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " h24 " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								CalendarPatternStyle  calendar_pattern_style_from_string ( StringView  style )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " narrow " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : Narrow ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " short " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : Short ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " long " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : Long ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " numeric " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : Numeric ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " 2-digit " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : TwoDigit ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-02 14:23:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( style  = =  " shortOffset " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : ShortOffset ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " longOffset " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : LongOffset ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " shortGeneric " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : ShortGeneric ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( style  = =  " longGeneric " sv ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  CalendarPatternStyle : : LongGeneric ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								StringView  calendar_pattern_style_to_string ( CalendarPatternStyle  style )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( style )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Narrow : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " narrow " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Short : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " short " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Long : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " long " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Numeric : 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-30 10:39:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  " numeric " sv ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : TwoDigit : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " 2-digit " sv ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-02 14:23:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : ShortOffset : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " shortOffset " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : LongOffset : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " longOffset " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : ShortGeneric : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " shortGeneric " sv ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : LongGeneric : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  " longGeneric " sv ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-04 11:29:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Optional < HourCycleRegion >  __attribute__ ( ( weak ) )  hour_cycle_region_from_string ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Vector < HourCycle > >  __attribute__ ( ( weak ) )  get_regional_hour_cycles ( StringView )  {  return  Vector < HourCycle >  { } ;  }  
						 
					
						
							
								
									
										
										
										
											2022-01-04 11:29:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								template < typename  T ,  FallibleFunction < StringView >  GetRegionalValues >  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  ErrorOr < T >  find_regional_values_for_locale ( StringView  locale ,  GetRegionalValues & &  get_regional_values )  
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  has_value  =  [ ] ( auto  const &  container )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  constexpr  ( requires  {  container . has_value ( ) ;  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  container . has_value ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  ! container . is_empty ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( auto  regional_values  =  TRY ( get_regional_values ( locale ) ) ;  has_value ( regional_values ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  regional_values ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-15 23:19:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  return_default_values  =  [ & ] ( )  {  return  get_regional_values ( " 001 " sv ) ;  } ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  language  =  TRY ( parse_unicode_language_id ( locale ) ) ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! language . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  return_default_values ( ) ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! language - > region . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        language  =  TRY ( add_likely_subtags ( * language ) ) ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! language . has_value ( )  | |  ! language - > region . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  return_default_values ( ) ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( auto  regional_values  =  TRY ( get_regional_values ( * language - > region ) ) ;  has_value ( regional_values ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  regional_values ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  return_default_values ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								template < typename  T ,  typename  GetRegionalValues >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  ErrorOr < T >  find_regional_values_for_locale ( StringView  locale ,  GetRegionalValues & &  get_regional_values )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  find_regional_values_for_locale < T > ( locale ,  [ & ] ( auto  region )  - >  ErrorOr < T >  {  return  get_regional_values ( region ) ;  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Vector < HourCycle > >  get_locale_hour_cycles ( StringView  locale )  
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  find_regional_values_for_locale < Vector < HourCycle > > ( locale ,  get_regional_hour_cycles ) ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < HourCycle > >  get_default_regional_hour_cycle ( StringView  locale )  
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( auto  hour_cycles  =  TRY ( get_locale_hour_cycles ( locale ) ) ;  ! hour_cycles . is_empty ( ) ) 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  hour_cycles . first ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  OptionalNone  { } ; 
							 
						 
					
						
							
								
									
										
										
											
												LibUnicode: Parse and generate regional hour cycles
Unlike most data in the CLDR, hour cycles are not stored on a per-locale
basis. Instead, they are keyed by a string that is usually a region, but
sometimes is a locale. Therefore, given a locale, to determine the hour
cycles for that locale, we:
    1. Check if the locale itself is assigned hour cycles.
    2. If the locale has a region, check if that region is assigned hour
       cycles.
    3. Otherwise, maximize that locale, and if the maximized locale has
       a region, check if that region is assigned hour cycles.
    4. If the above all fail, fallback to the "001" region.
Further, each locale's default hour cycle is the first assigned hour
cycle.
											 
										 
										
											2021-11-27 20:57:21 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Optional < MinimumDaysRegion >  __attribute__ ( ( weak ) )  minimum_days_region_from_string ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Optional < u8 >  __attribute__ ( ( weak ) )  get_regional_minimum_days ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < u8 > >  get_locale_minimum_days ( StringView  locale )  
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  find_regional_values_for_locale < Optional < u8 > > ( locale ,  get_regional_minimum_days ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Optional < FirstDayRegion >  __attribute__ ( ( weak ) )  first_day_region_from_string ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Optional < Weekday >  __attribute__ ( ( weak ) )  get_regional_first_day ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < Weekday > >  get_locale_first_day ( StringView  locale )  
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  find_regional_values_for_locale < Optional < Weekday > > ( locale ,  get_regional_first_day ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Optional < WeekendStartRegion >  __attribute__ ( ( weak ) )  weekend_start_region_from_string ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Optional < Weekday >  __attribute__ ( ( weak ) )  get_regional_weekend_start ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < Weekday > >  get_locale_weekend_start ( StringView  locale )  
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  find_regional_values_for_locale < Optional < Weekday > > ( locale ,  get_regional_weekend_start ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Optional < WeekendEndRegion >  __attribute__ ( ( weak ) )  weekend_end_region_from_string ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Optional < Weekday >  __attribute__ ( ( weak ) )  get_regional_weekend_end ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < Weekday > >  get_locale_weekend_end ( StringView  locale )  
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  find_regional_values_for_locale < Optional < Weekday > > ( locale ,  get_regional_weekend_end ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-06 08:21:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < String >  combine_skeletons ( StringView  first ,  StringView  second )  
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:52:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // https://unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    constexpr  auto  field_order  =  Array  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " G " sv ,        // Era
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " yYuUr " sv ,    // Year
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " ML " sv ,       // Month
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " dDFg " sv ,     // Day
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Eec " sv ,      // Weekday
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " abB " sv ,      // Period
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " hHKk " sv ,     // Hour
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " m " sv ,        // Minute
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " sSA " sv ,      // Second
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " zZOvVXx " sv ,  // Zone
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    StringBuilder  builder ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  append_from_skeleton  =  [ & ] ( auto  skeleton ,  auto  ch )  - >  ErrorOr < bool >  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:52:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto  first_index  =  skeleton . find ( ch ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! first_index . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto  last_index  =  skeleton . find_last ( ch ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TRY ( builder . try_append ( skeleton . substring_view ( * first_index ,  * last_index  -  * first_index  +  1 ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:52:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto  fields  :  field_order )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( auto  ch  :  fields )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( TRY ( append_from_skeleton ( first ,  ch ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:52:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                break ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 21:34:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( TRY ( append_from_skeleton ( second ,  ch ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:52:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  builder . to_string ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:52:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < CalendarFormat > >  __attribute__ ( ( weak ) )  get_calendar_date_format ( StringView ,  StringView )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Optional < CalendarFormat > >  __attribute__ ( ( weak ) )  get_calendar_time_format ( StringView ,  StringView )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Optional < CalendarFormat > >  __attribute__ ( ( weak ) )  get_calendar_date_time_format ( StringView ,  StringView )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
									
										
										
										
											2022-01-04 11:29:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < CalendarFormat > >  get_calendar_format ( StringView  locale ,  StringView  calendar ,  CalendarFormatType  type )  
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( type )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarFormatType : : Date : 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-04 11:29:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  get_calendar_date_format ( locale ,  calendar ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    case  CalendarFormatType : : Time : 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-04 11:29:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  get_calendar_time_format ( locale ,  calendar ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    case  CalendarFormatType : : DateTime : 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-04 11:29:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  get_calendar_date_time_format ( locale ,  calendar ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Vector < CalendarPattern > >  __attribute__ ( ( weak ) )  get_calendar_available_formats ( StringView ,  StringView )  {  return  Vector < CalendarPattern >  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Optional < CalendarRangePattern > >  __attribute__ ( ( weak ) )  get_calendar_default_range_format ( StringView ,  StringView )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Vector < CalendarRangePattern > >  __attribute__ ( ( weak ) )  get_calendar_range_formats ( StringView ,  StringView ,  StringView )  {  return  Vector < CalendarRangePattern >  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Vector < CalendarRangePattern > >  __attribute__ ( ( weak ) )  get_calendar_range12_formats ( StringView ,  StringView ,  StringView )  {  return  Vector < CalendarRangePattern >  { } ;  }  
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < Optional < StringView > >  __attribute__ ( ( weak ) )  get_calendar_era_symbol ( StringView ,  StringView ,  CalendarPatternStyle ,  Era )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Optional < StringView > >  __attribute__ ( ( weak ) )  get_calendar_month_symbol ( StringView ,  StringView ,  CalendarPatternStyle ,  Month )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Optional < StringView > >  __attribute__ ( ( weak ) )  get_calendar_weekday_symbol ( StringView ,  StringView ,  CalendarPatternStyle ,  Weekday )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Optional < StringView > >  __attribute__ ( ( weak ) )  get_calendar_day_period_symbol ( StringView ,  StringView ,  CalendarPatternStyle ,  DayPeriod )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ErrorOr < Optional < StringView > >  __attribute__ ( ( weak ) )  get_calendar_day_period_symbol_for_hour ( StringView ,  StringView ,  CalendarPatternStyle ,  u8 )  {  return  OptionalNone  { } ;  }  
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Optional < StringView >  __attribute__ ( ( weak ) )  get_time_zone_name ( StringView ,  StringView ,  CalendarPatternStyle ,  TimeZone : : InDST )  {  return  { } ;  }  
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Optional < TimeZoneFormat >  __attribute__ ( ( weak ) )  get_time_zone_format ( StringView )  {  return  { } ;  }  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  ErrorOr < Optional < String > >  format_time_zone_offset ( StringView  locale ,  CalendarPatternStyle  style ,  i64  offset_seconds )  
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  formats  =  get_time_zone_format ( locale ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! formats . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  OptionalNone  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 11:12:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  number_system  =  TRY ( get_preferred_keyword_value_for_locale ( locale ,  " nu " sv ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! number_system . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  OptionalNone  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( offset_seconds  = =  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  String : : from_utf8 ( formats - > gmt_zero_format ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  sign  =  offset_seconds  >  0  ?  formats - > symbol_ahead_sign  :  formats - > symbol_behind_sign ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  separator  =  offset_seconds  >  0  ?  formats - > symbol_ahead_separator  :  formats - > symbol_behind_separator ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    offset_seconds  =  llabs ( offset_seconds ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  offset_hours  =  offset_seconds  /  3'600 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    offset_seconds  % =  3'600 ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  offset_minutes  =  offset_seconds  /  60 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    offset_seconds  % =  60 ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    StringBuilder  builder ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 16:25:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    TRY ( builder . try_append ( sign ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( style )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The long format always uses 2-digit hours field and minutes field, with optional 2-digit seconds field.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : LongOffset : 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 16:25:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TRY ( builder . try_appendff ( " {:02}{}{:02} " ,  offset_hours ,  separator ,  offset_minutes ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( offset_seconds  >  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 16:25:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            TRY ( builder . try_appendff ( " {}{:02} " ,  separator ,  offset_seconds ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The short format is intended for the shortest representation and uses hour fields without leading zero, with optional 2-digit minutes and seconds fields.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : ShortOffset : 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 16:25:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TRY ( builder . try_appendff ( " {} " ,  offset_hours ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( offset_minutes  >  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 16:25:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            TRY ( builder . try_appendff ( " {}{:02} " ,  separator ,  offset_minutes ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( offset_seconds  >  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 16:25:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                TRY ( builder . try_appendff ( " {}{:02} " ,  separator ,  offset_seconds ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The digits used for hours, minutes and seconds fields in this format are the locale's default decimal digits.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 16:25:53 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  result  =  TRY ( replace_digits_for_number_system ( * number_system ,  TRY ( builder . to_string ( ) ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  TRY ( String : : from_utf8 ( formats - > gmt_format ) ) . replace ( " { 0 } " sv, result, ReplaceMode::FirstOnly); 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// https://unicode.org/reports/tr35/tr35-dates.html#Time_Zone_Format_Terminology
  
						 
					
						
							
								
									
										
										
										
											2023-03-13 22:28:08 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ErrorOr < String >  format_time_zone ( StringView  locale ,  StringView  time_zone ,  CalendarPatternStyle  style ,  AK : : UnixDateTime  time )  
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  offset  =  TimeZone : : get_time_zone_offset ( time_zone ,  time ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! offset . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  String : : from_utf8 ( time_zone ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    switch  ( style )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Short : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Long : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : ShortGeneric : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : LongGeneric : 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-19 14:54:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( auto  name  =  get_time_zone_name ( locale ,  time_zone ,  style ,  offset - > in_dst ) ;  name . has_value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            return  String : : from_utf8 ( * name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 12:06:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        break ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : ShortOffset : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : LongOffset : 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 10:18:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( auto  formatted_offset  =  TRY ( format_time_zone_offset ( locale ,  style ,  offset - > seconds ) ) ;  formatted_offset . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  formatted_offset . release_value ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  String : : from_utf8 ( time_zone ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 12:06:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // If more styles are added, consult the following table to ensure always falling back to GMT offset is still correct:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // https://unicode.org/reports/tr35/tr35-dates.html#dfst-zone
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    switch  ( style )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Short : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : ShortGeneric : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  format_time_zone ( locale ,  time_zone ,  CalendarPatternStyle : : ShortOffset ,  time ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : Long : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    case  CalendarPatternStyle : : LongGeneric : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  format_time_zone ( locale ,  time_zone ,  CalendarPatternStyle : : LongOffset ,  time ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VERIFY_NOT_REACHED ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-11 11:35:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-06 15:46:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-27 14:54:48 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}