
    ih                     <   d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZm
Z
mZmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZmZ ddlmZ ddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1 ee2e	e2   f   Z3eee4e5e5f   e4e5e5e5f   f   Z6eee
e2e7e5f   Z8ee4e5e5e2f   e4e4e5e5e2f   df   f   Z9eee4e5e5e5e5f   e4e5e5e5e5e5f   f   e4ee4e5e5e5e5f   e4e5e5e5e5e5f   f   df   f   Z:ee5e	e5   f   Z; G d de<ee2f         Z= G d de=      Z>y))DateLikeHolidayBase
HolidaySum    N)bisect_leftbisect_right)isleap)Iterable)datedatetime	timedeltatimezone)cached_property)gettexttranslation)Path)AnyLiteralOptionalUnioncast)parse)MONTUEWEDTHUFRISATSUN
_timedelta_get_nth_weekday_from_get_nth_weekday_of_monthDAYSMONTHSWEEKDAYS)HOLIDAY_NAME_DELIMITERPUBLICDEFAULT_START_YEARDEFAULT_END_YEAR)_normalize_arguments_normalize_tuple.c                   
    e Zd ZU dZeed<   	 eed<   	 dZeedf   ed<   	 i Ze	eef   ed<   	 e
e   ed<   	 eed	<   	 eed
<   	 dZee   ed<   	 i Ze	eeeef   f   ed<   	 dZeedf   ed<   	 eehZe
e   ed<   	 e
e   ed<   	 eZeed<   	 dZee   ed<   	  e
       Ze
e   ed<   	 efZeedf   ed<   	 dZeedf   ed<   	 eZeed<   	 e Z!eed<   	 dZ"ee#d       ed<   	 	 	 	 	 	 	 	 	 dddee$   d	ed
edee   dee   dee   dee   dee%   ddf fdZ&deed df   dd fd Z'defd!Z(d"e)defd#Z*de)defd$Z+d% Z,d"e-de.fd&Z/de	ee.f   fd'Z0d"e-defd(Z1de)defd)Z2de.dd fd*Z3deeee.df   f   f fd+Z4def fd,Z5d"ed-e.ddfd.Z6d"e-d-eddfd/Z7de	ee.f   ddfd0Z8def fd1Z9e:d2        Z;e<d3        Z=e<d4        Z>e:d5        Z?e@de	eeAf   fd6       ZBded7ZCdefd8ZDd9edee   fd:ZEdfd;ZFd<edefd=ZGd>ede
e   fd?ZHdefd@ZIdefdAZJdefdBZKdefdCZLdefdDZMdefdEZNdefdFZOdG ZPdHeddfdIZQdJ ZRdK ZSdLee	e-ef   eAe-   e-f   ddfdMZTdN ZUdgd"e-dOeee.f   deee.f   fdPZVd"e-deAe   fdQZW	 dhdRedSedTedeAe   fdUZX	 	 didVee-   dWeYdX   deeeef      fdYZZd"e-dZedefd[Z[d\e-d]e-defd^Z\d"e-defd_Z]d"e-defd`Z^dgd"e-dOeee.f   deee.f   fdaZ_djdRedSedeAe   fdbZ`dLee	e-ef   eAe-   e-f   ddfdcZa xZbS )kr   a  Represent a dictionary-like collection of holidays for a specific country or region.

    This class inherits from `dict` and maps holiday dates to their names. It supports
    customization by country and, optionally, by province or state (subdivision). A date
    not present as a key is not considered a holiday (or, if `observed` is `False`, not
    considered an observed holiday).

    Keys are holiday dates, and values are corresponding holiday names. When accessing or
    assigning holidays by date, the following input formats are accepted:

    * `datetime.date`
    * `datetime.datetime`
    * `float` or `int` (Unix timestamp)
    * `str` of any format recognized by `dateutil.parser.parse()`

    Keys are always returned as `datetime.date` objects.

    To maximize performance, the holiday list is lazily populated one year at a time.
    On instantiation, the object is empty. Once a date is accessed, the full calendar
    year for that date is generated, unless `expand` is set to `False`. To pre-populate
    holidays, instantiate the class with the `years` argument:

        us_holidays = holidays.US(years=2020)

    It is recommended to use the
    [country_holidays()][holidays.utils.country_holidays] function for instantiation.

    Example usage:

        >>> from holidays import country_holidays
        >>> us_holidays = country_holidays('US')
        # For a specific subdivisions (e.g. state or province):
        >>> california_holidays = country_holidays('US', subdiv='CA')

    The below will cause 2015 holidays to be calculated on the fly:

        >>> from datetime import date
        >>> assert date(2015, 1, 1) in us_holidays

    This will be faster because 2015 holidays are already calculated:

        >>> assert date(2015, 1, 2) not in us_holidays

    The `HolidayBase` class also recognizes strings of many formats
    and numbers representing a POSIX timestamp:

        >>> assert '2014-01-01' in us_holidays
        >>> assert '1/1/2014' in us_holidays
        >>> assert 1388597445 in us_holidays

    Show the holiday's name:

        >>> us_holidays.get('2014-01-01')
        "New Year's Day"

    Check a range:

        >>> us_holidays['2014-01-01': '2014-01-03']
        [datetime.date(2014, 1, 1)]

    List all 2020 holidays:

        >>> us_holidays = country_holidays('US', years=2020)
        >>> for day in sorted(us_holidays.items()):
        ...     print(day)
        (datetime.date(2020, 1, 1), "New Year's Day")
        (datetime.date(2020, 1, 20), 'Martin Luther King Jr. Day')
        (datetime.date(2020, 2, 17), "Washington's Birthday")
        (datetime.date(2020, 5, 25), 'Memorial Day')
        (datetime.date(2020, 7, 3), 'Independence Day (observed)')
        (datetime.date(2020, 7, 4), 'Independence Day')
        (datetime.date(2020, 9, 7), 'Labor Day')
        (datetime.date(2020, 10, 12), 'Columbus Day')
        (datetime.date(2020, 11, 11), 'Veterans Day')
        (datetime.date(2020, 11, 26), 'Thanksgiving Day')
        (datetime.date(2020, 12, 25), 'Christmas Day')

    Some holidays are only present in parts of a country:

        >>> us_pr_holidays = country_holidays('US', subdiv='PR')
        >>> assert '2018-01-06' not in us_holidays
        >>> assert '2018-01-06' in us_pr_holidays

    Append custom holiday dates by passing one of the following:

    * A dict mapping date values to holiday names (e.g. `{'2010-07-10': 'My birthday!'}`).
    * A list of date values (`datetime.date`, `datetime.datetime`, `str`, `int`, or `float`);
      each will be added with 'Holiday' as the default name.
    * A single date value of any of the supported types above; 'Holiday' will be used as
      the default name.

    ```python
    >>> custom_holidays = country_holidays('US', years=2015)
    >>> custom_holidays.update({'2015-01-01': "New Year's Day"})
    >>> custom_holidays.update(['2015-07-01', '07/04/2015'])
    >>> custom_holidays.update(date(2015, 12, 25))
    >>> assert date(2015, 1, 1) in custom_holidays
    >>> assert date(2015, 1, 2) not in custom_holidays
    >>> assert '12/25/2015' in custom_holidays
    ```

    For special (one-off) country-wide holidays handling use
    `special_public_holidays`:

        special_public_holidays = {
            1977: ((JUN, 7, "Silver Jubilee of Elizabeth II"),),
            1981: ((JUL, 29, "Wedding of Charles and Diana"),),
            1999: ((DEC, 31, "Millennium Celebrations"),),
            2002: ((JUN, 3, "Golden Jubilee of Elizabeth II"),),
            2011: ((APR, 29, "Wedding of William and Catherine"),),
            2012: ((JUN, 5, "Diamond Jubilee of Elizabeth II"),),
            2022: (
                (JUN, 3, "Platinum Jubilee of Elizabeth II"),
                (SEP, 19, "State Funeral of Queen Elizabeth II"),
            ),
        }

        def _populate(self, year):
            super()._populate(year)

            ...

    For more complex logic, like 4th Monday of January, you can inherit the
    [HolidayBase][holidays.holiday_base.HolidayBase] class and define your own `_populate()`
    method.
    See documentation for examples.
    countrymarket .subdivisionssubdivisions_aliasesyearsexpandobservedNsubdivspecial_holidays_deprecated_subdivisionsweekendweekend_workdaysdefault_categorydefault_language
categoriessupported_categoriessupported_languages
start_yearend_yearparent_entityprovstatelanguagereturnc	           
         t         |           | j                  r#| j                  | j                  vrt	        d      | j                  s|st	        d      t        t        |      xs | j                  h}|j                  | j                        x}	rt	        ddj                  |	       d      |xs |xs |x}r8t        |t              rt        |      }t        | j                        }
t        | j                  |
z   | j                  z   | j                   r| j                   j                  ndz         }t        | t"              s||vrt%        d| j&                   d|       |xs |x}rt)        j*                  d	| d
t,               || j                  v r[t)        j*                  ddj                  t/        | j                               ddj                  t/        |
             dt,               t1        | dd      x}r3t1        | dd      rt1        | dd      st	        d| j&                   d      || _        || _        t1        | dd      | _        || _        || _        || _        || _        t1        | dt                     | _         t        t        |      | _!        | jE                          | jB                  D ]  }| jG                  |        y)a^
  
        Args:
            years:
                The year(s) to pre-calculate public holidays for at instantiation.

            expand:
                Whether the entire year is calculated when one date from that year
                is requested.

            observed:
                Whether to include the dates when public holiday are observed
                (e.g. a holiday falling on a Sunday being observed the
                following Monday). This doesn't work for all countries.

            subdiv:
                The subdivision (e.g. state or province) as a ISO 3166-2 code
                or its alias; not implemented for all countries (see documentation).

            prov:
                *deprecated* use `subdiv` instead.

            state:
                *deprecated* use `subdiv` instead.

            language:
                Specifies the language in which holiday names are returned.

                Accepts either:

                * A two-letter ISO 639-1 language code (e.g., 'en' for English, 'fr' for French),
                    or
                * A language and entity combination using an underscore (e.g., 'en_US' for U.S.
                    English, 'pt_BR' for Brazilian Portuguese).

                !!! warning
                    The provided language or locale code must be supported by the holiday
                    entity. Unsupported values will result in names being shown in the entity's
                    original language.

                If not explicitly set (`language=None`), the system attempts to infer the
                language from the environment's locale settings. The following environment
                variables are checked, in order of precedence: LANGUAGE, LC_ALL, LC_MESSAGES, LANG.

                If none of these are set or they are empty, holiday names will default to the
                original language of the entity's holiday implementation.

                !!! warning
                    This fallback mechanism may yield inconsistent results across environments
                    (e.g., between a terminal session and a Jupyter notebook).

                To ensure consistent behavior, it is recommended to set the language parameter
                explicitly. If the specified language is not supported, holiday names will remain
                in the original language of the entity's holiday implementation.

                This behavior will be updated and formalized in v1.

            categories:
                Requested holiday categories.

        Returns:
            A `HolidayBase` object matching the `country` or `market`.
        z<The default category must be listed in supported categories.z<Categories cannot be empty if `default_category` is not set.zCategory is not supported: , .r.   zEntity `z` does not have subdivision z5Arguments prov and state are deprecated, use subdiv='z
' instead.zjThis subdivision is deprecated and will be removed after Dec, 1 2023. The list of supported subdivisions: z.; the list of supported subdivisions aliases: has_substituted_holidaysFsubstituted_labelNsubstituted_date_formatzS` class must have `substituted_label` and `substituted_date_format` attributes set.has_special_holidaysr8   )$super__init__r9   r<   
ValueErrorr)   str
differencejoin
isinstanceinttupler0   setr/   r6   r@   r   NotImplementedError_entity_codewarningswarnDeprecationWarningsortedgetattrr;   r2   rK   rH   rC   r3   r4   r8   r1   _init_translation	_populate)selfr1   r2   r3   r4   rA   rB   rC   r;   unknown_categoriessubdivision_aliasessupported_subdivisions
prov_staterH   year	__class__s                  U/var/www/api/v1/venv_fitandmore/lib/python3.12/site-packages/holidays/holiday_base.pyrM   zHolidayBase.__init__   s   R 	   T%:%:$B[B[%[[\\$$Z[\\)#z:Ut?T?T>U
!+!6!6%%"
 
 
 :499EW;X:YYZ[\\ ,t,u,6,&#&V"'(A(A"B%(!!%&//0 7;6H6H4%%22bR&" dJ/FBX4X)t0011MfXV 
 "]U*z*KJ<Wab& 666Hyy(9(9!:;< =Cyy(;!<=>a	A
 ' )06PRW(XX$X1484!:DA4,,- .@ @ 
 %$+D2H%$P!(@%   '.@#% H)#u5
 	  JJDNN4      otherr   c                     t        |t              r|dk(  r| S t        |t        t        f      st	        d      t        | |      S )aG  Add another dictionary of public holidays creating a
        [HolidaySum][holidays.holiday_base.HolidaySum] object.

        Args:
            other:
                The dictionary of public holiday to be added.

        Returns:
            A `HolidayBase` object unless the other object cannot be added, then `self`.
        r   z<Holiday objects can only be added with other Holiday objects)rR   rS   r   r   	TypeErrorr_   rh   s     rf   __add__zHolidayBase.__add__  sC     eS!eqj K%+z!:;Z[[$&&rg   c                     t        |       dkD  S )Nr   )lenr_   s    rf   __bool__zHolidayBase.__bool__  s    4y1}rg   keyc                     t        |t        t        t        t        t
        f      st        dt        |       d      t        j                  t        d|       | j                  |            S )a  Check if a given date is a holiday.

        The method supports the following input types:

        * `datetime.date`
        * `datetime.datetime`
        * `float` or `int` (Unix timestamp)
        * `str` of any format recognized by `dateutil.parser.parse()`

        Args:
            key:
                The date to check.

        Returns:
            `True` if the date is a holiday, `False` otherwise.
        Cannot convert type '
' to date.dict[Any, Any])rR   r
   r   floatrS   rO   rj   typedict__contains__r   __keytransform__r_   rq   s     rf   ry   zHolidayBase.__contains__  sY    $ #hsC@A3DI;jIJJ  &6!=t?T?TUX?YZZrg   c                     t        |t              sy| j                  D ]  }t        | |d       t        ||d       k7  s y t        j                  t        d|       |      S )NFru   )rR   r   _HolidayBase__attribute_namesr\   rx   __eq__r   r_   rh   attribute_names      rf   r~   zHolidayBase.__eq__  sX    %-"44Nt^T2ge^UY6ZZ 5 {{4 0$7??rg   c           	         	
 	  j                  |      S # t        $ r}d}|d t        |       |k7  r||j                  d      }t        |      dk(  r$|^ }
t        v r
t
        v r
 fdcY d }~S |t        |      dk(  r|^ }}|dk(  r5dk(  sd   j                         rt        v rt        v r fd	cY d }~S |^ }}}|d
v r3dv r/|dk(  r*t              dk  rj                         r fdcY d }~S |t        |      dk(  ro|^ }}}|d
v r^dv rZ|dk(  rUt              dk  rGj                         r7dk(  sd   j                         rt        v rt        v r fdcY d }~S |t        |      dk(  rG|^ }	
	dv r:d   j                         r't        v rt        v r
t
        v r	
 fdcY d }~S |d }~ww xY w)N_add_holiday__   c           
      r    j                  | t        j                  t           t	                          S N)_add_holidayr
   _yearr#   rS   )namedaymonthr_   s    rf   <lambda>z)HolidayBase.__getattr__.<locals>.<lambda>  s*    (9(9d4::ve}c#hG)rg      oflastr   c           	          j                  | t        dk(  rdnt        d         t           t           j
                              S )Nr   r   )r   r!   rS   r$   r#   r   )r   r   numberr_   weekdays    rf   r   z)HolidayBase.__getattr__.<locals>.<lambda>  sE    (9(91"(F"2BF1I$W-"5M JJ	)rg   >   r   days>   pastprioreaster   c           	          j                  | t        j                  dk(  rt                          S t                           S )Nr   )r   r   _easter_sundayrS   )r   r   delta_directionr_   s    rf   r   z)HolidayBase.__getattr__.<locals>.<lambda>  sK    (9(9" //*9V*CSYJ) KNd))rg   
   c                     j                  | t        t        dk(  rdnt        d         t           t
           j                        dk(  rt                          S t                           S )Nr   r   r   r   )r   r   r!   rS   r$   r#   r   )r   r   r   r   r   r_   r   s    rf   r   z)HolidayBase.__getattr__.<locals>.<lambda>  sv    (9(9"5&,&6Cq	N ( 1 &u $

	 +:V*CSYJ) KNd))rg      >   frombeforec                     j                  | t        dk(  rt        d          nt        d         t           t	        j
                  t           t                                S )Nr   r   )r   r    rS   r$   r
   r   r#   )r   date_directionr   r   r   r_   r   s    rf   r   z)HolidayBase.__getattr__.<locals>.<lambda>  s`    (9(9-/=/IS^OPSTZ[\T]P^$W- VE]CHE)rg   )__getattribute__AttributeErrorrn   splitr#   r"   isdigitr$   )r_   r   eadd_holiday_prefixtokensr   r   unitr   r   r   r   r   r   r   r   s   `        @@@@@@@rf   __getattr__zHolidayBase.__getattr__  s1   j	((.. h	!0-c,-.2DDZZ_F 6{a!'E3F?sd{ v Go V! 28.FGR$J6)VAY->->-@8+  ;A7D$O+'+<<(*D	A p G[ V"NTKD$"eO+'+<<d
D	A6)VAY->->-@8+  B G% V!BH?FG^UC"&88q	))+8+t   GQh	sT    
G'AG"5G';AG"G'9G"G'A7G"G'	AG"G' G""G'c                 H   t        |t              rm|j                  r|j                  st	        d      | j                  |j                        }| j                  |j                        }|j                  d}nzt        |j                  t              r|j                  j                  }nIt        |j                  t              r|j                  }n"t        dt        |j                         d      |dk(  rt	        d      ||z
  }|j                  dcxk  r|k  sn |j                  dcxk\  r|kD  rn n|dz  }g }t        d|j                  |      D ]$  }t        ||      }|| v s|j                  |       & |S t        j!                  | | j                  |            S )Nz"Both start and stop must be given.   rs   z	' to int.r   zStep value must not be zero.r   )rR   slicestartstoprN   rz   stepr   r   rS   rj   rw   ranger   appendrx   __getitem__)	r_   rq   r   r   r   	date_diffdays_in_range
delta_daysr   s	            rf   r   zHolidayBase.__getitem__&  sU   c5!99CHH !EFF))#))4E((2DxxCHHi0xx}}CHHc*xx"7SXX7Gy QRRqy !?@@uI~~)T)Y^^q-G4-G
M#Ay~~t<
 
3$;!((- =
 ! d&;&;C&@AArg   c                 ^    | j                   j                         }|j                  dd       |S )z,Return the object's state for serialization.trN)__dict__copypopr_   rB   s     rf   __getstate__zHolidayBase.__getstate__H  s'    ""$		$rg   c                 (   d}t        |      t        u r|}nt        |t              r@t	        |      dv r	 t        j
                  |      }|	 t        |      j                         }nt        |t              r|j                         }ntt        |t              r|}nat        |t        t        f      r3t        j                  |t        j                        j                         }nt        dt        |       d      | j                   rX|j"                  | j$                  vr@| j$                  j'                  |j"                         | j)                  |j"                         |S # t        $ r Y $w xY w# t        t        f$ r t        d| d      w xY w)a  Convert various date-like formats to `datetime.date`.

        The method supports the following input types:

        * `datetime.date`
        * `datetime.datetime`
        * `float` or `int` (Unix timestamp)
        * `str` of any format recognized by `dateutil.parser.parse()`

        Args:
            key:
                The date-like object to convert.

        Returns:
            The corresponding `datetime.date` representation.
        N>   r   r   zCannot parse date from string ''rs   rt   )rw   r
   rR   rO   rn   fromisoformatrN   r   OverflowErrorr   rv   rS   fromtimestampr   utcrj   r2   rd   r1   addr^   r_   rq   dts      rf   rz   zHolidayBase.__keytransform__N  sY   $ " 9B S!3x7"++C0B zOs*B
 X&B T"B eS\*''X\\:??AB 3DI;jIJJ ;;277$**4JJNN277#NN277#	; " 
 &z2 O$'Fse1%MNNOs   E" E2 "	E/.E/2Fc                     t        |t              sy| j                  D ]  }t        | |d       t        ||d       k7  s y t        j                  | |      S )NT)rR   r   r}   r\   rx   __ne__r   s      rf   r   zHolidayBase.__ne__  sP    %-"44Nt^T2ge^UY6ZZ 5 {{4''rg   c                 $    | j                  |      S r   )rl   rk   s     rf   __radd__zHolidayBase.__radd__  s    ||E""rg   c                      t         |          S r   )rL   
__reduce__)r_   re   s    rf   r   zHolidayBase.__reduce__  s    w!##rg   c                    | rt         |          S g }t        | d      r0|j                  d| j                         |j                  d       nwt        | d      rZ|j                  d| j
                         | j                  r|j                  d| j                         |j                  d       n|j                  d       dj                  |      S )	Nr-   zholidays.financial_holidays()r,   zholidays.country_holidays(z	, subdiv=zholidays.HolidayBase() )rL   __repr__hasattrr   r-   r,   r4   rQ   r_   partsre   s     rf   r   zHolidayBase.__repr__  s    7#%%4"LL7GHLLT9%LL5dll5EFG{{y89LLLL12wwu~rg   valuec                     t         j                  | ||       | r8|dv r3| j                          | j                  D ]  }| j	                  |        y y y )N>   r3   r;   )rx   __setattr__clearr1   r^   )r_   rq   r   rd   s       rf   r   zHolidayBase.__setattr__  sI    sE*C55JJL

t$ # 64rg   c                    || v rct        | |   j                  t                    }|j                  |j                  t                     t        j                  t        |            }t        j                  | | j                  |      |       y r   )	rU   r   r%   updaterQ   r[   rx   __setitem__rz   )r_   rq   r   holiday_namess       rf   r   zHolidayBase.__setitem__  sm    $;  S	0F GHM  -C!DE*//}0EFEt44S95Arg   c                 Z    | j                   j                  |       | j                          y)z1Restore the object's state after deserialization.N)r   r   r]   r   s     rf   __setstate__zHolidayBase.__setstate__  s     U# rg   c                 z      rt                   S  fd j                  D        }ddj                  |       dS )Nc           	   3   D   K   | ]  }d | dt        |d         yw)r   z': Nr\   ).0r   r_   s     rf   	<genexpr>z&HolidayBase.__str__.<locals>.<genexpr>  s1      
"8 s74#F"GH"8s    {rF   })rL   __str__r}   rQ   r   s   ` rf   r   zHolidayBase.__str__  sC    7?$$
"&"8"8

 DIIe$%R((rg   c                      y)N)r,   r2   rC   r-   r3   r4   r1   r.   ro   s    rf   __attribute_nameszHolidayBase.__attribute_names  s    Yrg   c           	      2    t        | dt        | dd             S )Nr,   r-   r   ro   s    rf   rW   zHolidayBase._entity_code  s    tYh(EFFrg   c                     | j                   j                  | j                  | j                        j                  t        j                  ddd            j                         S )Nr   )- )r0   getr4   	translaterO   	maketranslowerro   s    rf   _normalized_subdivzHolidayBase._normalized_subdiv  sQ     %%))$++t{{CY   UW	
rg   c                     | j                   | j                  v r1| j                   gt        | j                  | j                   hz
        z   S t        | j                        S r   )r9   r;   r[   ro   s    rf   _sorted_categorieszHolidayBase._sorted_categories  sX     $$7 ""#fT__@U@U?V-V&WW	
 (	
rg   c                     | j                   D ci c]  }|g  }}| j                  j                         D ]  \  }}||   j                  |        |S c c}w )zGet subdivision aliases.

        Returns:
            A dictionary mapping subdivision aliases to their official ISO 3166-2 codes.
        )r/   r0   itemsr   )clssra   aliassubdivisions        rf   get_subdivision_aliasesz#HolidayBase.get_subdivision_aliases  sg     EHDTDT4UDTqQUDT4U"%":":"@"@"BE;,33E: #C #"	 5Vs   
Ac                    t        | j                        }| j                  | j                  |v}| j                  |v r| j                  gnd}t	        t        t              j                  d            }t        | j                  |||      }| j                  x}r6|j                  t        |j                  xs |j                  |||             |j                  | _        yt        | _        y)z;Initialize translation function based on language settings.Nlocale)fallback	languages	localedir)rU   r=   rW   rC   rO   r   __file__	with_namer   r@   add_fallbackr,   r-   r   r   )r_   r=   r   r   locale_directoryentity_translationr@   s          rf   r]   zHolidayBase._init_translation  s    !$":":;(}},??H+/==<O+OUYI"4>#;#;H#EF "-!!!#*	" !% 2 22}2"//%--E1E1E!)"+"2	 )00DGDGrg   c                 ,    t        | j                        S )z:Returns True if the year is leap. Returns False otherwise.)r   r   ro   s    rf   _is_leap_yearzHolidayBase._is_leap_year  s    djj!!rg   r   c                     |st        d      t        |      dkD  r|n|d   }t        |t              r|nt        | j                  g| }|j
                  | j                  k7  ry| j                  |      | |<   |S )zAdd a holiday.zIncorrect number of arguments.r   r   N)rj   rn   rR   r
   r   rd   r   )r_   r   argsr   s       rf   r   zHolidayBase._add_holiday  sm    <==Y]TQb$'RT$**-Br-B77djj 774=R	rg   c           
      ~   |D ]7  }t        t        | |i       j                  | j                  d            D ]   }t	        |      dk(  rX|\  }}}| j                  |r-| j                  | j                        | j                  |      z  n| j                  |      ||       j|^}}	}
}}t        |r|d   n| j                  |
|      }| j                  | j                  | j                        |j                  | j                  | j                              z  ||	       | j                  j                  |        : y)zAdd special holidays.r.   r   r   N)r*   r\   r   r   rn   r   r   observed_labelr
   rI   strftimerJ   r8   r   )r_   mapping_namesr3   mapping_namedatar   r   r   to_monthto_day
from_monthfrom_dayoptional	from_dates                 rf   _add_special_holidaysz!HolidayBase._add_special_holidays+  s   )L(|R)H)L)LTZZY[)\]t9>'+$E3%%#  3 34twwt}D!WWT] IMEHfj(X $HXa[$**jZb cI%% 6 67#,,TWWT5Q5Q-RST 	 ))--i8' ^ *rg   r   c                     t        |      dkD  r|n|d   }t        |t              r|nt        | j                  g| }|j	                         |k(  S )zk
        Returns True if `weekday` equals to the date's week day.
        Returns False otherwise.
        r   r   )rn   rR   r
   r   r   )r_   r   r  r   s       rf   _check_weekdayzHolidayBase._check_weekdayC  sH    
 Y]TQb$'RT$**-Br-Bzz|w&&rg   r   c                     | j                   S r   )r7   )r_   r   s     rf   _get_weekendzHolidayBase._get_weekendL  s    ||rg   c                 0     | j                   t        g| S r   )r  r   r_   r  s     rf   
_is_mondayzHolidayBase._is_mondayO      "t""3...rg   c                 0     | j                   t        g| S r   )r  r   r  s     rf   _is_tuesdayzHolidayBase._is_tuesdayR  r  rg   c                 0     | j                   t        g| S r   )r  r   r  s     rf   _is_wednesdayzHolidayBase._is_wednesdayU  r  rg   c                 0     | j                   t        g| S r   )r  r   r  s     rf   _is_thursdayzHolidayBase._is_thursdayX  r  rg   c                 0     | j                   t        g| S r   )r  r   r  s     rf   
_is_fridayzHolidayBase._is_friday[  r  rg   c                 0     | j                   t        g| S r   )r  r   r  s     rf   _is_saturdayzHolidayBase._is_saturday^  r  rg   c                 0     | j                   t        g| S r   )r  r   r  s     rf   
_is_sundayzHolidayBase._is_sundaya  r  rg   c                     t        |      dkD  r|n|d   }t        |t              r|nt        | j                  g| }|j	                         | j                  |      v S )zd
        Returns True if date's week day is a weekend day.
        Returns False otherwise.
        r   r   )rn   rR   r
   r   r   r  )r_   r  r   s      rf   _is_weekendzHolidayBase._is_weekendd  sS    
 Y]TQb$'RT$**-Br-Bzz|t00444rg   rd   c                     || j                   k  s|| j                  kD  ry|| _        | j                          | j	                          y)a   This is a private method that populates (generates and adds) holidays
        for a given year. To keep things fast, it assumes that no holidays for
        the year have already been populated. It is required to be called
        internally by any country `populate()` method, while should not be called
        directly from outside.
        To add holidays to an object, use the [update()][holidays.holiday_base.HolidayBase.update]
        method.

        Args:
            year: The year to populate with holidays.

            >>> from holidays import country_holidays
            >>> us_holidays = country_holidays('US', years=2020)
            # to add new holidays to the object:
            >>> us_holidays.update(country_holidays('US', years=2021))
        N)r>   r?   r   _populate_common_holidays_populate_subdiv_holidays)r_   rd   s     rf   r^   zHolidayBase._populatem  s=    $ $//!TDMM%9
&&(&&(rg   c                     | j                   D ]+  }t        | d|j                          dd      x}s% |        - | j                  r#| j	                  d | j                   D               yy)z Populate entity common holidays.
_populate_	_holidaysNc              3   (   K   | ]
  }d | d  yw)special_r1  Nr.   )r   categorys     rf   r   z8HolidayBase._populate_common_holidays.<locals>.<genexpr>  s      '?V8(8*I.?Vs   )r   r\   r   rK   r  )r_   r4  
pch_methods      rf   r-  z%HolidayBase._populate_common_holidays  sn    //H$TZ8H7I+SUYZZzZ 0 $$&& '?C?V?V'  %rg   c           	           j                   y j                  D ]8  }t         d j                   d|j	                          dd      x}s2 |        :  j
                  r% j                   fd j                  D               yy)z%Populate entity subdivision holidays.N_populate_subdiv_r   r1  c              3   `   K   | ]%  }d j                    d|j                          d ' yw)r3  r   r1  N)r   r   )r   r4  r_   s     rf   r   z8HolidayBase._populate_subdiv_holidays.<locals>.<genexpr>  s7      ' 7H 42231X^^5E4FiP 7s   +.)r4   r   r\   r   r   rK   r  )r_   r4  asch_methods   `  rf   r.  z%HolidayBase._populate_subdiv_holidays  s    ;;//H%#D$;$;#<Ahnn>N=OyY { 
  0 $$&& ' $ 7 7'  %rg   r  c                       | j                   | S )a=  Alias for [update()][holidays.holiday_base.HolidayBase.update] to mimic list type.

        Args:
            args:
                Holiday data to add. Can be:

                * A dictionary mapping dates to holiday names.
                * A list of dates (without names).
                * A single date.
        )r   r  s     rf   r   zHolidayBase.append  s     t{{D!!rg   c                 ,    t        j                   |       S )zReturn a copy of the object.)r   ro   s    rf   r   zHolidayBase.copy  s    yyrg   defaultc                 N    t         j                  | | j                  |      |      S )aQ  Retrieve the holiday name(s) for a given date.

        If the date is a holiday, returns the holiday name as a string.
        If multiple holidays fall on the same date, their names are joined by a semicolon (`;`).
        If the date is not a holiday, returns the provided `default` value (defaults to `None`).

        Args:
            key:
                The date expressed in one of the following types:

                * `datetime.date`
                * `datetime.datetime`
                * `float` or `int` (Unix timestamp)
                * `str` of any format recognized by `dateutil.parser.parse()`

            default:
                The default value to return if no value is found.

        Returns:
            The holiday name(s) as a string if the date is a holiday,
                or the `default` value otherwise.
        )rx   r   rz   r_   rq   r<  s      rf   r   zHolidayBase.get  s"    . xxd33C8'BBrg   c                 x    | j                  |d      j                  t              D cg c]  }|s|	 c}S c c}w )a  Retrieve all holiday names for a given date.

        Args:
            key:
                The date expressed in one of the following types:

                * `datetime.date`
                * `datetime.datetime`
                * `float` or `int` (Unix timestamp)
                * `str` of any format recognized by `dateutil.parser.parse()`

        Returns:
            A list of holiday names if the date is a holiday, otherwise an empty list.
        r   )r   r   r%   )r_   rq   r   s      rf   get_listzHolidayBase.get_list  s8     "&#r!2!8!89O!PY!PTX!PYYYs   77holiday_namelookupsplit_multiple_namesc           
      $   |rd | j                         D        nd | j                         D        }|dk(  r8|j                         }|D cg c]  \  }}||j                         v s| c}}S |dk(  r|D cg c]  \  }}||k(  s| c}}S |dk(  r|D cg c]  \  }}||v s| c}}S |dk(  r'|D cg c]  \  }}||dt        |       k(  s| c}}S |dk(  r9|j                         }|D cg c]  \  }}||j                         k(  s| c}}S |d	k(  rD|j                         }|D cg c]&  \  }}||dt        |       j                         k(  r|( c}}S t        d
|       c c}}w c c}}w c c}}w c c}}w c c}}w c c}}w )a  Find all holiday dates matching a given name.

        The search by default is case-insensitive and includes partial matches.

        Args:
            holiday_name:
                The holiday's name to try to match.

            lookup:
                The holiday name lookup type:

                * contains - case sensitive contains match;
                * exact - case sensitive exact match;
                * startswith - case sensitive starts with match;
                * icontains - case insensitive contains match;
                * iexact - case insensitive exact match;
                * istartswith - case insensitive starts with match;

            split_multiple_names:
                Either use the exact name for each date or split it by holiday
                name delimiter.

        Returns:
            A list of all holiday dates matching the provided holiday name.
        c              3   ^   K   | ]%  \  }}|j                  t              D ]  }||f 
 ' y wr   )r   r%   )r   kvr   s       rf   r   z(HolidayBase.get_named.<locals>.<genexpr>  s,     \<41aAGGDZ<[DaY<[Y<s   +-c              3   *   K   | ]  \  }}||f  y wr   r.   )r   rF  rG  s      rf   r   z(HolidayBase.get_named.<locals>.<genexpr>  s     2\TQ1a&\s   	icontainsexactcontains
startswithNiexactistartswithzUnknown lookup type: )r   r   rn   r   )r_   rA  rB  rC  holiday_name_datesholiday_name_lowerr   r   s           rf   	get_namedzHolidayBase.get_named  s   < $ ]4::<\2TZZ\2 	 [ !-!3!3!5'9`'982t=OSWS]S]S_=_B'9``w'9R'982t\T=QB'9RRz!'9R'982t\T=QB'9RR|##5#5xr4NaPST`PaIb9b#5  x!-!3!3!5'9`'982t=OSWS]S]S_=_B'9``}$!-!3!3!5 !3 2HB%.AL0A)B)H)H)JJ  2  4VH=>>) aRR
 asB   E.&E.8E4E4E:%E:7F F 3FF1+Ftarget_date	direction)forwardbackwardc                    |dvrt        d|       | j                  |xs" t        j                         j	                               }|dk(  r/|j
                  dz   x}| j                  vr| j                  |       n3|dk(  r.|j
                  dz
  x}| j                  vr| j                  |       t        | j                               }|dk(  rt        ||      nt        ||      dz
  }d|cxk  rt        |      k  rn y||   }|| |   fS y)a  Find the closest holiday relative to a given date.

        If `direction` is "forward", returns the next holiday after `target_date`.
        If `direction` is "backward", returns the previous holiday before `target_date`.
        If `target_date` is not provided, the current date is used.

        Args:
            target_date:
                The reference date. If None, defaults to today.

            direction:
                Search direction, either "forward" (next holiday) or
                "backward" (previous holiday).

        Returns:
            A tuple containing the holiday date and its name, or None if no holiday is found.
        >   rT  rU  zUnknown direction: rT  r   rU  r   N)r   rz   r   nowr
   rd   r1   r^   r[   keysr   r   rn   )r_   rR  rS  r   	next_yearprevious_yearsorted_datespositions           rf   get_closest_holidayzHolidayBase.get_closest_holiday  s   , 33 #6yk!BCC"";#G(,,.2E2E2GH	!BGGaK'?y

&RNN9%*$277Q;*F-tzz)YNN=)diik* I% r*\2.2 	
 ,3|,,  h'BtBx<rg   nc                     |dk\  rdnd}| j                  |      }t        t        |      xs d      D ]@  }|rt        ||      }| j	                  |      r#t        ||      }| j	                  |      sB |S )a  Find the n-th working day from a given date.

        Moves forward if n is positive, or backward if n is negative.
        If n is 0, returns the given date if it is a working day; otherwise the next working day.

        Args:
            key:
                The starting date.

            n:
                The number of working days to move. Positive values move forward,
                negative values move backward.

        Returns:
            The calculated working day after shifting by n working days.
        r   r   r   )rz   r   absr   is_working_day)r_   rq   r^  rS  r   r   s         rf   get_nth_working_dayzHolidayBase.get_nth_working_dayD  sx    " q&Bb	""3's1v{#AI.))"-I. ))"- $
 	rg   r   endc                       j                  |       j                  |      }|kD  r|c}|z
  j                  dz   }t         fdt        |      D              S )a  Calculate the number of working days between two dates.

        The date range works in a closed interval fashion [start, end] so both
        endpoints are included.

        Args:
            start:
                The range start date.

            end:
                The range end date.

        Returns:
            The total count of working days between the given dates.
        r   c              3   T   K   | ]  }j                  t        |             ! y wr   )ra  r   )r   r^  dt1r_   s     rf   r   z5HolidayBase.get_working_days_count.<locals>.<genexpr>s  s$     PKq4&&z#q'9:Ks   %()rz   r   sumr   )r_   r   rc  dt2r   rf  s   `    @rf   get_working_days_countz"HolidayBase.get_working_days_count^  s`      ##E*##C(9CHCc	!#PE$KPPPrg   c                 B    | j                  | j                  |            S )zCheck if the given date's week day is a weekend day.

        Args:
            key:
                The date to check.

        Returns:
            True if the date's week day is a weekend day, False otherwise.
        )r+  rz   r{   s     rf   
is_weekendzHolidayBase.is_weekendu  s       5 5c :;;rg   c                 j    | j                  |      }| j                  |      r|| j                  v S || vS )zCheck if the given date is considered a working day.

        Args:
            key:
                The date to check.

        Returns:
            True if the date is a working day, False if it is a holiday or weekend.
        )rz   r+  r8   r   s      rf   ra  zHolidayBase.is_working_day  s<     ""3'.2.>.>r.BrT***VRVVrg   c                     |%t         j                  | | j                  |            S t         j                  | | j                  |      |      S )at  Remove a holiday for a given date and return its name.

        If the specified date is a holiday, it will be removed, and its name will
        be returned. If the date is not a holiday, the provided `default` value
        will be returned instead.

        Args:
            key:
                The date expressed in one of the following types:

                * `datetime.date`
                * `datetime.datetime`
                * `float` or `int` (Unix timestamp)
                * `str` of any format recognized by `dateutil.parser.parse()`

            default:
                The default value to return if no match is found.

        Returns:
            The name of the removed holiday if the date was a holiday, otherwise
                the provided `default` value.

        Raises:
            KeyError: if date is not a holiday and default is not given.
        )rx   r   rz   r>  s      rf   r   zHolidayBase.pop  sC    4 ?88D$"7"7"<==xxd33C8'BBrg   c           
      t   t         |v }| j                  |||       x}st        |      g }|D ]g  }| |   j                  t               }| j	                  |       |j                  |       |rA|dk(  r3|j                         }|D 	cg c]  }	||	j                         vs|	 }}	n|dk(  r4|j                         }|D 	cg c]  }	||	j                         k7  s|	 }}	n|dk(  r?|j                         }|D 	cg c]#  }	||	dt        |       j                         k7  r|	% }}	nV|dk(  r|D 	cg c]	  }	||	vs|	 }}	n<|dk(  r|D 	cg c]
  }	||	k7  s	|	 }}	n!|D 	cg c]  }	||	dt        |       k7  s|	 }}	|sPt        j                  |      | |<   j |S c c}	w c c}	w c c}	w c c}	w c c}	w c c}	w )a  Remove all holidays matching the given name.

        This method removes all dates associated with a holiday name, so they are
        no longer considered holidays. The search by default is case-insensitive and
        includes partial matches.

        Args:
            holiday_name:
                The holiday's name to try to match.

            lookup:
                The holiday name lookup type:

                * contains - case sensitive contains match;
                * exact - case sensitive exact match;
                * startswith - case sensitive starts with match;
                * icontains - case insensitive contains match;
                * iexact - case insensitive exact match;
                * istartswith - case insensitive starts with match;

        Returns:
            A list of dates removed.

        Raises:
            KeyError: if date is not a holiday.
        )rB  rC  rI  rM  rN  NrK  rJ  )	r%   rQ  KeyErrorr   r   r   r   rn   rQ   )
r_   rA  rB  use_exact_namedtspoppedr   r   rP  r   s
             rf   	pop_namedzHolidayBase.pop_named  s    6 0<?>>VnBT "  C  <((B HNN+ABMHHRLMM" $%1%7%7%9"%2!%2T6HPTPZPZP\6\D]  ! 8#%1%7%7%9"%2!%2T6HDJJL6XD]  ! =(%1%7%7%9" !.! -)T2EC4E-F-L-L-NN  -  !
 :%2? \-$<W[C[- \7"2? X-$<SWCW- X &3!%2TldK^SQ]M^F_6_D]  ! 166}ERE H 5!
!
! !] X!sB   	F!FF!F!:(F&.	F+8F+
F0F0F55F5c                     |D ]R  }t        |t              r|j                         D ]
  \  }}|| |<    1t        |t              r|D ]  }d| |<   	 Nd| |<   T y)aJ  Update the object, overwriting existing dates.

        Args:
            args:
                Either another dictionary object where keys are dates and values
                are holiday names, or a single date (or a list of dates) for which
                the value will be set to "Holiday".

                Dates can be expressed in one or more of the following types:

                * `datetime.date`
                * `datetime.datetime`
                * `float` or `int` (Unix timestamp)
                * `str` of any format recognized by `dateutil.parser.parse()`
        HolidayN)rR   rx   r   list)r_   r  argrq   r   items         rf   r   zHolidayBase.update  s]    $ C#t$"%))+JC %DI #.C&D!*DJ   &S	 rg   )NTTNNNNN)rD   N)Fr   )rI  T)NrT  )rI  )c__name__
__module____qualname____doc__rO   __annotations__r/   rT   r0   rx   rU   rS   boolr4   r   r5   r   SpecialHolidaySubstitutedHolidayr6   r   r   r7   r
   r&   r9   r:   r;   r<   r=   r'   r>   r(   r?   r@   rw   YearArgCategoryArgrM   rl   rp   objectry   r~   r   r   r   r   r   rz   r   r   r   r   r   r   r   r   propertyr}   r   rW   r   r   classmethodrv  r   r]   r  r   r  r  r  r  r  r!  r#  r%  r'  r)  r+  r^   r-  r.  r   r   r   r@  rQ  r   r]  rb  ri  rk  ra  r   rs  r   __classcell__)re   s   @rf   r   r   9   se   ~@ L0K/$&L%S/&J+-$sCx.-2s8OLNF FHSM HMOd3n6H&H IIJO02eCHo2c
GSX"$i)"c".&*hsm*.5JC '-3I%S/5:+-sCx-1(J(:$Hc$837M8D/078 $( $"#"&,0W! W! W! 	W!
 W! smW! }W! 3-W! [)W! 
W!r'U3|#CD ' '*$ [ [4 [.@F @t @kZ Bx  BC  BDd38n <H < <|(F (t (#c #m #$E#uS#X"67 $# $%s %3 %4 %Bx B B B!$sCx. !T !
	) 	) Z Z G G 
 
 
 
 
#S$Y 
# 
#:"t "  90'c 'T 't C /4 //D //d //T //4 //T //4 /5)c )d )2	&"E$x}"5tH~x"OP "UY "Cx C%S/ CU3PS8_ C2ZH Zc Z$ Z^8?8?),8?RV8?	d8?x +/4=)h') 01) 
%c	"	#	)Vx C D 4QH Q8 Q Q.
<h 
<4 
<W( Wt WCx C%S/ CU3PS8_ C>Hc H3 Hd HT&4#.XHI&	&rg   r   c                       e Zd ZU dZeeee   f   ed<   	 eeee   f   ed<   	 eeeee   f      ed<   	 ee	   ed<   	 e
e   ed<   	 dee	d f   dee	d f   d	d
fdZd Zy
)r   ah  
    Combine multiple holiday collections into a single dictionary-like object.

    This class represents the sum of two or more `HolidayBase` instances.
    The resulting object behaves like a dictionary mapping dates to holiday
    names, with the following behaviors:

    * The `holidays` attribute stores the original holiday collections as a list.
    * The `country` and `subdiv` attributes are combined from all operands and
      may become lists.
    * If multiple holidays fall on the same date, their names are merged.
    * Holidays are generated (expanded) for all years included in the operands.
    r,   r-   r4   holidaysr1   h1h2rD   Nc                    g | _         ||fD ]S  }t        |t              r&| j                   j                  |j                          9| j                   j	                  |       U i }|j
                  |j
                  z  |d<   |j                  xs |j                  |d<   |j                  xs |j                  |d<   dD ]  }t        ||d      rt        ||d      rt        ||      t        ||      k7  rlt        t        ||      t              rt        ||      nt        ||      g}t        t        ||      t              rt        ||      nt        ||      g}||z   }nt        ||d      xs t        ||d      }|dk(  r|||<   t        | ||        |j                  xs |j                  }	|j                  xs |j                  }
t        |	t              r
|	|
k(  r|	|d<   t        j                  | fi | |	r	|	f| _        yd| _        y)	u  
        Args:
            h1:
                The first HolidayBase object to add.

            h2:
                The other HolidayBase object to add.

        Example:

            >>> from holidays import country_holidays
            >>> nafta_holidays = country_holidays('US', years=2020) +     country_holidays('CA') + country_holidays('MX')
            >>> dates = sorted(nafta_holidays.items(), key=lambda x: x[0])
            >>> from pprint import pprint
            >>> pprint(dates[:10], width=72)
            [(datetime.date(2020, 1, 1), "Año Nuevo; New Year's Day"),
             (datetime.date(2020, 1, 20), 'Martin Luther King Jr. Day'),
             (datetime.date(2020, 2, 3), 'Día de la Constitución'),
             (datetime.date(2020, 2, 17), "Washington's Birthday"),
             (datetime.date(2020, 3, 16), 'Natalicio de Benito Juárez'),
             (datetime.date(2020, 4, 10), 'Good Friday'),
             (datetime.date(2020, 5, 1), 'Día del Trabajo'),
             (datetime.date(2020, 5, 25), 'Memorial Day'),
             (datetime.date(2020, 7, 1), 'Canada Day'),
             (datetime.date(2020, 7, 3), 'Independence Day (observed)')]
        r1   r2   r3   )r,   r-   r4   Nr4   rC   r.   )r  rR   r   extendr   r1   r2   r3   r\   rv  setattrrC   r:   rO   r   rM   r=   )r_   r  r  operandkwargsattra1a2r   h1_languageh2_languages              rf   rM   zHolidaySum.__init__.  s   > BxG':.$$W%5%56$$W-	   "$((RXX-w991		x[[7BKKz 4DD$'Bd+B%T):: "'"d"3T: B%!"d+,  "'"d"3T: B%!"d+, 
 RD$/J72tT3Jx$tdE*/ 46 kk8R%8%8kk8R%8%8k3'K;,F!,F:T,V, 6AK> b rg   c                 ~    | j                   D ].  }|j                  |       | j                  t        d|             0 y )Nzdict[DateLike, str])r  r^   r   r   )r_   rd   r  s      rf   r^   zHolidaySum._populate  s2    }}Gd#KK2G<= %rg   )ry  rz  r{  r|  r   rO   rv  r}  r   r   rU   rS   rM   r^   r.   rg   rf   r   r     s     3S	>""-#tCy.!!+U3S	>*++0;Ds8OVI\12VI8=k<>W8XVI	VIp>rg   r   )?__all__r   rX   bisectr   r   calendarr   collections.abcr	   r   r
   r   r   	functoolsr   r   r   pathlibr   typingr   r   r   r   r   dateutil.parserr   holidays.calendars.gregorianr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   holidays.constantsr%   r&   r'   r(   holidays.helpersr)   r*   rO   r  rT   rS   DateArgrv   r   r  r  r  rx   r   r   r.   rg   rf   <module>r     sy   4   ,  $ 8 8 % (  6 6 !    d c CC#&'
eCHouS#s]';;
<xeS01uS#s]+U5c33G3L-MMN	%S#s"
#U3S#s+B%C
CD	%c3S()5c3S1H+II
JC
OPR  Xc]"
#X&$tSy/ X&v&u> u>rg   