
    x7#h`                     P    d dl mZ d dlmZ d dlmZ d dlmZ dZdZ	 G d d      Z
y	)
    )date)	lru_cache)Optional)
_timedeltaKHMER_CALENDARTHAI_CALENDARc                      e Zd ZdZh dZh dZ eddd      ZdZdZ	e
fddZed	efd       Zedd       Zeded	ee   fd       Zdded	ee   fdZdded	ee   fdZded	ee   fdZdded	ee   fdZded	ee   fdZded	ee   fdZded	ee   fdZded	ee   fdZded	ee   fdZded	ee   fdZded	ee   fdZded	ee   fdZy
)_ThaiLunisolaru  Thai Lunar Calendar Holidays.

    Works from 1913 (B.E. 2456/2455) onwards until 2157 (B.E. 2700), as we only have
    Thai year-type data for cross-checking through that period.

    ## The basics of the Thai Lunar Calendar:

    3-year types for calendar intercalation:
        * Pakatimat (Normal Year):
            Consists of 12 months, totaling 354 days.
        * Athikawan (Extra-Day Year):
            Adds one extra day to the 7th month, totaling 355 days for synodic month correction.
        * Athikamat (Extra-Month Year):
            Adds one extra 8th month, totaling 384 days for sidereal year correction.

    Months alternate between 30 (even months) and 29 (odd months) days.

    The waxing phase (Full Moon) lasts 15 days, while the waning phase (New Moon) lasts
    14 days for odd months (except Month 7 in Athikawan years), 15 days for even months.

    The second "Month 8" for Athikamat years is called "Month 8.8"
    (read as "the latter 8th month"), with all observed holidays
    delayed from the usual calendar by 30 days.

    Implemented Thai Lunar Calendar holiday methods:
        * Magha Puja / Makha Bucha / Meak Bochea:
            15th Waxing Day (Full Moon) of Month 3 (On Month 4 for Athikamat Years).
            `KHMER_CALENDAR` always falls on Month 3.

        * Vesak / Visakha Bucha / Visaka Bochea:
            15th Waxing Day (Full Moon) of Month 6 (On Month 7 for Athikamat Years).
            `KHMER_CALENDAR` always falls on Month 6.

        * Cambodian Royal Ploughing Ceremony / Preah Neangkol:
            4th Waning Day of Month 6 (On Month 7 for Athikamat Years).
            Defaults to `KHMER_CALENDAR` (its sole user).

        * Buddha's Cremation Day / Atthami Bucha:
            8th Waning Day of Month 6 (On Month 7 for Athikamat Years).
            `KHMER_CALENDAR` always falls on Month 6.

        * Asalha Puja / Asarnha Bucha:
            15th Waxing Day (Full Moon) of Month 8 (On Month 8.8 for Athikamat Years).

        * Buddhist Lent Day / Wan Khao Phansa:
            1st Waning Day of Month 8 (On Month 8.8 for Athikamat Years).

        * Boun Haw Khao Padapdin / Boon Khao Padap Din:
            14th Waning Day (New Moon) of Month 9.

        * Boun Haw Khao Salark / Boon Khao Sak:
            15th Waxing Day (Full Moon) of Month 10.

        * Pchum Ben / Prachum Bandar:
            15th Waning Day (New Moon) of Month 10.

        * Ok Boun Suang Huea / Vientiane Boat Racing Festival:
            1st Waning Day (New Moon) of Month 11.

        * Loy Krathong / Boun That Louang / Bon Om Touk:
            15th Waxing Day (Full Moon) of Month 12.

    Other Thai Lunar Calendar holidays:
        * Thai Royal Ploughing Ceremony / Raeknakhwan:
            Court astrologers choose the auspicious dates based on the Thai Lunar Calendar,
            but these dates do not follow a predictable pattern.
            See the specific section in `thailand.py` for more details.

        * End of Buddhist Lent Day / Ok Phansa:
            15th Waxing Day (Full Moon) of Month 11
            (Currently calculated based on Asalha Puja / Asarnha Bucha method).

    Notes:
        The following code is based on Ninenik Narkdee's PHP implementation,
        and we're thankful for his work.

    References:
        * <https://www.ninenik.com/แนวทางฟังก์ชั่น_php_อย่างง่ายกับการหาวันข้างขึ้นข้างแรม-1021.html>
        * <https://www.myhora.com/ปฏิทิน/ปฏิทิน-พ.ศ.2560.aspx>

    Example:

        >>> from holidays.calendars.thai import _ThaiLunisolar
        >>> thls = _ThaiLunisolar()
        >>> print(thls.visakha_bucha_date(2010))
        2010-05-28

    >0       
        #  &  ,  1  7  =  ?  E  I  N  U  X  ^  c  i  }                                                    z  >Z                               "  %  (  +  .  0  3  5  8  ;  @  B  D  G  J  L  O  R  T  W  Z  ]  `  b  e  g  j  {  ~                                                                                                m  iy        r:   r   returnNc                 4    | j                  |       || _        y N)_ThaiLunisolar__verify_calendar_ThaiLunisolar__calendar)selfcalendars     W/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/holidays/calendars/thai.py__init__z_ThaiLunisolar.__init__  s    x("    c                     | t         k(  S )zCheck if the given calendar is the Khmer calendar.

        Args:
            calendar:
                The calendar identifier to check.

        Returns:
            True if the calendar is `KHMER_CALENDAR`, False otherwise.
        )r   r   s    r   __is_khmer_calendarz"_ThaiLunisolar.__is_khmer_calendar  s     >))r   c                 >    | t         t        hvrt        d|  d      y)zVerify calendar type.zUnknown calendar name: z*. Use `KHMER_CALENDAR` or `THAI_CALENDAR`.N)r   r   
ValueErrorr   s    r   __verify_calendarz _ThaiLunisolar.__verify_calendar   s0     NM::)(3]^  ;r   yearc                 N   |t         j                  k  s|t         j                  kD  ryd|t         j                  z
  z  }t        t         j                  |      D ]2  }|t         j                  v r|dz  }|t         j
                  v s.|dz  }4 t        t         j                  |      S )a  Calculate the start date of that particular Thai Lunar Calendar Year.

        This usually falls in November or December of the previous Gregorian
        year in question. Should the year be outside of working scope
        (1914-2157: B.E 2457-2700), this will returns None instead.

        Args:
            year:
                The Gregorian year.

        Returns:
             The start date of Thai Lunar Calendar for a Gregorian year.
        Nib        )r
   
START_YEAREND_YEARrangeATHIKAMAT_YEARS_GREGORIANATHIKAWAN_YEARS_GREGORIANr   
START_DATE)r   r   
delta_days	iter_years       r   _get_start_datez_ThaiLunisolar._get_start_date(  s     .+++tn6M6M/MD>#<#<<=
~88$?INDDDb 
nFFFa
	 @ .33Z@@r   c                     |xs | j                   }| j                  |       | j                  |      }|syt        ||t        j
                  v r| j                  |      sd      S d      S )a  Calculate the estimated Gregorian date of Makha Bucha.

        Also known as "Magha Puja", "Makha Buxha" and "Meak Bochea".
        This coincides with the 15th Waxing Day of Month 3
        in Thai Lunar Calendar, or Month 4 in Athikamat years.

        `KHMER_CALENDAR` will always use Month 3 regardless of year type.

        To calculate, we use the following time delta:

        * Athikamat:
            15th Waxing Day of Month 4 or 29[1] + 30[2] + 29[3] + 15[4] -1 = 102

        * Athikawan:
            15th Waxing Day of Month 3 or 29[1] + 30[2] + 15[3] -1 = 73

        * Pakatimat:
            15th Waxing Day of Month 3 or 29[1] + 30[2] + 15[3] -1 = 73

        Args:
            year:
                The Gregorian year.

            calendar:
                Calendar type, this defaults to THAI_CALENDAR.

        Returns:
            Estimated Gregorian date of Makha Bucha.
            Returns None if the Gregorian year input is invalid.
        Nf   I   r   r   r   r   r
   r   !_ThaiLunisolar__is_khmer_calendarr   r   r   
start_dates       r   makha_bucha_datez_ThaiLunisolar.makha_bucha_dateC  sx    > .tx())$/
 @@@00: 
 	
 
 	
r   c                     |xs | j                   }| j                  |       | j                  |      }|syt        ||t        j
                  v r| j                  |      sd      S d      S )a  Calculate the estimated Gregorian date of Visakha Bucha.

        Also known as "Vesak" and "Buddha Day". This coincides with
        the 15th Waxing Day of Month 6 in Thai Lunar Calendar, or Month 7 in Athikamat years.

        `KHMER_CALENDAR` will always use Month 6 regardless of year type.

        To calculate, we use use the following time delta:

        * Athikamat:
            15th Waxing Day of Month 7 or 177[1-6] + 15[7] -1 = 191

        * Athikawan:
            15th Waxing Day of Month 6 or 147[1-5] + 15[6] -1 = 161

        * Pakatimat:
            15th Waxing Day of Month 6 or 147[1-5] + 15[6] -1 = 161

        Args:
            year:
                The Gregorian year.

            calendar:
                Calendar type, this defaults to THAI_CALENDAR.

        Returns:
            Estimated Gregorian date of Visakha Bucha.
            Returns None if the Gregorian year input is invalid.
        N      r   r   s       r   visakha_bucha_datez!_ThaiLunisolar.visakha_bucha_dates  sx    < .tx())$/
 @@@00: 
 	
 
 	
r   c                 B    | j                  |      }|syt        |d      S )a  Calculate the estimated Gregorian date of Preah Neangkoal.

        Also known as "Cambodian Royal Ploughing Ceremony". This always
        coincides with the 4th Waning Day of Month 6 in Khmer Lunar Calendar.

        To calculate, we use use the following time delta:

        * Athikamat:
            4th Waning Day of Month 6 (Khmer Lunar Calendar) or 177[1-5] + 19[6] -1 = 165

        * Athikawan:
            4th Waning Day of Month 6 or 147[1-5] + 19[6] -1 = 165

        * Pakatimat:
            4th Waning Day of Month 6 or 147[1-5] + 19[6] -1 = 165

        Or as in simpler terms: "Visakha Bucha" (Khmer Lunar Calendar) +4.

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Preah Neangkoal.
        N   )r   r   )r   r   r   s      r   preah_neangkoal_datez#_ThaiLunisolar.preah_neangkoal_date  s'    4 ))$/
*d++r   c                     |xs | j                   }| j                  |       | j                  |      }|syt        ||t        j
                  v r| j                  |      sd      S d      S )a  Calculate the estimated Gregorian date of Atthami Bucha.

        Also known as "Buddha's Cremation Day". This coincides with
        the 8th Waning Day of Month 6 in Thai Lunar Calendar, or Month 7 in Athikamat years.

        `KHMER_CALENDAR` will always use Month 6 regardless of year type.

        To calculate, we use use the following time delta:

        * Athikamat:
            8th Waning Day of  Month 7 or 177[1-6] + 23[7] -1 = 199

        * Athikawan:
            8th Waning Day of  Month 6 or 147[1-5] + 23[6] -1 = 169

        * Pakatimat:
            8th Waning Day of  Month 6 or 147[1-5] + 23[6] -1 = 169

        Or as in simpler terms: "Visakha Bucha" +8

        Args:
            year:
                The Gregorian year.

            calendar:
                Calendar type, this defaults to THAI_CALENDAR.

        Returns:
            Estimated Gregorian date of Atthami Bucha.
            Returns None if the Gregorian year input is invalid.
        N      r   r   s       r   atthami_bucha_datez!_ThaiLunisolar.atthami_bucha_date  sy    @ .tx())$/
 @@@00: 
 	
 
 	
r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )a|  Calculate the estimated Gregorian date of Asarnha Bucha.

        Also known as "Asalha Puja". This coincides with
        the 15th Waxing Day of Month 8 in Thai Lunar Calendar,
        or Month 8.8 in Athikamat years.

        Lao Start of Buddhist Lent start on this day (1-day earlier than Thai and Khmer ones).

        To calculate, we use the following time delta:

        * Athikamat:
            15th Waxing Day of Month 8/8 or 177[1-6] + 29[7] + 30[8] + 15[8.8] -1 = 250

        * Athikawan:
            15th Waxing Day of Month 8 or 177[1-6] + 30[7] + 15[8] -1 = 221

        * Pakatimat:
            15th Waxing Day of Month 8 or 177[1-6] + 29[7] + 15[8] -1 = 220

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Asarnha Bucha.
            Returns None if the Gregorian year input is invalid.
        N         r   r
   r   r   r   r   r   r   r   s       r   asarnha_bucha_datez!_ThaiLunisolar.asarnha_bucha_date  R    8 ))$/
>;;;J^===JJ*j11r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )an  Calculate the estimated Gregorian date of Khao Phansa.

        Also known as "(Start of) Buddhist Lent" and "Start of Vassa".
        This coincides with the 1st Waning Day of Month 8
        in Thai Lunar Calendar, or Month 8.8 in Athikamat years.

        To calculate, we use use the following time delta:

        * Athikamat:
            1st Waning Day of Month 8.8 or 177[1-6] + 29[7] + 30[8] + 16[8.8] -1 = 251

        * Athikawan:
            1st Waning Day of Month 8 or 177[1-6] + 30[7] + 16[8] -1 = 222

        * Pakatimat:
            1st Waning Day of Month 8 or 177[1-6] + 29[7] + 16[8] -1 = 221

        Or as in simpler terms: "Asarnha Bucha" +1

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Khao Phansa.
            Returns None if the Gregorian year input is invalid.
        N      r   r   r   s       r   khao_phansa_datez_ThaiLunisolar.khao_phansa_date  r   r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )a  Calculate the estimated Gregorian date of Boun Haw Khao Padapdin.

        Also known as "Boon Khao Padap Din".
        This coincides with the 14th Waning Day of Month 9 in Thai Lunar Calendar.

        To calculate, we use use the following time delta:

        * Athikamat:
            14th Waning Day of Month 9 or 236[1-8] + 30[8.8] + 29[9] -1 = 294

        * Athikawan:
            14th Waning Day of Month 9 or 236[1-8] + 1[7] + 29[9] -1 = 265

        * Pakatimat:
            14th Waning Day of Month 9 or 236[1-8] + 29[9] -1 = 264

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Boun Haw Khao Padapdin.
            Returns None if the Gregorian year input is invalid.
        N&  i	  i  r   r   s       r   boun_haw_khao_padapdin_datez*_ThaiLunisolar.boun_haw_khao_padapdin_dateC  R    2 ))$/
>;;;J^===JJ*j11r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )a  Calculate the estimated Gregorian date of Boun Haw Khao Salark.

        Also known as "Boon Khao Sak".
        This coincides with the 15th Waxing Day of Month 10 in Thai Lunar Calendar.

        To calculate, we use use the following time delta:

        * Athikamat:
            15th Waxing Day of Month 10 or 265[1-9] + 30[8.8] + 15[10] -1 = 309

        * Athikawan:
            15th Waxing Day of Month 10 or 265[1-9] + 1[7] + 15[10] -1 = 280

        * Pakatimat:
            15th Waxing Day of Month 10 or 265[1-9] + 15[10] -1 = 279

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Boun Haw Khao Salark.
            Returns None if the Gregorian year input is invalid.
        N5  i  i  r   r   s       r   boun_haw_khao_salark_datez(_ThaiLunisolar.boun_haw_khao_salark_dateh  r   r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )a  Calculate the estimated Gregorian date of Pchum Ben.

        Also known as "Prachum Bandar".
        This coincides with the 15th Waning Day of Month 10 in Thai Lunar Calendar.

        To calculate, we use use the following time delta:

        * Athikamat:
            15th Waning Day of Month 10 or 265[1-9] + 30[8.8] + 30[10] -1 = 324

        * Athikawan:
            15th Waning Day of Month 10 or 265[1-9] + 1[7] + 30[10] -1 = 295

        * Pakatimat:
            15th Waning Day of Month 10 or 265[1-9] + 30[10] -1 = 294

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Pchum Ben.
            Returns None if the Gregorian year input is invalid.
        NiD  i'  r   r   r   s       r   pchum_ben_datez_ThaiLunisolar.pchum_ben_date  r   r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )a  Calculate the estimated Gregorian date of Ok Phansa.

        Also known as "End of Buddhist Lent" and "End of Vassa".
        This coincides with the 15th Waxing Day of Month 11 in Thai Lunar Calendar.

        To calculate, we use use the following time delta:

        * Athikamat:
            15th Waxing Day of Month 11 or 295[1-10] + 30[8.8] + 15[11] -1 = 339

        * Athikawan:
            15th Waxing Day of Month 11 or 295[1-10] + 1[7] + 15[11] -1 = 310

        * Pakatimat:
            15th Waxing Day of Month 11 or 295[1-10] + 15[11] -1 = 309

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Ok Phansa.
            Returns None if the Gregorian year input is invalid.
        NS  6  r   r   r   s       r   ok_phansa_datez_ThaiLunisolar.ok_phansa_date  r   r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )a+  Calculate the estimated Gregorian date of Ok Boun Suang Huea.

        Boun Suang Huea Nakhone Luang Prabang, also known as "Vientiane Boat Racing Festival".
        This coincides with the 1st Waning Day of Month 11 in Thai Lunar Calendar.

        To calculate, we use use the following time delta:

        * Athikamat:
            1st Waning Day of Month 11 or 295[1-10] + 30[8.8] + 16[11] -1 = 340

        * Athikawan:
            1st Waning Day of Month 11 or 295[1-10] + 1[7] + 16[11] -1 = 311

        * Pakatimat:
            1st Waning Day of Month 11 or 295[1-10] + 16[11] -1 = 310

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Boun Suang Huea.
            Returns None if the Gregorian year input is invalid.
        NiT  i7  r   r   r   s       r   boun_suang_heua_datez#_ThaiLunisolar.boun_suang_heua_date  r   r   c                     | j                  |      }|sy|t        j                  v rd}n|t        j                  v rd}nd}t	        ||      S )a  Calculate the estimated Gregorian date of Loy Krathong.

        Also known as "Boun That Louang" and "Bon Om Touk".
        This coincides with the 15th Waxing Day of Month 12 in Thai Lunar Calendar.

        To calculate, we use use the following time delta:

        * Athikamat:
            15th Waxing Day of Month 12 or 324[1-11] + 30[8.8] + 15[11] -1 = 368

        * Athikawan:
            15th Waxing Day of Month 12 or 324[1-11] + 1[7] + 15[11] -1 = 339

        * Pakatimat:
            15th Waxing Day of Month 12 or 324[1-11] + 15[11] -1 = 338

        Args:
            year:
                The Gregorian year.

        Returns:
            Estimated Gregorian date of Loy Krathong.
            Returns None if the Gregorian year input is invalid.
        Nip  r   iR  r   r   s       r   loy_krathong_datez _ThaiLunisolar.loy_krathong_date  r   r   )r   Nr   ) __name__
__module____qualname____doc__r   r   r   r   r   r   r   r   staticmethodboolr   r   r   intr   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r
   r
      s   Wv1!l[!D dB#JJH - # 
* 
* 
*   AC AHTN A A4.
S .
HTN .
`-
s -
htn -
^, ,$ ,@/
s /
htn /
b&2s &2x~ &2P&2S &2Xd^ &2P#2 #2 #2J#2c #2htn #2J#23 #28D> #2J#23 #28D> #2J#2 #2$ #2J#2c #2htn #2r   r
   N)datetimer   	functoolsr   typingr   holidays.calendars.gregorianr   r   r   r
   r   r   r   <module>r      s)       3!H2 H2r   