
    `f:                       d Z ddlmZ ddlZddl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mZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ej#        dk    rddl$m%Z% nddl&m%Z% dZ'ej(        )                    dd          Z*dZ+ e, e-e+ e.d                              Z/d d d dZ0ddd fdd d! fd"d#d$ fd%d&d' ffZ1 ed          Z2dZ3 G d( d)e          Z4 G d* d+          Z5 e5            Zdgd0Z6dhd3Z7	 	 didjd:Z8dkd>Z9dld@Z:	 	 dmdndFZ;dodIZ<dpdJZ=dqdMZ>drdNZ?dsdOZ@dsdPZAdtdQZB	 	 dudvdUZC G dV dW          ZDeejE        fdwd\ZFeFfdxdaZG	 dydzdfZHdS ){z<Utilities related to dates, times, intervals, and timezones.    )annotationsN)
monthrange)datedatetime	timedelta)timezonetzinfo)
ModuleType)AnyCallabletz)isoparse)reprcall)cached_property   )
dictfilter)	pluralize)   	   )ZoneInfo)LocalTimezoner   maybe_timedeltadelta_resolution	remainingrateweekdayhumanize_secondsmaybe_iso8601is_naive
make_awarelocalizeto_utcmaybe_make_awareffwd	utcoffsetadjust_timestamp get_exponential_backoff_interval
C_REMDEBUGF)sunmontuewedthufrisat   c                    | S N ns    C/var/www/html/env/lib/python3.11/site-packages/celery/utils/time.py<lambda>r9   -   s    1     c                    | dz  S N      N@r5   r6   s    r8   r9   r9   .   s
    1t8 r:   c                    | dz  dz  S r<   r5   r6   s    r8   r9   r9   /   s    1t8d? r:   )smhdayg     @c                "    t          | d          S N.2fformatr6   s    r8   r9   r9   3   s    fQ&6&6 r:   hourg      @c                "    t          | d          S rD   rF   r6   s    r8   r9   r9   4   s    &E"2"2 r:   minuter=   c                "    t          | d          S rD   rF   r6   s    r8   r9   r9   5   s    va// r:   second      ?c                "    t          | d          S rD   rF   r6   s    r8   r9   r9   6   s    fQ.. r:   c                  d     e Zd ZU dZi Zded<   d fdZddZddZddZ	ddZ
ddZddZ xZS )r   a  Local time implementation. Provided in _Zone to the app when `enable_utc` is disabled.
    Otherwise, _Zone provides a UTC ZoneInfo instance as the timezone implementation for the application.

    Note:
        Used only when the :setting:`enable_utc` setting is disabled.
    zdict[int, tzinfo]_offset_cachereturnNonec                "   t          t          j                   | _        t          j        r!t          t          j                   | _        n| j        | _        | j        | j        z
  | _        t                      	                                 d S )Nseconds)
r   _timer   	STDOFFSETdaylightaltzone	DSTOFFSETDSTDIFFsuper__init__)self	__class__s    r8   r]   zLocalTimezone.__init__H   sr     #EN?;;;> 	,&~>>>DNN!^DN~6r:   strc                ^    dt          | j                                        dz            ddS )Nz<LocalTimezone: UTC  z+03d>)intrZ   total_secondsr^   s    r8   __repr__zLocalTimezone.__repr__S   s1    WS)E)E)G)G$)N%O%OWWWWWr:   dtr   r   c                H    |                      |          r| j        n| j        S r4   )_isdstrZ   rW   r^   rh   s     r8   r'   zLocalTimezone.utcoffsetV   s    !%RDt~~dnDr:   c                H    |                      |          r| j        nt          S r4   )rj   r[   ZEROrk   s     r8   dstzLocalTimezone.dstY   s    #{{28t||D8r:   c                L    t           j        |                     |                   S r4   )rV   tznamerj   rk   s     r8   rp   zLocalTimezone.tzname\   s    |DKKOO,,r:   c                4   t          |                     |          j        dz            }	 | j        |         }n7# t          $ r* t          t          |                    x}| j        |<   Y nw xY w|                    |                    |                    S )Nr=   )minutesr	   )	rd   r'   rU   rP   KeyErrordatetime_timezoner   fromutcreplace)r^   rh   offsetr   s       r8   ru   zLocalTimezone.fromutc_   s     T^^B''/$677	+#F+BB 	+ 	+ 	+.?&)))/+ /+ +B#F+++	+ zz"**B*//000s   : 1A.-A.boolc           	         |j         |j        |j        |j        |j        |j        |                                ddf	}t          j        |          }t          j	        |          }|j
        dk    S )Nr   )yearmonthrB   rH   rJ   rL   r   rV   mktime	localtimetm_isdst)r^   rh   ttstamps       r8   rj   zLocalTimezone._isdstj   s^    grxgry")jjllAq" R  _U##{Qr:   )rQ   rR   rQ   r`   )rh   r   rQ   r   )rh   r   rQ   r`   rh   r   rQ   r   rh   r   rQ   rx   )__name__
__module____qualname____doc__rP   __annotations__r]   rg   r'   rn   rp   ru   rj   __classcell__)r_   s   @r8   r   r   >   s           (*M))))	 	 	 	 	 	X X X XE E E E9 9 9 9- - - -	1 	1 	1 	1       r:   r   c                  n    e Zd ZdZdddZddd	Zdd
ZddZddZe	dd            Z
e	dd            ZdS )_Zoneag  Timezone class that provides the timezone for the application.
    If `enable_utc` is disabled, LocalTimezone is provided as the timezone provider through local().
    Otherwise, this class provides a UTC ZoneInfo instance as the timezone provider for the application.

    Additionally this class provides a few utility methods for converting datetimes.
    Nr
   tzinfo | NonerQ   c                >    || j         S |                     |          S )z:Return either our local timezone or the provided timezone.)localget_timezone)r^   r
   s     r8   tz_or_localz_Zone.tz_or_local{   s%     >:  (((r:   rh   r   c                    t          |          rt          ||p| j                  }t          ||                     |                    S )z*Converts a datetime to the local timezone.)r!   r"   utcr#   r   )r^   rh   r   origs       r8   to_localz_Zone.to_local   sF     B<< 	2B 011BD,,U33444r:   c                .    |                     d          S )z+Converts a datetime to the system timezone.Nr   )
astimezonerk   s     r8   	to_systemz_Zone.to_system   s    
 }}}%%%r:   c                t    t          |          rt          || j                  S t          || j                  S )zBConverts a datetime to the local timezone, or the system timezone.)r!   r"   r   r#   rk   s     r8   to_local_fallbackz_Zone.to_local_fallback   s4    B<< 	.b$*---DJ'''r:   zonestr | tzinfoc                N    t          |t                    rt          |          S |S )zVReturns ZoneInfo timezone if the provided zone is a string, otherwise return the zone.)
isinstancer`   r   )r^   r   s     r8   r   z_Zone.get_timezone   s%    dC   	"D>>!r:   r   c                    t                      S )z2Return LocalTimezone instance for the application.)r   rf   s    r8   r   z_Zone.local   s     r:   c                ,    |                      d          S )z*Return UTC timezone created with ZoneInfo.UTC)r   rf   s    r8   r   z	_Zone.utc   s       '''r:   r4   )r
   r   rQ   r
   )NN)rh   r   r   )r   r   rQ   r
   )rQ   r   )rQ   r
   )r   r   r   r   r   r   r   r   r   r   r   r   r5   r:   r8   r   r   s   s         ) ) ) ) )5 5 5 5 5& & & &( ( ( (       _ ( ( ( _( ( (r:   r   deltard   rQ   r   c                Z    t          | t          j                  rt          |           S | S )z8Convert integer to timedelta, if argument is an integer.rT   )r   numbersRealr   )r   s    r8   r   r      s,    %&& (''''Lr:   rh   r   c                   t          |                                d          }dd fdd fdd ff}| j        | j        | j        | j        | j        | j        f}|D ]/\  }} ||          dk    rt          |d	|         d
| j	        ic S 0| S )a  Round a :class:`~datetime.datetime` to the resolution of timedelta.

    If the :class:`~datetime.timedelta` is in days, the
    :class:`~datetime.datetime` will be rounded to the nearest days,
    if the :class:`~datetime.timedelta` is in hours the
    :class:`~datetime.datetime` will be rounded to the nearest hour,
    and so on until seconds, which will just return the original
    :class:`~datetime.datetime`.
    r   r   c                    | dz  S )NiQ r5   xs    r8   r9   z"delta_resolution.<locals>.<lambda>   s
    U r:      c                    | dz  S )Nrb   r5   r   s    r8   r9   z"delta_resolution.<locals>.<lambda>   s
    T r:      c                    | dz  S )N<   r5   r   s    r8   r9   z"delta_resolution.<locals>.<lambda>   s
    R r:   rM   Nr
   )
maxre   rz   r{   rB   rH   rJ   rL   r   r
   )rh   r   resolutionsargsres	predicates         r8   r   r      s     ##%%q))E**+))*''(*K 7BHbfbgry")CD% ; ;Y9Us""T$3$Z:	::::: #Ir:   startends_innowCallable | Nonerelativerx   c           	        |pt          j                    }t          | j                  t          |j                  k    rE|                                |                                 k    r|                     |j                  } | |z   }|r$t          ||                              d          }||z
  }t          r&t          d	                    || |||                     |S )a_  Calculate the remaining time for a start date and a timedelta.

    For example, "how many seconds left for 30 seconds after start?"

    Arguments:
        start (~datetime.datetime): Starting date.
        ends_in (~datetime.timedelta): The end delta.
        relative (bool): If enabled the end time will be calculated
            using :func:`delta_resolution` (i.e., rounded to the
            resolution of `ends_in`).
        now (Callable): Function returning the current time and date.
            Defaults to :func:`datetime.utcnow`.

    Returns:
        ~datetime.timedelta: Remaining time.
    r	   r   )microsecondz8rem: NOW:{!r} START:{!r} ENDS_IN:{!r} END_DATE:{} REM:{})
r   utcnowr`   r
   r'   rv   r   r*   printrG   )r   r   r   r   end_daterets         r8   r   r      s    & 
"""C
L  J  MMOOu/@/@@@SZ00wH N#Hg66>>1>MM
S.C 1HOO30 0 	1 	1 	1Jr:   rr`   floatc                    | rXt          | t                    r?|                     d          \  }}}t          |pd         t	          |                    pdS | pdS dS )zAConvert rate string (`"100/m"`, `"2/h"` or `"0.5/s"`) to seconds./r?   r   )r   r`   	partitionRATE_MODIFIER_MAPr   )r   ops_modifiers       r8   r   r      se     a 	G {{3//CH$X_5eCjjAAFQFvA1r:   namec                    | dd                                          }	 t          |         S # t          $ r t          |           w xY w)zReturn the position of a weekday: 0 - 7, where 0 is Sunday.

    Example:
        >>> weekday('sunday'), weekday('sun'), weekday('mon')
        (0, 0, 1)
    r   r   )lowerWEEKDAYSrs   )r   abbreviations     r8   r   r      sR     !9??$$L%%   tnns	   + A secsprefixsepmicrosecondsc           
     H   t          t          t          |           d                    } t          D ]O\  }}}| |k    rC| t          |          z  }d                    || ||          t          ||                    c S P|r| dk    rd                    | ||          S |S )a[  Show seconds in human form.

    For example, 60 becomes "1 minute", and 7200 becomes "2 hours".

    Arguments:
        prefix (str): can be used to add a preposition to the output
            (e.g., 'in' will give 'in 1 second', but add nothing to 'now').
        now (str): Literal 'now'.
        microseconds (bool): Include microseconds.
    rE   z	{}{}{} {}g        z{prefix}{sep}{0:.2f} seconds)r   r   )r   rG   
TIME_UNITSr   )	r   r   r   r   r   unitdivider	formatterws	            r8   r   r     s     dU++,,D$. : : gy7??uW~~%A%%fc99Q<<&/4&8&8: : : : :   *s

-44c& 5 * * 	*Jr:   datetime | str | NoneNone | datetimec                V    | sdS t          | t                    r| S t          |           S )z:Either ``datetime | str -> datetime`` or ``None -> None``.N)r   r   r   rh   s    r8   r    r      s2     "h 	B<<r:   c                L    | j         du p| j                             |           du S )z_Return True if :class:`~datetime.datetime` is naive, meaning it doesn't have timezone info set.N)r
   r'   r   s    r8   r!   r!   '  s)    9?	 3 3B 7 74 ??r:   r   r
   c                L    t          | t                    pt          | d          S )zUHelper function to determine if a timezone can detect ambiguous times using dateutil.is_ambiguous)r   r   hasattrr   s    r8   _can_detect_ambiguousr   ,  s#     b(##Bwr>'B'BBr:   c                H    t          |          ot          j        |           S )a  Helper function to determine if a timezone is ambiguous using python's dateutil module.

    Returns False if the timezone cannot detect ambiguity, or if there is no ambiguity, otherwise True.

    In order to detect ambiguous datetimes, the timezone must be built using ZoneInfo, or have an is_ambiguous
    method. Previously, pytz timezones would throw an AmbiguousTimeError if the localized dt was ambiguous,
    but now we need to specifically check for ambiguity with dateutil, as pytz is deprecated.
    )r   dateutil_tzdatetime_ambiguousrh   r   s     r8   _is_ambigiousr   2  s"     !$$K)G)K)KKr:   c                    |                      |          } t          | |          r8t          |                      d          |                      d                    } | S )z6Set timezone for a :class:`~datetime.datetime` object.r	   r   )foldr   )rv   r   minr   s     r8   r"   r"   ?  sY     
2		BR 9##RZZQZ%7%788Ir:   c                    t          |           rt          | |          } | j        t          d          k    r|                     |          } | S )zConvert aware :class:`~datetime.datetime` to another timezone.

    Using a ZoneInfo timezone will give the most flexibility in terms of ambiguous DST handling.
    r   )r!   r"   r
   r   r   r   s     r8   r#   r#   H  sJ    
 ||  B	yHUOO##]]2Ir:   c                6    t          | t          j                  S )z1Convert naive :class:`~datetime.datetime` to UTC.)r"   r   r   r   s    r8   r$   r$   T  s    b(,'''r:   Tr   naive_as_utcc                    t          |           rG|rt          |           } t          | |t          j        nt                              |                    S | S )z@Convert dt to aware datetime, do nothing if dt is already aware.)r!   r$   r#   r   r   r   )rh   r   r   s      r8   r%   r%   Y  s[     || 
 	B
0D0DR0H0H
 
 	
 Ir:   c                  8    e Zd ZdZ	 	 dddZdd	ZddZddZdS )r&   zBVersion of ``dateutil.relativedelta`` that only supports addition.Nr   kwargsr   c
                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |dz  | _	        | j        d up| j        d u| _
        d S )Nr2   )rz   r{   weeksr   rB   rH   rJ   rL   r   days	_has_time)r^   rz   r{   r   r   rB   rH   rJ   rL   r   r   s              r8   r]   zffwd.__init__h  sm    
 	

	&AI	$.I$+T2Ir:   rQ   r`   c                b    t          dd|                     | j        | j                            S )Nr&   r5   )r   r   )r   _fieldsr   r   rf   s    r8   rg   zffwd.__repr__y  s;    DLLtz9= %1 %G %G H H 	Hr:   otherr   c           
        t          |t                    st          S | j        p|j        }| j        p|j        }t          t          ||          d         | j        p|j                  } |j        di t          t          |                                           |||          }| j        3|t          d|                                z
  | j        z   dz            z  }|t          | j                  z   S )Nr   )rz   r{   rB   r2   )r   r5   )r   r   NotImplementedrz   r{   r   r   rB   rv   dictr   r   r   r   r   )r^   r   rz   r{   rB   r   s         r8   __radd__zffwd.__radd__}  s    %&& 	"!!y&EJ
)ek*T5))!,dh.C%)DDem E Ed:dllnn#=#=(,EsD D D E E<#91s{{}}#4t|#Cq"HIIIICYDI.....r:   extradict[str, Any]c           
     r    t          | j        | j        | j        | j        | j        | j        | j        dfi |S )N)rz   r{   rB   rH   rJ   rL   r   )r   rz   r{   rB   rH   rJ   rL   r   )r^   r   s     r8   r   zffwd._fields  sM    I
48Ik$2B
 
   	  	r:   )	NNr   NNNNNN)r   r   r   )r   r   rQ   r   )r   r   rQ   r   )r   r   r   r   r]   rg   r   r   r5   r:   r8   r&   r&   e  s~        LLIMBFJ J J J J"H H H H
/ 
/ 
/ 
/     r:   r&   timer   r}    Callable[..., _time.struct_time]c                H     |            j         r
| j        dz  S | j        dz  S )z*Return the current offset to UTC in hours.rb   )r~   rY   r   )r   r}   s     r8   r'   r'     s/     y{{ $|t##=D  r:   tsrw   hereCallable[..., float]c                (    | | |            z
  dz  z
  S )z-Adjust timestamp based on provided utcoffset.rb   r5   )r   rw   r   s      r8   r(   r(     s     $$&&D(((r:   factorretriesmaximumfull_jitterc                    t          || d|z  z            }|rt          j        |dz             }t          d|          S )z,Calculate the exponential backoff wait time.   r   r   )r   random	randranger   )r  r  r  r  	countdowns        r8   r)   r)     sJ     GVqG|455I  4$Y]33	q)r:   )r   rd   rQ   r   )rh   r   r   r   rQ   r   )NF)
r   r   r   r   r   r   r   rx   rQ   r   )r   r`   rQ   r   )r   r`   rQ   rd   )r   r   r   F)r   rd   r   r`   r   r`   r   r`   r   rx   rQ   r`   )rh   r   rQ   r   r   )r   r
   rQ   rx   )rh   r   r   r
   rQ   rx   )rh   r   r   r
   rQ   r   r   )NT)rh   r   r   r   r   rx   rQ   r   )r   r   r}   r   rQ   r   )r   r   rw   rd   r   r  rQ   r   )F)
r  rd   r  rd   r  rd   r  rx   rQ   rd   )Ir   
__future__r   r   osr	  sysr   rV   calendarr   r   r   r   r   rt   r
   typesr   typingr   r   dateutilr   r   dateutil.parserr   kombu.utils.functionalr   kombu.utils.objectsr   
functionalr   textr   version_infozoneinfor   backports.zoneinfo__all__environgetr*   DAYNAMESr   zipranger   r   r   rm   _local_timezoner   r   r   r   r   r   r   r   r    r!   r   r   r"   r#   r$   r%   r&   r}   r'   r(   r)   r5   r:   r8   <module>r"     sj   B B " " " " " "  				  



           . . . . . . . . . . 2 2 2 2 2 2                             & & & & & & $ $ $ $ $ $ + + + + + + / / / / / / " " " " " "      v!!!!!!!++++++ Z^^L%00
:4HeeAhh''(( 
			"	"   N667Y223t//0s../	
 y||2 2 2 2 2F 2 2 2j2( 2( 2( 2( 2( 2( 2( 2(j 577      0 EI         F        @E"    2   @ @ @ @
C C C C
L 
L 
L 
L   	 	 	 	( ( ( (
 8<*.	 	 	 	 	) ) ) ) ) ) ) )Z !6;o! ! ! ! ! 3<) ) ) ) ) 	      r:   