
    MhZ*                   ^   U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
mZ 	 ddlZn# e$ r	 dZddlZY nw xY wddlZddlmZ ddlmZ ddlmZmZmZ dd	lmZ e	r_dd
lmZ ej        ej        z  ez  dz  Zde d<   e
d         Z!de d<   e
d         Z"de d<   ej        ej#        z  e$z  e%z  ej        z  dz  Z&de d<   dZ'ej(        j)        Z*ej+        Z+ ed          Z,ddZ-ddZ.ddZ/dd Z0ddd#Z1	 ddd'Z2ddd*Z3	 	 	 ddd3Z4	 	 	 ddd6Z5	 	 	 ddd7Z6	 	 	 ddd8Z7	 	 ddd9Z8	 	 ddd<Z9	 	 ddd=Z:	 	 ddd>Z;	 	 	 	 dddEZ<	 	 	 dddGZ=	 	 	 	 	 	 dddMZ>	 	 	 dddQZ?	 	 	 	 dddRZ@	 	 	 	 dddTZA	 	 	 	 dddXZBdYZCdZe d[<   	 	 	 	 	 dddfZDddkZE	 	 	 	 dddlZF	 	 	 dddoZG G dp dqeH          ZI	 	 dddtZJ	 	 ddduZK G dv d;          ZL G dw dx          ZMi dyg dzd{dd|dd}dd~g dzdg dzdg dzdg dzdddgddgdddgdg dddgdddg ddg ddg di dg dzdg dzdg dzdddgdddgdddgdddgdddgdddgdddddg ddg dzdddgdddgdg ddg dzdg dziZNde d<   dZOddZP ed          dd            ZQddZRddZSddZTdddZUdS )a  
    babel.dates
    ~~~~~~~~~~~

    Locale dependent formatting and parsing of dates and times.

    The default locale for the functions in this module is determined by the
    following environment variables, in that order:

     * ``LC_TIME``,
     * ``LC_ALL``, and
     * ``LANG``

    :copyright: (c) 2013-2025 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    )annotationsN)	lru_cache)TYPE_CHECKINGLiteralSupportsInt)Iterable)	localtime)Localedefault_locale
get_global)LocaleDataDict)	TypeAliasr   _Instantfulllongmediumshort_PredefinedTimeFormat)formatstand-alone_Context_DtOrTzinfou	   ∅∅∅LC_TIMEtzdatetime.tzinfodtdatetime.datetimereturnc                    |j         | u r|S t          | d          r|                     |          S |j         |                    |           S |                    |           S )Nlocalizetzinfo)r#   hasattrr!   replace
astimezone)r   r   s     K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/babel/dates.py	_localizer(   =   sf     
yB	r: {{2	yzzz$$$ ==    dt_or_tzinfo0tuple[datetime.datetime | None, datetime.tzinfo]c                   | &t           j                                         }t          }nt          | t                    rd}t          |           }nnt          | t                    r
d}t          }nOt          | t           j         t           j        f          r%t          |           }|j
        |j
        nt          }nd}| }||fS )z
    Parse a `dt_or_tzinfo` value into a datetime and a tzinfo.

    See the docs for this function's callers for semantics.

    :rtype: tuple[datetime, tzinfo]
    N)datetimenowLOCALTZ
isinstancestrget_timezoneintUTCtime_get_datetimer#   r*   r   r#   s      r'   _get_dt_and_tzinfor8   N   s     ""$$	L#	&	& l++	L#	&	& 	L8#4hm"D	E	E <(( i3v:r)   r1   c                   t          |           \  }}t          |d          r|j        S t          |d          r|j        |j        S |                    |p#t
          j                            t                              S )z[
    Get the timezone name out of a time, datetime, or tzinfo object.

    :rtype: str
    zonekey)r8   r$   r:   r;   tznamer-   r.   r4   r7   s      r'   _get_tz_namer=   h   sx     $L11JBvv ?{			 ?FJ$:z}}R=8#4#8#8#=#=>>>r)   instantc                   | 8t           j                             t                                        d          S t	          | t
          t          f          r9t           j                             | t                                        d          S t	          | t           j                  r<t           j         	                    t           j
                                        |           S t	          | t           j
                  rKt	          | t           j                   s1t           j         	                    | t          j                              S | S )a  
    Get a datetime out of an "instant" (date, time, datetime, number).

    .. warning:: The return values of this function may depend on the system clock.

    If the instant is None, the current moment is used.
    If the instant is a time, it's augmented with today's date.

    Dates are converted to naive datetimes with midnight as the time component.

    >>> from datetime import date, datetime
    >>> _get_datetime(date(2015, 1, 1))
    datetime.datetime(2015, 1, 1, 0, 0)

    UNIX timestamps are converted to datetimes.

    >>> _get_datetime(1400000000)
    datetime.datetime(2014, 5, 13, 16, 53, 20)

    Other values are passed through as-is.

    >>> x = datetime(2015, 1, 1)
    >>> _get_datetime(x) is x
    True

    :param instant: date, time, datetime, integer, float or None
    :type instant: date|time|datetime|int|float|None
    :return: a datetime
    :rtype: datetime
    Nr"   )r-   r.   r4   r%   r0   r3   floatfromtimestampr5   combinedatetoday)r>   s    r'   r6   r6   w   s    >  $$S))111>>>	Gc5\	*	* C ..w<<DDDDQQQ	GX]	+	+ C (()<)<)>)>HHH	GX]	+	+ CJwHY4Z4Z C (((-//BBBNr)   r#   datetime.tzinfo | Nonec                    | j         |                     t                    } |G|                     t	          |                    } t          |d          r|                    |           } | S )aS  
    Ensure the datetime passed has an attached tzinfo.

    If the datetime is tz-naive to begin with, UTC is attached.

    If a tzinfo is passed in, the datetime is normalized to that timezone.

    >>> from datetime import datetime
    >>> _get_tz_name(_ensure_datetime_tzinfo(datetime(2015, 1, 1)))
    'UTC'

    >>> tz = get_timezone("Europe/Stockholm")
    >>> _ensure_datetime_tzinfo(datetime(2015, 1, 1, 13, 15, tzinfo=UTC), tzinfo=tz).hour
    14

    :param datetime: Datetime to augment.
    :param tzinfo: optional tzinfo
    :return: datetime with tzinfo
    :rtype: datetime
    Nr"   	normalize)r#   r%   r4   r&   r2   r$   rG   )r   r#   s     r'   _ensure_datetime_tzinforH      sh    * 
yZZsZ##]]<//006;'' 	&!!"%%BIr)   r5   (datetime.time | datetime.datetime | Nonedatetime.timec                    | %t           j                             t                    } nAt          | t          t
          f          r%t           j                             | t                    } | j        |                     t                    } t          | t           j                   rQ|:| 	                    |          } t          |d          r|                    |           } |                                 } n||                     |          } | S )z
    Get a timezoned time from a given instant.

    .. warning:: The return values of this function may depend on the system clock.

    :param time: time, datetime or None
    :rtype: time
    Nr"   rG   )r-   r.   r4   r0   r3   r@   rA   r#   r%   r&   r$   rG   timetz)r5   r#   s     r'   	_get_timerM      s     | $$S))	D3,	'	' : ..tS99{||3|''$)** +??6**Dv{++ .''--{{}}		||6|**Kr)   r:   str | datetime.tzinfo | Nonec                T   | t           S t          | t                    s| S t          r3	 t          j        |           S # t          j        $ r}|}Y d}~nDd}~ww xY wt          sJ 	 t          j        |           S # t          j        $ r}|}Y d}~nd}~ww xY wt          d|            |)a  Looks up a timezone by name and returns it.  The timezone object
    returned comes from ``pytz`` or ``zoneinfo``, whichever is available.
    It corresponds to the `tzinfo` interface and can be used with all of
    the functions of Babel that operate with dates.

    If a timezone is not known a :exc:`LookupError` is raised.  If `zone`
    is ``None`` a local zone object is returned.

    :param zone: the name of the timezone to look up.  If a timezone object
                 itself is passed in, it's returned unchanged.
    NzUnknown timezone )
r/   r0   r1   pytztimezoneUnknownTimeZoneErrorzoneinfoZoneInfoZoneInfoNotFoundErrorLookupError)r:   eexcs      r'   r2   r2      s     |dC    
	=&&&( 	 	 	CCCCCC	 	$T***- 	 	 	CCCCCC	 0$00
1
1s:s-   = AAA%A9 9BBBwider   width(Literal['abbreviated', 'narrow', 'wide']contextlocaleLocale | str | Noner   c                Z    t          j        |pt                    j        |         |          S )al  Return the names for day periods (AM/PM) used by the locale.

    >>> get_period_names(locale='en_US')['am']
    u'AM'

    :param width: the width to use, one of "abbreviated", "narrow", or "wide"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    )r
   parser   day_periodsrZ   r\   r]   s      r'   get_period_namesrc      s&     <)'**6w?FFr)   r   1Literal['abbreviated', 'narrow', 'short', 'wide']c                Z    t          j        |pt                    j        |         |          S )aO  Return the day names used by the locale for the specified format.

    >>> get_day_names('wide', locale='en_US')[1]
    u'Tuesday'
    >>> get_day_names('short', locale='en_US')[1]
    u'Tu'
    >>> get_day_names('abbreviated', locale='es')[1]
    u'mar'
    >>> get_day_names('narrow', context='stand-alone', locale='de_DE')[1]
    u'D'

    :param width: the width to use, one of "wide", "abbreviated", "short" or "narrow"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    )r
   r`   r   daysrb   s      r'   get_day_namesrg     s&    ( <)'**/8??r)   c                Z    t          j        |pt                    j        |         |          S )a  Return the month names used by the locale for the specified format.

    >>> get_month_names('wide', locale='en_US')[1]
    u'January'
    >>> get_month_names('abbreviated', locale='es')[1]
    u'ene'
    >>> get_month_names('narrow', context='stand-alone', locale='de_DE')[1]
    u'J'

    :param width: the width to use, one of "wide", "abbreviated", or "narrow"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    )r
   r`   r   monthsrb   s      r'   get_month_namesrj   '  s&    $ <)'**1':5AAr)   c                Z    t          j        |pt                    j        |         |          S )a
  Return the quarter names used by the locale for the specified format.

    >>> get_quarter_names('wide', locale='en_US')[1]
    u'1st quarter'
    >>> get_quarter_names('abbreviated', locale='de_DE')[1]
    u'Q1'
    >>> get_quarter_names('narrow', locale='de_DE')[1]
    u'1'

    :param width: the width to use, one of "wide", "abbreviated", or "narrow"
    :param context: the context, either "format" or "stand-alone"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    )r
   r`   r   quartersrb   s      r'   get_quarter_namesrm   <  s&    $ <)'**3G<UCCr)   c                N    t          j        |pt                    j        |          S )a  Return the era names used by the locale for the specified format.

    >>> get_era_names('wide', locale='en_US')[1]
    u'Anno Domini'
    >>> get_era_names('abbreviated', locale='de_DE')[1]
    u'n. Chr.'

    :param width: the width to use, either "wide", "abbreviated", or "narrow"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    )r
   r`   r   erasrZ   r]   s     r'   get_era_namesrq   Q  s!     <)'**/66r)   r   DateTimePatternc                N    t          j        |pt                    j        |          S )a  Return the date formatting patterns used by the locale for the specified
    format.

    >>> get_date_format(locale='en_US')
    <DateTimePattern u'MMM d, y'>
    >>> get_date_format('full', locale='de_DE')
    <DateTimePattern u'EEEE, d. MMMM y'>

    :param format: the format to use, one of "full", "long", "medium", or
                   "short"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    )r
   r`   r   date_formatsr   r]   s     r'   get_date_formatrv   b  !      <)'**7??r)   c                ^    t          j        |pt                    j        }| |vrd} ||          S )a`  Return the datetime formatting patterns used by the locale for the
    specified format.

    >>> get_datetime_format(locale='en_US')
    u'{1}, {0}'

    :param format: the format to use, one of "full", "long", "medium", or
                   "short"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    N)r
   r`   r   datetime_formats)r   r]   patternss      r'   get_datetime_formatr{   u  s6     |F-g..?HXFr)   c                N    t          j        |pt                    j        |          S )u  Return the time formatting patterns used by the locale for the specified
    format.

    >>> get_time_format(locale='en_US')
    <DateTimePattern u'h:mm:ss a'>
    >>> get_time_format('full', locale='de_DE')
    <DateTimePattern u'HH:mm:ss zzzz'>

    :param format: the format to use, one of "full", "long", "medium", or
                   "short"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    )r
   r`   r   time_formatsru   s     r'   get_time_formatr~     rw   r)   r   Fr-   4Literal['long', 'short', 'iso8601', 'iso8601_short']return_zboolc                   t          t          |                     } t          j        |pt                    }| j                            |           }|j        dz  dz  dz  |j        z   }t          |d          \  }}|r|dk    r|dk    rdS |dk    r|dk    rd|z  S |dk    s|dk    rd	}n|d
k    rd}n|j
        d         dz  }|||dz  fz  S )a4  Return the timezone associated with the given `datetime` object formatted
    as string indicating the offset from GMT.

    >>> from datetime import datetime
    >>> dt = datetime(2007, 4, 1, 15, 30)
    >>> get_timezone_gmt(dt, locale='en')
    u'GMT+00:00'
    >>> get_timezone_gmt(dt, locale='en', return_z=True)
    'Z'
    >>> get_timezone_gmt(dt, locale='en', width='iso8601_short')
    u'+00'
    >>> tz = get_timezone('America/Los_Angeles')
    >>> dt = _localize(tz, datetime(2007, 4, 1, 15, 30))
    >>> get_timezone_gmt(dt, locale='en')
    u'GMT-07:00'
    >>> get_timezone_gmt(dt, 'short', locale='en')
    u'-0700'
    >>> get_timezone_gmt(dt, locale='en', width='iso8601_short')
    u'-07'

    The long format depends on the locale, for example in France the acronym
    UTC string is used instead of GMT:

    >>> get_timezone_gmt(dt, 'long', locale='fr_FR')
    u'UTC-07:00'

    .. versionadded:: 0.9

    :param datetime: the ``datetime`` object; if `None`, the current date and
                     time in UTC is used
    :param width: either "long" or "short" or "iso8601" or "iso8601_short"
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    :param return_z: True or False; Function returns indicator "Z"
                     when local time offset is 0
       <     r   Ziso8601_shortz%+03dr   z	%+03d%02diso8601z
%+03d:%02dgmt)rH   r6   r
   r`   r   r#   	utcoffsetrf   secondsdivmodzone_formats)r-   rZ   r]   r   offsetr   hourspatterns           r'   get_timezone_gmtr     s   R '}X'>'>??H\&+G,,F_&&x00FkB#b(6>9GGT**NE7 	<EQJJ7a<<s	A%?22	'		Uo55	)		%e,|;eW]+++r)   return_cityc                V   t          j        |pt                    }t          |           }t	          d                              ||          }|j                            |i           }|j        d         }t	          d                              |          }||j        vrd}|j        |         }|s;|r9t          t	          d                              |g                     dk    r||z  S |j        d         }d|v r	|d         }	nt	          d	                              |          }
|j
                            |
i           }d|v r	|d         }	nKd
|v r1|                    d
d          d                             dd          }	n|                    dd          }	|r|	S |||	|dz  z  S )u  Return a representation of the given timezone using "location format".

    The result depends on both the local display name of the country and the
    city associated with the time zone:

    >>> tz = get_timezone('America/St_Johns')
    >>> print(get_timezone_location(tz, locale='de_DE'))
    Kanada (St. John’s) (Ortszeit)
    >>> print(get_timezone_location(tz, locale='en'))
    Canada (St. John’s) Time
    >>> print(get_timezone_location(tz, locale='en', return_city=True))
    St. John’s
    >>> tz = get_timezone('America/Mexico_City')
    >>> get_timezone_location(tz, locale='de_DE')
    u'Mexiko (Mexiko-Stadt) (Ortszeit)'

    If the timezone is associated with a country that uses only a single
    timezone, just the localized country name is returned:

    >>> tz = get_timezone('Europe/Berlin')
    >>> get_timezone_name(tz, locale='de_DE')
    u'Mitteleurop\xe4ische Zeit'

    .. versionadded:: 0.9

    :param dt_or_tzinfo: the ``datetime`` or ``tzinfo`` object that determines
                         the timezone; if `None`, the current date and time in
                         UTC is assumed
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    :param return_city: True or False, if True then return exemplar city (location)
                        for the time zone
    :return: the localized timezone name using location format

    zone_aliasesregionzone_territoriesZZterritory_zones   fallbackcity
meta_zones/_ )01)r
   r`   r   r=   r   get
time_zonesr   territorieslenr   splitr%   )r*   r]   r   r:   inforegion_format	territoryterritory_namefallback_format	city_namemetazonemetazone_infos               r'   get_timezone_locationr     s   N \&+G,,F%%D n%%))$55D  r**D '1M-..22488I***	'	2N .9 .Z8I-J-J-N-NyZ\-]-])^)^bc)c)c~-- )*5O~~L		l++//55)--h;;]""%f-IID[[

3**1-55c3??IIS#..I O/ /   r)   Literal['long', 'short']uncommonzone_variant1Literal['generic', 'daylight', 'standard'] | Nonereturn_zonec                $   t          |           \  }}t          j        |pt                    }t	          |           }|!|d}n/|                    |          }	|	rdnd}n|dvrt          d          t          d                              ||          }|r|S |j	                            |i           }
||
v r||
|         v r|
|         |         S t          d                              |          }|rx|j
                            |i           }||v rY||                             |          }|d	k    r4|t          k    r)|                    d
i                               |          }|r|S |t          |||          S t          | |          S )az  Return the localized display name for the given timezone. The timezone
    may be specified using a ``datetime`` or `tzinfo` object.

    >>> from datetime import time
    >>> dt = time(15, 30, tzinfo=get_timezone('America/Los_Angeles'))
    >>> get_timezone_name(dt, locale='en_US')  # doctest: +SKIP
    u'Pacific Standard Time'
    >>> get_timezone_name(dt, locale='en_US', return_zone=True)
    'America/Los_Angeles'
    >>> get_timezone_name(dt, width='short', locale='en_US')  # doctest: +SKIP
    u'PST'

    If this function gets passed only a `tzinfo` object and no concrete
    `datetime`,  the returned display name is independent of daylight savings
    time. This can be used for example for selecting timezones, or to set the
    time of events that recur across DST changes:

    >>> tz = get_timezone('America/Los_Angeles')
    >>> get_timezone_name(tz, locale='en_US')
    u'Pacific Time'
    >>> get_timezone_name(tz, 'short', locale='en_US')
    u'PT'

    If no localized display name for the timezone is available, and the timezone
    is associated with a country that uses only a single timezone, the name of
    that country is returned, formatted according to the locale:

    >>> tz = get_timezone('Europe/Berlin')
    >>> get_timezone_name(tz, locale='de_DE')
    u'Mitteleurop\xe4ische Zeit'
    >>> get_timezone_name(tz, locale='pt_BR')
    u'Hor\xe1rio da Europa Central'

    On the other hand, if the country uses multiple timezones, the city is also
    included in the representation:

    >>> tz = get_timezone('America/St_Johns')
    >>> get_timezone_name(tz, locale='de_DE')
    u'Neufundland-Zeit'

    Note that short format is currently not supported for all timezones and
    all locales.  This is partially because not every timezone has a short
    code in every locale.  In that case it currently falls back to the long
    format.

    For more information see `LDML Appendix J: Time Zone Display Names
    <https://www.unicode.org/reports/tr35/#Time_Zone_Fallback>`_

    .. versionadded:: 0.9

    .. versionchanged:: 1.0
       Added `zone_variant` support.

    :param dt_or_tzinfo: the ``datetime`` or ``tzinfo`` object that determines
                         the timezone; if a ``tzinfo`` object is used, the
                         resulting display name will be generic, i.e.
                         independent of daylight savings time; if `None`, the
                         current date in UTC is assumed
    :param width: either "long" or "short"
    :param uncommon: deprecated and ignored
    :param zone_variant: defines the zone variation to return.  By default the
                           variation is defined from the datetime object
                           passed in.  If no datetime object is passed in, the
                           ``'generic'`` variation is assumed.  The following
                           values are valid: ``'generic'``, ``'daylight'`` and
                           ``'standard'``.
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    :param return_zone: True or False. If true then function
                        returns long time zone ID
    Ngenericdaylightstandard)r   r   r   zInvalid zone variationr   r   r   r   rp   r]   )r8   r
   r`   r   r=   dst
ValueErrorr   r   r   r   NO_INHERITANCE_MARKERr   r   )r*   rZ   r   r]   r   r   r   r#   r:   r   r   r   r   names                 r'   get_timezone_namer   (  s   \ $L11JB\&+G,,F%%D:$LL**R..C),<::*LLBBB5666 n%%))$55D   r**D}}e44E{<((,''++D11H 	)--h;;M!! '++L99DD,A$A$A %((4488FF  
~%???? f====r)   rC   datetime.date | None_PredefinedTimeFormat | strc                J   | t           j                                        } n.t          | t           j                   r|                                 } t	          j        |pt                    }|dv rt          ||          }t          |          }|	                    | |          S )a  Return a date formatted according to the given pattern.

    >>> from datetime import date
    >>> d = date(2007, 4, 1)
    >>> format_date(d, locale='en_US')
    u'Apr 1, 2007'
    >>> format_date(d, format='full', locale='de_DE')
    u'Sonntag, 1. April 2007'

    If you don't want to use the locale default formats, you can specify a
    custom date pattern:

    >>> format_date(d, "EEE, MMM d, ''yy", locale='en')
    u"Sun, Apr 1, '07"

    :param date: the ``date`` or ``datetime`` object; if `None`, the current
                 date is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param locale: a `Locale` object or a locale identifier. Defaults to the system time locale.
    Nr   r   )
r-   rC   rD   r0   r
   r`   r   rv   parse_patternapply)rC   r   r]   r   s       r'   format_dater     s    4 |}""$$	D(+	,	, yy{{\&+G,,F444 777F##G==v&&&r)   c           	        t          t          |           |          } t          j        |pt                    }|dv rnt          ||                              dd                              dt          | |d|                                        dt          | ||                    S t          |          
                    | |          S )	u  Return a date formatted according to the given pattern.

    >>> from datetime import datetime
    >>> dt = datetime(2007, 4, 1, 15, 30)
    >>> format_datetime(dt, locale='en_US')
    u'Apr 1, 2007, 3:30:00\u202fPM'

    For any pattern requiring the display of the timezone:

    >>> format_datetime(dt, 'full', tzinfo=get_timezone('Europe/Paris'),
    ...                 locale='fr_FR')
    'dimanche 1 avril 2007, 17:30:00 heure d’été d’Europe centrale'
    >>> format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
    ...                 tzinfo=get_timezone('US/Eastern'), locale='en')
    u'2007.04.01 AD at 11:30:00 EDT'

    :param datetime: the `datetime` object; if `None`, the current date and
                     time is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the timezone to apply to the time for display
    :param locale: a `Locale` object or a locale identifier. Defaults to the system time locale.
    r   r   ' {0}Nr#   r]   {1})rH   r6   r
   r`   r   r{   r%   format_timer   r   r   )r-   r   r#   r]   s       r'   format_datetimer     s    : '}X'>'>GGH\&+G,,F444"6&999WS"WUK&/57 7 7 8 8WUK&HHHII		J V$$**8V<<<r)   0datetime.time | datetime.datetime | float | Nonec                ,   t          | t          j                  r|                                 nd}t          | |          } t	          j        |pt                    }|dv rt          ||          }t          |          	                    | ||          S )u	  Return a time formatted according to the given pattern.

    >>> from datetime import datetime, time
    >>> t = time(15, 30)
    >>> format_time(t, locale='en_US')
    u'3:30:00\u202fPM'
    >>> format_time(t, format='short', locale='de_DE')
    u'15:30'

    If you don't want to use the locale default formats, you can specify a
    custom time pattern:

    >>> format_time(t, "hh 'o''clock' a", locale='en')
    u"03 o'clock PM"

    For any pattern requiring the display of the time-zone a
    timezone has to be specified explicitly:

    >>> t = datetime(2007, 4, 1, 15, 30)
    >>> tzinfo = get_timezone('Europe/Paris')
    >>> t = _localize(tzinfo, t)
    >>> format_time(t, format='full', tzinfo=tzinfo, locale='fr_FR')
    '15:30:00 heure d’été d’Europe centrale'
    >>> format_time(t, "hh 'o''clock' a, zzzz", tzinfo=get_timezone('US/Eastern'),
    ...             locale='en')
    u"09 o'clock AM, Eastern Daylight Time"

    As that example shows, when this function gets passed a
    ``datetime.datetime`` value, the actual time in the formatted string is
    adjusted to the timezone specified by the `tzinfo` parameter. If the
    ``datetime`` is "naive" (i.e. it has no associated timezone information),
    it is assumed to be in UTC.

    These timezone calculations are **not** performed if the value is of type
    ``datetime.time``, as without date information there's no way to determine
    what a given time would translate to in a different timezone without
    information about whether daylight savings time is in effect or not. This
    means that time values are left as-is, and the value of the `tzinfo`
    parameter is only used to display the timezone name if needed:

    >>> t = time(15, 30)
    >>> format_time(t, format='full', tzinfo=get_timezone('Europe/Paris'),
    ...             locale='fr_FR')  # doctest: +SKIP
    u'15:30:00 heure normale d\u2019Europe centrale'
    >>> format_time(t, format='full', tzinfo=get_timezone('US/Eastern'),
    ...             locale='en_US')  # doctest: +SKIP
    u'3:30:00\u202fPM Eastern Standard Time'

    :param time: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the time-zone to apply to the time for display
    :param locale: a `Locale` object or a locale identifier. Defaults to the system time locale.
    Nr   r   )reference_date)
r0   r-   rC   rM   r
   r`   r   r~   r   r   )r5   r   r#   r]   ref_dates        r'   r   r     s    @ )x/@AAKtyy{{{tHT6""D\&+G,,F444 777  &&tVH&MMMr)   Tskeletonfuzzyc                    t          j        |pt                    }|r| |j        vrt	          | |j                  } |j        |          }t          ||||          S )a  Return a time and/or date formatted according to the given pattern.

    The skeletons are defined in the CLDR data and provide more flexibility
    than the simple short/long/medium formats, but are a bit harder to use.
    The are defined using the date/time symbols without order or punctuation
    and map to a suitable format for the given locale.

    >>> from datetime import datetime
    >>> t = datetime(2007, 4, 1, 15, 30)
    >>> format_skeleton('MMMEd', t, locale='fr')
    u'dim. 1 avr.'
    >>> format_skeleton('MMMEd', t, locale='en')
    u'Sun, Apr 1'
    >>> format_skeleton('yMMd', t, locale='fi')  # yMMd is not in the Finnish locale; yMd gets used
    u'1.4.2007'
    >>> format_skeleton('yMMd', t, fuzzy=False, locale='fi')  # yMMd is not in the Finnish locale, an error is thrown
    Traceback (most recent call last):
        ...
    KeyError: yMMd
    >>> format_skeleton('GH', t, fuzzy=True, locale='fi_FI')  # GH is not in the Finnish locale and there is no close match, an error is thrown
    Traceback (most recent call last):
        ...
    KeyError: None

    After the skeleton is resolved to a pattern `format_datetime` is called so
    all timezone processing etc is the same as for that.

    :param skeleton: A date time skeleton as defined in the cldr data.
    :param datetime: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param tzinfo: the time-zone to apply to the time for display
    :param fuzzy: If the skeleton is not found, allow choosing a skeleton that's
                  close enough to it. If there is no close match, a `KeyError`
                  is thrown.
    :param locale: a `Locale` object or a locale identifier. Defaults to the system time locale.
    )r
   r`   r   datetime_skeletonsmatch_skeletonr   )r   r-   r#   r   r]   r   s         r'   format_skeletonr   <  sb    V \&+G,,F G!:::!(F,EFF&x0F8VVV<<<r)   ))yeari3)monthi ' )weeki:	 )dayQ )hourr   )minuter   )secondr   ztuple[tuple[str, int], ...]TIMEDELTA_UNITSr   333333?deltadatetime.timedelta | intgranularityCLiteral['year', 'month', 'week', 'day', 'hour', 'minute', 'second']	thresholdr@   add_direction,Literal['narrow', 'short', 'medium', 'long']c                6   dvrt          d          dk    rt          j        dt          d           dt	          | t
          j                  r t          | j        dz  | j	        z             n| t          j        |pt                    }|j        d	         |j        d
         fd}t          D ]\  }}t                    |z  }	|	|k    s||k    r||k    r|	dk    rt!          d|	          }	t          t#          |	                    }	|                    |	          }
d} ||          D ]2}|.|                    |
          p|                    d          }|r n3| dS |                    dt+          |	                    c S dS )a
  Return a time delta according to the rules of the given locale.

    >>> from datetime import timedelta
    >>> format_timedelta(timedelta(weeks=12), locale='en_US')
    u'3 months'
    >>> format_timedelta(timedelta(seconds=1), locale='es')
    u'1 segundo'

    The granularity parameter can be provided to alter the lowest unit
    presented, which defaults to a second.

    >>> format_timedelta(timedelta(hours=3), granularity='day', locale='en_US')
    u'1 day'

    The threshold parameter can be used to determine at which value the
    presentation switches to the next higher unit. A higher threshold factor
    means the presentation will switch later. For example:

    >>> format_timedelta(timedelta(hours=23), threshold=0.9, locale='en_US')
    u'1 day'
    >>> format_timedelta(timedelta(hours=23), threshold=1.1, locale='en_US')
    u'23 hours'

    In addition directional information can be provided that informs
    the user if the date is in the past or in the future:

    >>> format_timedelta(timedelta(hours=1), add_direction=True, locale='en')
    u'in 1 hour'
    >>> format_timedelta(timedelta(hours=-1), add_direction=True, locale='en')
    u'1 hour ago'

    The format parameter controls how compact or wide the presentation is:

    >>> format_timedelta(timedelta(hours=3), format='short', locale='en')
    u'3 hr'
    >>> format_timedelta(timedelta(hours=3), format='narrow', locale='en')
    u'3h'

    :param delta: a ``timedelta`` object representing the time difference to
                  format, or the delta in seconds as an `int` value
    :param granularity: determines the smallest unit that should be displayed,
                        the value can be one of "year", "month", "week", "day",
                        "hour", "minute" or "second"
    :param threshold: factor that determines at which point the presentation
                      switches to the next higher unit
    :param add_direction: if this flag is set to `True` the return value will
                          include directional information.  For instance a
                          positive timedelta will include the information about
                          it being in the future, a negative will be information
                          about the value being in the past.
    :param format: the format, can be "narrow", "short" or "long". (
                   "medium" is deprecated, currently converted to "long" to
                   maintain compatibility)
    :param locale: a `Locale` object or a locale identifier. Defaults to the system time locale.
    )narrowr   r   r   z1Format must be one of "narrow", "short" or "long"r   zU"medium" value for format param of format_timedelta is deprecated. Use "long" instead   )category
stacklevelr   r   date_fieldsunit_patternsc              3  (  K   r=                     |  d           p|          }dk    r|d         V  n
|d         V  d|  }                      | i           }|                               V  dv r|                     d          V  d S d S )N-r   futurepastz	duration-)r   r   r   )r   )a_unitunit_rel_patterns	unit_patsr   r   r   r   r   s      r'   _iter_patternsz(format_timedelta.<locals>._iter_patterns  s       	0 "-F1E1EV1E1E!F!F!]+V\J]!||'11111'////%V%%!%%fb11	mmF#####
 '''--((((((( ('r)   r   r   Notherr   r   )	TypeErrorwarningswarnDeprecationWarningr0   r-   	timedeltar3   rf   r   r
   r`   r   _datar   absmaxroundplural_formr   r%   r1   )r   r   r   r   r   r]   r   unitsecs_per_unitvaluer  r   rz   r   r   r   s      ``        @@@r'   format_timedeltar  y  s   ~ :::KLLL1'		
 	
 	
 	
 %+,, uzE)U]:;;\&+G,,F,}-KL1M) ) ) ) ) ) ) ) )&  / 6 6mG},I!4!4{""uqyyAue%%E ,,U33KG*N400  '&ll;77P8<<;P;PG rr??5#e**55555 "5  2r)   startend
str | Noner
   c                   j         v rfd}nIt          d | |fD                       rfd}n(t          d | |fD                       rfd}nfd} ||           } ||          }||k    r ||           S j                            d d                              d|                              d	|          S )
Nc                *    t          |           S Nr   )r   )r   r]   r   r#   s    r'   <lambda>z+_format_fallback_interval.<locals>.<lambda>  s    OHb&PPP r)   c              3     K   | ]9}t          |t          j                  ot          |t          j                   V  :d S N)r0   r-   rC   .0ds     r'   	<genexpr>z,_format_fallback_interval.<locals>.<genexpr>  sD      kkYZjHM**S:aAR3S3S/Skkkkkkr)   c                &    t          |           S r  )r   )r   r]   s    r'   r  z+_format_fallback_interval.<locals>.<lambda>  s    K6::: r)   c              3     K   | ]9}t          |t          j                  ot          |t          j                   V  :d S r  )r0   r-   r5   rC   r  s     r'   r  z,_format_fallback_interval.<locals>.<genexpr>  sC      ggUVjHM**O:a3O3O/Oggggggr)   c                (    t          |           S Nr   )r   r   r]   r#   s    r'   r  z+_format_fallback_interval.<locals>.<lambda>  s    K6&III r)   c                (    t          |           S r  )r   r  s    r'   r  z+_format_fallback_interval.<locals>.<lambda>   s    OBvfMMM r)   z{0}-{1}r   r   )r   allinterval_formatsr   r%   )r  r  r   r#   r]   r   formatted_startformatted_ends     ```   r'   _format_fallback_intervalr    s    6,,,PPPPPP	kk_dfi^jkkk	k	k N::::	gg[`beZfggg	g	g NIIIIIMMMMMfUmmOF3KKM-''ve}} 	##D)44''}%%r)   c           	        t          j        pt                    j        }||vs|s,|r|rt	          ||          }nd}|st          | |||          S ||         }| |k    rt          || ||          S t          t          |           |          } t          t          |          |          }t          |           }t          |          }	t          D ]k}
|
|v re|                    |
          |	                    |
          k    r9d                    fdt          ||
         | |f          D                       c S lt          | |||          S )u  
    Format an interval between two instants according to the locale's rules.

    >>> from datetime import date, time
    >>> format_interval(date(2016, 1, 15), date(2016, 1, 17), "yMd", locale="fi")
    u'15.–17.1.2016'

    >>> format_interval(time(12, 12), time(16, 16), "Hm", locale="en_GB")
    '12:12–16:16'

    >>> format_interval(time(5, 12), time(16, 16), "hm", locale="en_US")
    '5:12 AM – 4:16 PM'

    >>> format_interval(time(16, 18), time(16, 24), "Hm", locale="it")
    '16:18–16:24'

    If the start instant equals the end instant, the interval is formatted like the instant.

    >>> format_interval(time(16, 18), time(16, 18), "Hm", locale="it")
    '16:18'

    Unknown skeletons fall back to "default" formatting.

    >>> format_interval(date(2015, 1, 1), date(2017, 1, 1), "wzq", locale="ja")
    '2015/01/01～2017/01/01'

    >>> format_interval(time(16, 18), time(16, 24), "xxx", locale="ja")
    '16:18:00～16:24:00'

    >>> format_interval(date(2016, 1, 15), date(2016, 1, 17), "xxx", locale="de")
    '15.01.2016 – 17.01.2016'

    :param start: First instant (datetime/date/time)
    :param end: Second instant (datetime/date/time)
    :param skeleton: The "skeleton format" to use for formatting.
    :param tzinfo: tzinfo to use (if none is already attached)
    :param fuzzy: If the skeleton is not found, allow choosing a skeleton that's
                  close enough to it.
    :param locale: A locale object or identifier. Defaults to the system time locale.
    :return: Formatted interval
    N)r   r]   r"   r   r   c              3  d   K   | ]*\  }}t          |                              |          V  +d S r  )r   r   )r  r   r>   r]   s      r'   r  z"format_interval.<locals>.<genexpr>m  sS        $GW g&&,,Wf==     r)   )r
   r`   r   r  r   r  r   rH   r6   DateTimeFormatPATTERN_CHAR_ORDERextractjoinzip)r  r  r   r#   r   r]   r  skel_formats	start_fmtend_fmtfields        `     r'   format_intervalr)    s   b \&+G,,F .'''x'  	 	%h0@AAHHH 	S,UC66RRR#H-L||xeFSSSS#M%$8$8HHHE
!-"4"4V
D
D
DCuV444IS000G $  L  Y%6%6u%=%=QVAWAW%W%W 77     |E*UCL99        %UC66JJJr)   typeLiteral['selection'] | Nonec                
   t          | |          } t          | j        dz  dz  | j        dz  z   | j        z             }t          j        |pt                    }|j        	                    |i           
                                }|D ] \  }}|D ]}d|v r|d         |k    r|c c S !|D ]\  }}|D ]}d|v rjd|v rf|d         |d         k     r#|d         |cxk    r|d         k     r	n n8|c c S n1|d         |cxk    rdk     sn d|cxk    r|d         k     r	n n|c c S dx}	}
d|v r||d         k    rd}	d	|v r||d	         k    rd}
d|v r||d         k     rd}
d
|v rt          d          |	r|
r|c c S Ȍ|dk     rdS dS )u  
    Get the day period ID for a given time.

    This ID can be used as a key for the period name dictionary.

    >>> from datetime import time
    >>> get_period_names(locale="de")[get_period_id(time(7, 42), locale="de")]
    u'Morgen'

    >>> get_period_id(time(0), locale="en_US")
    u'midnight'

    >>> get_period_id(time(0), type="selection", locale="en_US")
    u'night1'

    :param time: The time to inspect.
    :param tzinfo: The timezone for the time. See ``format_time``.
    :param type: The period type to use. Either "selection" or None.
                 The selection type is used for selecting among phrases such as
                 “Your email arrived yesterday evening” or “Your email arrived last night”.
    :param locale: the `Locale` object, or a locale string. Defaults to the system time locale.
    :return: period ID. Something is always returned -- even if it's just "am" or "pm".
    r   atfrombeforer   r   FTtoafterz$'after' is deprecated as of CLDR 29.i  ampm)rM   r3   r   r   r   r
   r`   r   day_period_rulesr   itemsNotImplementedError)r5   r#   r*  r]   seconds_past_midnightrulesetsrule_idrulesrulestart_okend_oks              r'   get_period_idr>  x  s^   : T6""D	B 3dkB6F F TUU\&+G,,F &**444::<<H"   	 	Dt||T
.C C C	 #   	 	D~~(d"2"2<$x.00F|'<MMMMtH~MMMMM& N F|'<DDDDuDDDD!6GGGGhGGGGG& %%Hv~~"74<"G"Gt|| 5d C C 4$9DN$J$J$)*PQQQ F 3	6 u$$ttr)   c                      e Zd ZdS )
ParseErrorN)__name__
__module____qualname__ r)   r'   r@  r@    s        Dr)   r@  stringdatetime.datec                   t          j        d|           }|st          d          |dv }t          j        d| t           j                  }|rF|rD	 t          j        t          t          |	                                           S # t          $ r Y nw xY w|rt          ||          }nt          |          }|j                                        }|                    d          }|                    d          }	|	d	k     r|                    d
          }	|                    d          }
t#          |df|	df|
dfg          }d t%          |          D             }||d                  }t'          |          dk    rdt          |          z   nt          |          }t          ||d                            }t          ||d                            }|dk    r||}}t          j        |||          S )a  Parse a date from a string.

    If an explicit format is provided, it is used to parse the date.

    >>> parse_date('01.04.2004', format='dd.MM.yyyy')
    datetime.date(2004, 4, 1)

    If no format is given, or if it is one of "full", "long", "medium",
    or "short", the function first tries to interpret the string as
    ISO-8601 date format and then uses the date format for the locale
    as a hint to determine the order in which the date fields appear in
    the string.

    >>> parse_date('4/1/04', locale='en_US')
    datetime.date(2004, 4, 1)
    >>> parse_date('01.04.2004', locale='de_DE')
    datetime.date(2004, 4, 1)
    >>> parse_date('2004-04-01', locale='en_US')
    datetime.date(2004, 4, 1)
    >>> parse_date('2004-04-01', locale='de_DE')
    datetime.date(2004, 4, 1)
    >>> parse_date('01.04.04', locale='de_DE', format='short')
    datetime.date(2004, 4, 1)

    :param string: the string containing the date
    :param locale: a `Locale` object or a locale identifier
    :param locale: a `Locale` object or a locale identifier. Defaults to the system time locale.
    :param format: the format to use, either an explicit date format,
                   or one of "full", "long", "medium", or "short"
                   (see ``get_time_format``)
    (\d+)No numbers were found in inputr   z^(\d{4})-?([01]\d)-?([0-3]\d)$)flagsru   ymr   lr  YMDc                &    i | ]\  }}|d          |S r   rD  r  idxitems      r'   
<dictcomp>zparse_date.<locals>.<dictcomp>  "    @@@	TtAw@@@r)   r   i     )refindallr@  matchASCIIr-   rC   mapr3   groupsr   rv   r   r   lowerindexfindsorted	enumerater   )rE  r]   r   numbersuse_predefined_format	iso_alikefmt
format_stryear_idx	month_idxday_idxindexesr   r   r   s                  r'   
parse_daterm    s   H j6**G ;9:::"&II :rx1 1 1I * 	=#c9+;+;+=+=">">?? 	 	 	D	  $VF;;;F##""$$J$$H$$I1}}$$S))	s##Gxo	3'7'3HIIG@@Yw-?-?@@@G
 73< D"4yyA~~4#d))3t99D%&&E
ggcl#
$
$Crzz%s=uc***s   2B 
BBc                h   t          j        d|           }|st          d          |dv rt          ||          }nt	          |          }|j                                        }|                    d          }|dk     r|                    d          }|                    d          }|                    d	          x}dk     rt          j
        }t          |d
f|df|dfg          }	d t          |	          D             }	d}
d|v rd|                                 v rd}
dx}}t          ||	d
                            |
z   }t          |          dk    rIt          ||	d                            }t          |          dk    rt          ||	d                            }t          j        |||          S )a  Parse a time from a string.

    This function uses the time format for the locale as a hint to determine
    the order in which the time fields appear in the string.

    If an explicit format is provided, the function will use it to parse
    the time instead.

    >>> parse_time('15:30:00', locale='en_US')
    datetime.time(15, 30)
    >>> parse_time('15:30:00', format='H:mm:ss')
    datetime.time(15, 30)

    :param string: the string containing the time
    :param locale: a `Locale` object or a locale identifier. Defaults to the system time locale.
    :param format: the format to use, either an explicit time format,
                   or one of "full", "long", "medium", or "short"
                   (see ``get_time_format``)
    :return: the parsed time
    :rtype: `time`
    rH  rI  r   ru   hr   krL  sHrO  Sc                &    i | ]\  }}|d          |S rR  rD  rS  s      r'   rV  zparse_time.<locals>.<dictcomp>B  rW  r)   ar3  rX  r   r   )rY  rZ  r@  r~   r   r   r_  ra  r`  mathinfrb  rc  r3   r   r-   r5   )rE  r]   r   rd  rg  rh  hour_idxmin_idxsec_idxrl  hour_offsetr   r   r   s                 r'   
parse_timer|    s   4 j6**G ;9::: 444VF;;;F##""$$Js##H!||##C((s##G??3'''1,,(xo~~FGGG@@Yw-?-?@@@G K
jTV\\^^33 FVwws|$%%3D
7||aWWS\*++w<<!.//F=vv...r)   c                  :    e Zd ZddZddZddZdd
Z	 dddZdS )rr   r   r1   r   r   c                "    || _         || _        d S r  )r   r   )selfr   r   s      r'   __init__zDateTimePattern.__init__X  s    r)   r   c                B    dt          |           j         d| j        dS )N<r   >)r*  rA  r   r  s    r'   __repr__zDateTimePattern.__repr__\  s&    :4::&::::::r)   c                    | j         }|S r  r   )r  pats     r'   __str__zDateTimePattern.__str___  s    l
r)   r   c                N    t          |t                    st          S | j        |z  S r  )r0   r   NotImplementedr   )r  r   s     r'   __mod__zDateTimePattern.__mod__c  s'    %00 	"!!{U""r)   Nr-   datetime.date | datetime.timer]   r^   r   r   c                *    | t          |||          z  S r  )r   )r  r-   r]   r   s       r'   r   zDateTimePattern.applyh  s     nXv~FFFFr)   )r   r1   r   r   r   r1   )r   r   r   r1   r  )r-   r  r]   r^   r   r   r   r1   )rA  rB  rC  r  r  r  r  r   rD  r)   r'   rr   rr   V  s           ; ; ; ;   # # # # 04	G G G G G G Gr)   c                      e Zd Z	 d+d,d
Zd-dZd.dZd/dZd/dZd/dZd/dZ	d/dZ
d0d/dZd1dZd2dZd/dZd1dZd Zd/dZd3d"Zd+d4d$Zd5d%Zd5d&Zd+d6d*ZdS )7r   Nr  r  r]   Locale | strr   r   r   Nonec                J   t          |t          j        t          j        t          j        f          sJ t          |t          j        t          j        f          r"|j        |                    t                    }|| _        t          j	        |          | _
        || _        d S )Nr"   )r0   r-   rC   r5   r#   r%   r4   r  r
   r`   r]   r   )r  r  r]   r   s       r'   r  zDateTimeFormat.__init__s  s     %(-1BHM!RSSSSSeh/?@@ 	.U\EYMMM--E
l6**,r)   r   r1   c                   |d         }t          |          }|dk    r|                     ||          S |dv r|                     ||          S |dv r|                     ||          S |dv r|                     ||          S |dv r|                     ||          S |dk    r |                     | j        j        |          S |dk    r| 	                    |          S |d	k    r| 
                                S |d
v r|                     ||          S |dv r|                     ||          S |dk    rL| j        j        dz  dk    r|                     d|          S |                     | j        j        dz  |          S |dk    r |                     | j        j        |          S |dk    r#|                     | j        j        dz  |          S |dk    rF| j        j        dk    r|                     d|          S |                     | j        j        |          S |dk    r |                     | j        j        |          S |dk    r |                     | j        j        |          S |dk    r|                     |          S |dk    r|                     |          S |dv r|                     ||          S t'          d|          )Nr   G)rK  rN  uQqrO  L)wWr  rP  F)ErW   c)ru  bBro  rX  rr  Krp  r   rL  rq  rs  A)zr   vVxXOzUnsupported date/time field )r   
format_eraformat_yearformat_quarterformat_monthformat_weekr   r  r   format_day_of_yearformat_day_of_week_in_monthformat_weekdayformat_periodr   r   r   format_frac_secondsformat_milliseconds_in_dayformat_timezoneKeyError)r  r   charnums       r'   __getitem__zDateTimeFormat.__getitem__  s   Aw$ii3;;??4---_$$##D#...Z&&tS111Z$$T3///Z##D#...S[[;;tz~s333S[[**3///S[[33555_$$&&tS111_$$%%dC000S[[z#q(({{2s+++{{4:?R#7===S[[;;tz444S[[;;tz3S999S[[z!##{{2s+++{{4:?C888S[[;;tz0#666S[[;;tz0#666S[[++C000S[[223777888''c222B$BBCCCr)   r  r3   c                   t          |          d         }|dk    r| j        j        S |dk    r| j        j        S |dk    r| j        j        S |dk    r| j        j        S |dk    r| j        j        dz  pdS |dk    r| j        j        S |d	k    rt          | j        j        dk              S t          d
|d| j                  )Nr   rK  rO  r  rr  ro  rX  rL  ru  zNot implemented: extracting z from )	r1   r  r   r   r   r   r   r3   r6  )r  r  s     r'   r"  zDateTimeFormat.extract  s    4yy|3;;:?"S[[:##S[[:>!S[[:?"S[[:?R'-2-S[[:$$S[[tz",---%&aT&a&aSWS]&a&abbbr)   r  c                    ddddt          d|                   }t          | j        j        dk              }t	          || j                  |         S )NabbreviatedrY   r            r  r   )r   r3   r  r   rq   r]   )r  r  r  rZ   eras        r'   r  zDateTimeFormat.format_era  sK    !f::3q#;;G$*/Q&''UDK0055r)   c                x   | j         j        }|                                rs| j         j        }|dk    r.| j         j        dk     r|                                 dk    r|dz  }n3|dk    r-| j         j        dk    r|                                 dk    r|dz  }|                     ||          }|dk    r
|dd          }|S )Nr      4   rX     r   )r  r   isupperr   r   get_week_of_yearr   )r  r  r  r  r   r   s         r'   r  zDateTimeFormat.format_year  s    
<<>> 	J$Ezzdjnq00T5J5J5L5LPR5R5R
""!4!49N9N9P9PTU9U9U
{{5#&&!889Dr)   c                    | j         j        dz
  dz  dz   }|dk    rd||fz  S dddd|         }d	d
d|         }t          ||| j                  |         S )Nr   r  r   %0*dr  rY   r   r  r   r   r  )r  r   rm   r]   )r  r  r  quarterrZ   r\   s         r'   r  zDateTimeFormat.format_quarter  sr    :#a'A-1!88S'N**!f::3? }55d; ==gFFr)   c                    |dk    rd|| j         j        fz  S dddd|         }ddd	|         }t          ||| j                  | j         j                 S )
Nr   r  r  rY   r   r  r   r   r  )r  r   rj   r]   )r  r  r  rZ   r\   s        r'   r  zDateTimeFormat.format_month  sd    !88S$*"2333!f::3? }55d;ugt{;;DJ<LMMr)   c                    |                                 r*|                                 }|                     ||          S |                                 }t	          |          S r  )islowerr  r   get_week_of_monthr1   )r  r  r  r   s       r'   r  zDateTimeFormat.format_week  sT    <<>> 	((**D;;tS)))))++Dt99r)   r  r  c                \   |dk     r[|                                 rEd| j        j        z
  | j                                        z   }|                     |dz  dz   |          S d}| j                                        }ddddd|         }|d	k    rd
nd}t          ||| j                  |         S )a  
        Return weekday from parsed datetime according to format pattern.

        >>> from datetime import date
        >>> format = DateTimeFormat(date(2016, 2, 28), Locale.parse('en_US'))
        >>> format.format_weekday()
        u'Sunday'

        'E': Day of week - Use one through three letters for the abbreviated day name, four for the full (wide) name,
             five for the narrow name, or six for the short name.
        >>> format.format_weekday('E',2)
        u'Sun'

        'e': Local day of week. Same as E except adds a numeric value that will depend on the local starting day of the
             week, using one or two letters. For this example, Monday is the first day of the week.
        >>> format.format_weekday('e',2)
        '01'

        'c': Stand-Alone local day of week - Use one letter for the local numeric value (same as 'e'), three for the
             abbreviated day name, four for the full (wide) name, five for the narrow name, or six for the short name.
        >>> format.format_weekday('c',1)
        '1'

        :param char: pattern format character ('e','E','c')
        :param num: count of format character

        r  r  r   r  rY   r   r   )r  r  r     r  r   r   )r  r]   first_week_dayr  weekdayr   rg   )r  r  r  r  r  rZ   r\   s          r'   r  zDateTimeFormat.format_weekday  s    8 77||~~ 7DK669K9K9M9MM{{519q=#666C*$$&&!fgFFsK#'3;;--HUGT[99'BBr)   c                R    |                      |                                 |          S r  )r   get_day_of_year)r  r  s     r'   r  z!DateTimeFormat.format_day_of_year  s"    {{4//113777r)   c                F    t          | j        j        dz
  dz  dz             S )Nr   r  )r1   r  r   r  s    r'   r  z*DateTimeFormat.format_day_of_week_in_month  s#    DJNQ&1,q0111r)   c                J   ddddt          d|                   dddg}|dk    r| j        j        dk    rdnd	}d
}n%t          | j        | j                  }|dk    rd
nd}|D ]'}t          ||| j                  }||v r
||         c S (t          d| d| j                   )u  
        Return period from parsed datetime according to format pattern.

        >>> from datetime import datetime, time
        >>> format = DateTimeFormat(time(13, 42), 'fi_FI')
        >>> format.format_period('a', 1)
        u'ip.'
        >>> format.format_period('b', 1)
        u'iltap.'
        >>> format.format_period('b', 4)
        u'iltapäivä'
        >>> format.format_period('B', 4)
        u'iltapäivällä'
        >>> format.format_period('B', 5)
        u'ip.'

        >>> format = DateTimeFormat(datetime(2022, 4, 28, 6, 27), 'zh_Hant')
        >>> format.format_period('a', 1)
        u'上午'
        >>> format.format_period('B', 1)
        u'清晨'

        :param char: pattern format character ('a', 'b', 'B')
        :param num: count of format character

        r  rY   r   r  r  ru  rX  r3  r2  r   r   r  r   )r\   rZ   r]   zCould not format period z in )r   r  r   r>  r]   rc   r   )r  r  r  widthsperiodr\   rZ   period_namess           r'   r  zDateTimeFormat.format_period  s    6 $8<<SC[[I(M33;;!Z_22TTFGG"4:dkBBBF"&#++hh=G 	, 	,E+G5QUQ\]]]L%%#F++++ &MFMMMMNNNr)   c                t    | j         j        dz  }|                     t          ||          d|z  z  |          S )z Return fractional seconds.

        Rounds the time's microseconds to the precision given by the number         of digits passed in.
        i@B 
   )r  microsecondr   r   )r  r  r  s      r'   r  z"DateTimeFormat.format_frac_secondsC  s:     
&0{{5,,r3w6<<<r)   c                    | j         j        dz  | j         j        dz  z   | j         j        dz  z   | j         j        dz  z   }|                     ||          S )Ni  i`  i6 )r  r  r   r   r   r   )r  r  msecss      r'   r  z)DateTimeFormat.format_milliseconds_in_dayL  sX    
&$.1BT1IIJ%&(,
'(AB{{5#&&&r)   c                j   ddddt          d|                   }| j        }| j        r*t          j                            | j        | j                  }|dk    rt          ||| j                  S |dk    r5|d	k    rt          ||| j        d
          S t          ||| j                  S |dk    r|dk    rt          ||| j                  S d S |dk    rt          |j        || j                  S |dk    r|dk    rt          |j        |d
| j                  S |dk    rt          |j        | j        d
          S |dk    rt          |j        | j        d
          S t          |j        | j                  S |dk    rX|dk    rt          |d| j        d
          S |dv rt          |d| j        d
          S |dv rt          |d| j        d
          S d S |dk    rS|dk    rt          |d| j                  S |dv rt          |d| j                  S |dv rt          |d| j                  S d S d S )Nr   r   r   r  r  r  r   r   r  T)r]   r   r  r  r  r  r   )r   r]   r   )r]   r   )r]   r   r  r   )rZ   r]   r   )r   r  )r  r  r  rp   )
r   r  r   r-   rB   r   r]   r   r#   r   )r  r  r  rZ   r  s        r'   r  zDateTimeFormat.format_timezoneQ  s   955c!SkkB
 
 	O%--d.A4:NNE3;;$UE$+FFFFS[[axx'uT[SWXXXX#E5EEEES[[axx'uT[IIII x S[[$U\5,0K9 9 9 9S[[axx(u26t{L L L L(dkW[\\\\,U\$+[_````(dkJJJJS[[axx'_T[157 7 7 7'WT[157 7 7 7'Yt{157 7 7 7  S[[axx'_T[YYYY'WT[QQQQ'Yt{SSSS [
 r)   r   lengthc                    d||fz  S )Nr  rD  )r  r  r  s      r'   r   zDateTimeFormat.format  s    ''r)   rC   c                X    || j         }||                    dd          z
  j        dz   S )Nr   )r   r   )r  r%   rf   )r  rC   s     r'   r  zDateTimeFormat.get_day_of_year  s1    <:Dt||!|3339A==r)   c                "   |                      | j                  }|                     |          }|dk    r_t          j        | j        j        dz
  dd          }|                     |                      |          |                                          }nz|dk    rtt          j        | j        j        dz   dd                                          }|                     d|          dk    r%d|| j        j        z
  dz  z
  | j        j	        k    rd}|S )zReturn the week of the year.r   r   rX     r      r  )
r  r  get_week_numberr-   rC   r   r  r]   r  r   )r  day_of_yearr   rC   r  s        r'   r  zDateTimeFormat.get_week_of_year  s    **4:66##K00199=1!4b"==D''(<(<T(B(B(,8 8DDBYYmDJOa$7A>>FFHHG##Aw//144'DK$>>!CCtz~UUr)   c                @    |                      | j        j                  S )zReturn the week of the month.)r  r  r   r  s    r'   r  z DateTimeFormat.get_week_of_month  s    ##DJN333r)   day_of_periodday_of_week
int | Nonec                    || j                                         }|| j        j        z
  |z
  dz   dz  }|dk     r|dz  }||z   dz
  dz  }d|z
  | j        j        k    r|dz  }|S )aA  Return the number of the week of a day within a period. This may be
        the week number in a year or the week number in a month.

        Usually this will return a value equal to or greater than 1, but if the
        first week of the period is so short that it actually counts as the last
        week of the previous period, this function will return 0.

        >>> date = datetime.date(2006, 1, 8)
        >>> DateTimeFormat(date, 'de_DE').get_week_number(6)
        1
        >>> DateTimeFormat(date, 'en_US').get_week_number(6)
        2

        :param day_of_period: the number of the day in the period (usually
                              either the day of month or the day of year)
        :param day_of_week: the week day; if omitted, the week day of the
                            current date is assumed
        Nr   r  r   )r  r  r]   r  min_week_days)r  r  r  	first_dayweek_numbers        r'   r  zDateTimeFormat.get_week_number  s    & *,,..K 4;#=="#%&'*+,	q==NI$y014:y=DK5551Kr)   r  )r  r  r]   r  r   r   r   r  )r   r1   r   r1   )r  r1   r   r3   )r  r1   r  r3   r   r1   )r  r  )r  r3   r   r1   r  )r  r   r  r3   r   r1   )rC   r   r   r3   )r   r3   )r  r3   r  r  r   r3   )rA  rB  rC  r  r  r"  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  rD  r)   r'   r   r   q  s        04	- - - - -0D 0D 0D 0Ddc c c c&6 6 6 6
   G G G GN N N N   $C $C $C $C $CL8 8 8 82 2 2 2'O 'O 'O 'OR= = = =' ' '
1T 1T 1T 1Tf( ( ( (> > > > >
   4 4 4 4      r)   r   r  )r   r   r  r  r  rK  rN  r  r  r  rO  r  r  r   r   r  r  rP  )r   r   r  r  gr  )r   r   r  r  r  r  rW   r  )r   r  r  r  r  ru  r  r  ro  rr  r  rp  rL  rq  rs  r  r  )r   r   r  r  r   r  r  r  r  r  r  zdict[str, list[int] | None]PATTERN_CHARS(GyYuUQqMLlwWdDFgEecabBChHKkjJmsSAzZOvVXxr   str | DateTimePatternc                N    t          | t                    r| S t          |           S )a  Parse date, time, and datetime format patterns.

    >>> parse_pattern("MMMMd").format
    u'%(MMMM)s%(d)s'
    >>> parse_pattern("MMM d, yyyy").format
    u'%(MMM)s %(d)s, %(yyyy)s'

    Pattern can contain literal strings in single quotes:

    >>> parse_pattern("H:mm' Uhr 'z").format
    u'%(H)s:%(mm)s Uhr %(z)s'

    An actual single quote can be used by using two adjacent single quote
    characters:

    >>> parse_pattern("hh' o''clock'").format
    u"%(hh)s o'clock"

    :param pattern: the formatting pattern to parse
    )r0   rr   _cached_parse_patternr  s    r'   r   r     s)    * '?++  )))r)   i   )maxsizec                   g }t          |           D ]\  }}|dk    r*|                    |                    dd                     5|dk    rI|\  }}t          |         }|r||vrt	          d||z            |                    d||z  z             t          d|           t          | d                    |                    S )	Nchars%z%%r(  zInvalid length for field: z%%(%s)szUnknown token type: r   )tokenize_patternappendr%   r  r   r6  rr   r#  )r   resulttok_type	tok_value	fieldcharfieldnumlimits          r'   r  r    s    F/88 
I 
I)wMM)++C667777  "+Ix!),E X.. !Vi(>R!V!VWWWMM)y8';<====%&GX&G&GHHH7BGGFOO444r)   'list[tuple[str, str | tuple[str, int]]]c                \   g d}g dgdgfd}fd}|                      dd          D ]}||dk    r"d         r |             nr
 |             g },|t          v rFr
 |             |d         k    rdxx         d	z  cc<   ^d         r
 |             |d<   d	d<   {d         r
 |                                 |           |3|dk    r                    |           d}|                    |           ىd         r |             nr
 |             S )
ay  
    Tokenize date format patterns.

    Returns a list of (token_type, token_value) tuples.

    ``token_type`` may be either "chars" or "field".

    For "chars" tokens, the value is the literal value.

    For "field" tokens, the value is a tuple of (field character, repetition count).

    :param pattern: Pattern string
    :type pattern: str
    :rtype: list[tuple]
    Nr   r   c                                          dd                                                   dd          f            d d = d S )Nr  r    r   )r  r#  r%   )charbufr  s   r'   append_charsz&tokenize_pattern.<locals>.append_chars  sE    w 0 0 8 8s C CDEEEAAAJJJr)   c                 f                         d d         d         ff           d d<   dd<   d S )Nr(  r   r   )r  )r  r  r  s   r'   append_fieldz&tokenize_pattern.<locals>.append_field  s=    w1x{ ;<===	!r)   ''r  r   r   )r%   r  r  extend)	r   quotebufr	  r  r  r  r  r  r  s	        @@@@r'   r  r     s     FHGIsH           
 d++ & &s{{Q< # LNNNN # LNNN&& # LNNN9Q<''QKKK1$KKKK | '$#'IaL"#HQKKQ< # LNNNt$$$$!s{{x(((%%%| 	 Mr)   tokens+Iterable[tuple[str, str | tuple[str, int]]]c                X   g }| D ]\  }}|dk    r%|                     |d         |d         z             0|dk    r[t          d |D                       s|                     |           e|                     d|                    dd          z             d	                    |          S )
z
    Turn a date format pattern token stream back into a string.

    This is the reverse operation of ``tokenize_pattern``.

    :type tokens: Iterable[tuple]
    :rtype: str
    r(  r   r   r  c              3  (   K   | ]}|t           v V  d S r  )r  )r  chs     r'   r  z%untokenize_pattern.<locals>.<genexpr>S  s'      ??rr]*??????r)   z'%s'r   r  r   )r  anyr%   r#  )r  outputr  r   s       r'   untokenize_patternr  E  s     F% E E)wMM)A,156666  ??Y????? Ei((((fy'8'8d'C'CCDDD776??r)   	list[str]c                H   t                      }g g}t          |           D ]v\  }}|dk    rN|d         |v r)|                    g            |                                 |                    |d                    |d                             ||f           wd |D             S )u  
    Split an interval-describing datetime pattern into multiple pieces.

    > The pattern is then designed to be broken up into two pieces by determining the first repeating field.
    - https://www.unicode.org/reports/tr35/tr35-dates.html#intervalFormats

    >>> split_interval_pattern(u'E d.M. – E d.M.')
    [u'E d.M. – ', 'E d.M.']
    >>> split_interval_pattern("Y 'text' Y 'more text'")
    ["Y 'text '", "Y 'more text'"]
    >>> split_interval_pattern(u"E, MMM d – E")
    [u'E, MMM d – ', u'E']
    >>> split_interval_pattern("MMM d")
    ['MMM d']
    >>> split_interval_pattern("y G")
    ['y G']
    >>> split_interval_pattern(u"MMM d – d")
    [u'MMM d – ', u'd']

    :param pattern: Interval pattern string
    :return: list of "subpatterns"
    r(  r   c                ,    g | ]}t          |          S rD  )r  )r  r  s     r'   
<listcomp>z*split_interval_pattern.<locals>.<listcomp>}  s!    ;;;6v&&;;;r)   )setr  r  clearadd)r   seen_fieldspartsr  r   s        r'   split_interval_patternr!  Z  s    0 %%KDE/88 0 0)w|{**R   !!###OOIaL)))b	(I.////;;U;;;;r)   optionsIterable[str]allow_different_fieldsc                   t          d |D                       }d| v r/t          d |D                       s|                     dd          } d| v r/t          d |D                       s|                     dd          } d| v r/t          d	 |D                       s|                     dd
          } d| v r/t          d |D                       s|                     dd          } d| v r/t          d |D                       s|                     dd          } t          d t	          |           D                       j        }d}d}|D ]}t          d t	          |          D                       j        }d}t          D ]r}	 ||	d          }
 ||	d          }|
|k    r!|dk    s|
dk    r|sd} n@|dz  }9|	dk    r|
dk    r|dk    s|
dk    r|dk    r|dz  }]|t          |
|z
            z  }s|s|r||k     r|}|}|dk    r n|S )ae  
    Find the closest match for the given datetime skeleton among the options given.

    This uses the rules outlined in the TR35 document.

    >>> match_skeleton('yMMd', ('yMd', 'yMMMd'))
    'yMd'

    >>> match_skeleton('yMMd', ('jyMMd',), allow_different_fields=True)
    'jyMMd'

    >>> match_skeleton('yMMd', ('qyMMd',), allow_different_fields=False)

    >>> match_skeleton('hmz', ('hmv',))
    'hmv'

    :param skeleton: The skeleton to match
    :type skeleton: str
    :param options: An iterable of other skeletons to match against
    :type options: Iterable[str]
    :param allow_different_fields: Whether to allow a match that uses different fields
                                   than the skeleton requested.
    :type allow_different_fields: bool

    :return: The closest skeleton match, or if no match was found, None.
    :rtype: str|None
    c              3     K   | ]}||V  	d S r  rD  r  options     r'   r  z!match_skeleton.<locals>.<genexpr>  s'      <<V<V<<<<<<r)   r  c              3     K   | ]}d |v V  	dS )r  NrD  r'  s     r'   r  z!match_skeleton.<locals>.<genexpr>  &      "G"GV3&="G"G"G"G"G"Gr)   r  rp  c              3     K   | ]}d |v V  	dS )rp  NrD  r'  s     r'   r  z!match_skeleton.<locals>.<genexpr>  r*  r)   rr  r  c              3     K   | ]}d |v V  	dS )r  NrD  r'  s     r'   r  z!match_skeleton.<locals>.<genexpr>  r*  r)   ro  ru  c              3     K   | ]}d |v V  	dS )ru  NrD  r'  s     r'   r  z!match_skeleton.<locals>.<genexpr>  r*  r)   r   r  c              3     K   | ]}d |v V  	dS )r  NrD  r'  s     r'   r  z!match_skeleton.<locals>.<genexpr>  r*  r)   c              3  >   K   | ]}|d          dk    |d         V  dS r   r(  r   NrD  r  ts     r'   r  z!match_skeleton.<locals>.<genexpr>  s/       ] ]!QqTU\__1____ ] ]r)   Nc              3  >   K   | ]}|d          dk    |d         V  dS r0  rD  r1  s     r'   r  z!match_skeleton.<locals>.<genexpr>  s/      "]"]AQqTU\__1Q4____"]"]r)   r   i   rO  r      )rb  r  r%   dictr  r   r  r   )r   r"  r$  get_input_field_widthbest_skeletonbest_distancer(  get_opt_field_widthdistancer(  input_width	opt_widths               r'   r   r     s   F <<'<<<<<G
hs"G"Gw"G"G"GGG##C--
hs"G"Gw"G"G"GGG##C--
hs"G"Gw"G"G"GGG##C--
hs"G"Gw"G"G"GGG##C,,
hs"G"Gw"G"G"GGG##C,,  ] ]/?/I/I ] ] ]]]aMM  ""]"]1A&1I1I"]"]"]]]a" 	9 	9E//q99K++E155Ii''A~~!1!1- !FEF"#K!OO	QK[\L\L\ajmnananE!Ci 7888 	 	%= 8 8"M$Mq==E  r)   )r   r   r   r   r   r   )r*   r   r   r+   )r*   r   r   r1   )r>   r   r   r   r  )r   r   r#   rE   r   r   )r5   rI   r#   rE   r   rJ   )r:   rN   r   r   )rY   r   N)rZ   r[   r\   r   r]   r^   r   r   )rY   r   N)rZ   rd   r\   r   r]   r^   r   r   )rY   N)rZ   r[   r]   r^   r   r   )r   N)r   r   r]   r^   r   rr   )Nr   NF)
r-   r   rZ   r   r]   r^   r   r   r   r1   )NNF)r*   r   r]   r^   r   r   r   r1   )Nr   FNNF)r*   r   rZ   r   r   r   r]   r^   r   r   r   r   r   r1   )Nr   N)rC   r   r   r   r]   r^   r   r1   )Nr   NN)
r-   r   r   r   r#   rE   r]   r^   r   r1   )
r5   r   r   r   r#   rE   r]   r^   r   r1   )NNTN)r   r1   r-   r   r#   rE   r   r   r]   r^   r   r1   )r   r   Fr   N)r   r   r   r   r   r@   r   r   r   r   r]   r^   r   r1   )r  r   r  r   r   r  r#   rE   r]   r
   r   r1   )r  r   r  r   r   r  r#   rE   r   r   r]   r^   r   r1   )NNN)
r5   r   r#   rE   r*  r+  r]   r^   r   r1   )Nr   )rE  r1   r]   r^   r   r   r   rF  )rE  r1   r]   r^   r   r   r   rJ   )r   r  r   rr   )r   r1   r   rr   )r   r1   r   r  )r  r  r   r1   )r   r1   r   r  )F)r   r1   r"  r#  r$  r   r   r  )V__doc__
__future__r   rv  rY  r   	functoolsr   typingr   r   r   rP   ModuleNotFoundErrorrS   r-   collections.abcr   babelr	   
babel.corer
   r   r   babel.localedatar   typing_extensionsr   rC   r5   r@   r   __annotations__r   r   r#   r1   r3   r   r   rQ   utcr4   r/   r   r(   r8   r=   r6   rH   rM   r2   rc   rg   rj   rm   rq   rv   r{   r~   r   r   r   r   r   r   r   r   r  r  r)  r>  r   r@  rm  r|  rr   r   r  r!  r   r  r  r  r!  r   rD  r)   r'   <module>rI     sb	    " # " " " " "  				        6 6 6 6 6 6 6 6 6 6KKKK   DOOOOO  $ $ $ $ $ $       9 9 9 9 9 9 9 9 9 9 + + + + + + d++++++"-(-7%?$FHFFFF'./P'QQQQQ!"9:H::::%.@3FLx}\_ccKcccc - 


.
#
#   "   4? ? ? ?( ( ( (V    @ &*    >; ; ; ; ;B 7=%"&G G G G G$ @F "&@ @ @ @ @0 7= "&B B B B B, 7= "&D D D D D, 7="&7 7 7 7 7$ %-"&@ @ @ @ @( %-"&    * %-"&@ @ @ @ @( BH"&	9, 9, 9, 9, 9,z !%"&M M M M Mb !%&,"&FJw> w> w> w> w>v "&*2"&#' #' #' #' #'N *2%)"&	'= '= '= '= '=V >B*2%)"&	GN GN GN GN GNX %)"&/= /= /= /= /=d0     X`;A"&v v v v vr   @  %)"&fK fK fK fK fKV &*(,"&	I I I I IX	 	 	 	 	 	 	 	 #'*2J+ J+ J+ J+ J+^ #'*2>/ >/ >/ >/ >/BG G G G G G G G6J J J J J J J JZ
...D.t. . . 	. 	.
 !Q.
 qc. !Q. iii. "%qc. ,/. 			. !"4"4"4. 7:???. . . . 14___. !Q. q!f. "Aq6. ,/A. !Q. !Q. d.  . . OOO. .11a&. ;>1v. . OOO. . .1///. .    & @ * * * *4 45 5 5 5"B B B BJ   *#< #< #< #<LO O O O O O Os   , ::