o
    _oi9                     @  s   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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rHd dlmZ d!ddZG dd deZedde_edddddde_edde_G dd  d eZdS )"    )annotations)	timedelta)TYPE_CHECKING)cast)overloadN)SECONDS_PER_DAY)SECONDS_PER_HOUR)SECONDS_PER_MINUTE)US_PER_SECOND)PYPY)Selfafloatbreturnintc                 C  sZ   t | |\}}t|}|d9 }|dkr||kn||k }|s'||kr+|d dkr+|d7 }|S )zdivide a by b and round result to the nearest integer

    When the ratio is exactly half-way between two integers,
    the even integer is returned.
       r      )divmodr   )r   r   qrZgreater_than_half r   Y/var/www/html/kuke-dev/django-kuke/venv/lib/python3.10/site-packages/pendulum/duration.py_divide_and_round   s   r   c                   @  s  e Zd ZU dZdZded< dZded< dZded< dZded< dZ	ded	< dZ
ded
< dZded< dZded< dZdZdZdZdZdZdZdZ									dxdyddZdzddZdzddZdzdd Zdzd!d"Zerqdzd#d$Zed{d%d&Zed{d'd(Zed{d)d*Zered{d+d,Z ed{d-d.Z!ed{d/d0Z"ed{d1d2Z#ed{d3d4Z$ed{d5d6Z%ed{d7d8Z&ed|d:d;Z'd{d<d=Z(d{d>d?Z)d{d@dAZ*d{dBdCZ+d{dDdEZ,d}d~dKdLZ-ddNdOZ.ddQdRZ/ddSdTZ0ddUdVZ1ddXdYZ2e2Z3ddZd[Z4dd\d]Z5d{d^d_Z6ddadbZ7e7Z8e9ddcddZ:e9ddeddZ:ddhddZ:e9ddidjZ;e9ddkdjZ;ddndjZ;e:Z<ddodpZ=ddrdsZ>ddvdwZ?dS )Durationzo
    Replacement for the standard timedelta class.

    Provides several improvements over the base class.
    r   r   _totalr   _years_months_weeks_days_remaining_days_seconds_microsecondsNdayssecondsmicrosecondsmillisecondsminuteshoursweeksyearsmonthsr   r   c
              
   C  s  t |tr
t |	tstdt| ||d  |	d  ||||||}
|
 |d |	d  t  }||
_d}|dk r;d}t|| d |
_	t
t|t | |
_t
t|t | }||
_t
|d | |
_t
|d | |
_|	|
_||
_||	|||||||d	  d
|
_|
S )N'Float year and months are not supportedm     r   r       .A   i  )r*   r+   r)   r#   r(   r'   r$   r%   )
isinstancer   
ValueErrorr   __new__total_secondsr   r   roundr"   absr!   r   r    r   r   r   
_signature)clsr#   r$   r%   r&   r'   r(   r)   r*   r+   selftotalmr   r   r   r   r4   G   sF   
zDuration.__new__c                 C     |   t S N)r5   r	   r:   r   r   r   total_minutes      zDuration.total_minutesc                 C  r=   r>   )r5   r   r?   r   r   r   total_hours   rA   zDuration.total_hoursc                 C  r=   r>   )r5   r   r?   r   r   r   
total_days   rA   zDuration.total_daysc                 C  s   |   d S )Nr1   )rC   r?   r   r   r   total_weeks   rA   zDuration.total_weeksc                 C  sz   d}t | dr|| jd 7 }t | dr|| jd 7 }t | dr*|| jd | j 7 }n|| j7 }|t | j t | j	 t S )Nr   r   r-   r   r.   r    r1   )
hasattrr   r   r   r    r   r   r!   r
   r"   )r:   r#   r   r   r   r5      s   



zDuration.total_secondsc                 C     | j S r>   )r   r?   r   r   r   r*         zDuration.yearsc                 C  rF   r>   )r   r?   r   r   r   r+      rG   zDuration.monthsc                 C  rF   r>   )r   r?   r   r   r   r)      rG   zDuration.weeksc                 C  s   | j d | jd  | j S )Nr-   r.   )r   r   r   r?   r   r   r   r#      s   zDuration.daysc                 C  rF   r>   )r    r?   r   r   r   remaining_days   rG   zDuration.remaining_daysc                 C  sD   | j d u r| j}d| _ t|dkrt|d d | | | _ | j S )Nr   i     )_hr!   r7   _signr:   r$   r   r   r   r(         
zDuration.hoursc                 C  sD   | j d u r| j}d| _ t|dkrt|d d | | | _ | j S )Nr   <   )_ir!   r7   rK   rL   r   r   r   r'      rM   zDuration.minutesc                 C  rF   r>   )r!   r?   r   r   r   r$      rG   zDuration.secondsc                 C  s4   | j d u r| j| _ t| j d | | j  | _ | j S )NrN   )_sr!   r7   rK   r?   r   r   r   remaining_seconds   s   
zDuration.remaining_secondsc                 C  rF   r>   )r"   r?   r   r   r   r%      rG   zDuration.microsecondsboolc                 C  s   | j d u r|  dk | _ | j S Nr   )_invertr5   r?   r   r   r   invert   s   
zDuration.invertc                 C     t |  S r>   )r   rD   r?   r   r   r   in_weeks   rA   zDuration.in_weeksc                 C  rV   r>   )r   rC   r?   r   r   r   in_days   rA   zDuration.in_daysc                 C  rV   r>   )r   rB   r?   r   r   r   in_hours   rA   zDuration.in_hoursc                 C  rV   r>   )r   r@   r?   r   r   r   
in_minutes   rA   zDuration.in_minutesc                 C  rV   r>   )r   r5   r?   r   r   r   
in_seconds   rA   zDuration.in_seconds locale
str | None	separatorstrc              
   C  s  d| j fd| jfd| jfd| jfd| jfd| jfd| jfg}|du r&t }t	|}g }|D ]$}|\}}t
|d	krS|d
| d|t
| }	||	| q/|sd	}
t
| jd	krqd|d }t
| jd d}
nd|d	 }||}	||	|
 ||S )z
        Get the current interval in words in the current locale.

        Ex: 6 jours 23 heures 58 minutes

        :param locale: The locale to use. Defaults to current locale.
        :param separator: The separator to use between each unit
        yearmonthweekdayhourminutesecondNr   zunits..zunits.second.r   r0   z.2fzunits.microsecond.)r*   r+   r)   rH   r(   r'   rQ   pendulumZ
get_localer]   r7   translationpluralappendformatr%   join)r:   r]   r_   Z	intervalsZloaded_localepartsintervalunitZinterval_countrj   countr   r   r   in_words   s:   




zDuration.in_wordsvaluec                 C  s   |dk rdS dS )Nr   r/   r   r   )r:   rt   r   r   r   rK     s   zDuration._signr   c                 C  s   t |  dS )z<
        Return the interval as a native timedelta.
        r$   )r   r5   r?   r   r   r   as_timedelta$  s   zDuration.as_timedeltac                 C  s   |   S r>   )rs   r?   r   r   r   __str__*  s   zDuration.__str__c                 C  s   | j j d}| jr|d| j d7 }| jr|d| j d7 }| jr+|d| j d7 }| jr7|d| j d7 }| jrC|d| j d7 }| jrO|d| j d7 }| j	r[|d	| j	 d7 }| j
rg|d
| j
 d7 }|d7 }|ddS )N(zyears=z, zmonths=zweeks=zdays=zhours=zminutes=zseconds=zmicroseconds=)z, ))	__class____name__r   r   r   r   r    r(   r'   rQ   r%   replace)r:   repr   r   r   __repr__-  s&   zDuration.__repr__otherc                 C  s&   t |tr| j|  |  dS tS Nru   r2   r   rz   r5   NotImplementedr:   r   r   r   r   __add__L     
zDuration.__add__c                 C  s&   t |tr| j|  |  dS tS r   r   r   r   r   r   __sub__T  r   zDuration.__sub__c                 C  s.   | j | j | j | j | j | j | j dS )N)r*   r+   r)   r#   r$   r%   )rz   r   r   r   r    r!   r"   r?   r   r   r   __neg__Z  s   zDuration.__neg__c                 C  s   | j d | j d | j S )NiQ i@B )r   r!   r"   r?   r   r   r   _to_microsecondsd  s   zDuration._to_microsecondsint | floatc                 C  sf   t |tr| j| j| | j| | j| dS t |tr1|  }| \}}| ddt	|| |S t
S )N)r*   r+   r$   r   )r2   r   rz   r   r   r   r   r   as_integer_ratior   r   r:   r   usecr   r   r   r   r   __mul__g  s   

zDuration.__mul__c                 C     d S r>   r   r   r   r   r   __floordiv__y     zDuration.__floordiv__c                 C  r   r>   r   r   r   r   r   r   }  r   int | timedeltaint | Durationc                 C  sh   t |ttfs	tS |  }t |trtt||  S t |tr2| jdd|| | j| | j| dS d S Nr   )r*   r+   )	r2   r   r   r   r   r   rz   r   r   )r:   r   r   r   r   r   r     s    

c                 C  r   r>   r   r   r   r   r   __truediv__  r   zDuration.__truediv__c                 C  r   r>   r   r   r   r   r   r     r   int | float | timedeltaSelf | floatc                 C  s   t |tttfs
tS |  }t |trtt||  S t |tr6| jddt||t| j	|t| j
|dS t |trZ| \}}| jddt|| |t| j	| |t| j
|dS d S r   )r2   r   r   r   r   r   r   rz   r   r   r   r   r   r   r   r   r     s2   





c                 C  s,   t |tr|  |  }| dd|S tS rS   )r2   r   r   rz   r   )r:   r   r   r   r   r   __mod__  s   
zDuration.__mod__tuple[int, Duration]c                 C  s6   t |trt|  | \}}|| dd|fS tS rS   )r2   r   r   r   rz   r   )r:   r   r   r   r   r   r   
__divmod__  s   
zDuration.__divmod___dict[int, Self]c              	   C  s&   | j | j| j| j| j| j| j| jdS )N)r#   r$   r%   r'   r(   r*   r+   )rz   rH   rQ   r%   r'   r(   r*   r+   )r:   r   r   r   r   __deepcopy__  s   zDuration.__deepcopy__	r   r   r   r   r   r   r   r   r   )r#   r   r$   r   r%   r   r&   r   r'   r   r(   r   r)   r   r*   r   r+   r   r   r   r   r   )r   r   r   rR   )Nr\   )r]   r^   r_   r`   r   r`   )rt   r   r   r   )r   r   )r   r`   )r   r   r   r   )r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )@r{   
__module____qualname____doc__r   __annotations__r   r   r   r   r    r!   r"   Z_y_m_wZ_drJ   rO   rP   rT   r4   r@   rB   rC   rD   r   r5   propertyr*   r+   r)   r#   rH   r(   r'   r$   rQ   r%   rU   rW   rX   rY   rZ   r[   rs   rK   rv   rw   r~   r   __radd__r   r   r   r   __rmul__r   r   r   __div__r   r   r   r   r   r   r   r   .   s   
 
9



		





-












r   i6e)r#   iɚ;   ;   i?B )r#   r(   r'   r$   r%   r   )r%   c                   @  sF   e Zd ZdZ									ddddZdddZedddZdS )AbsoluteDurationzG
    Duration that expresses a time difference in absolute values.
    r   r#   r   r$   r%   r&   r'   r(   r)   r*   r+   r   c
              
   C  s   t |tr
t |	tstdt| |||||||}
t|||||||}| |
_t|
j}t|d d |
_	t
t|t\}|
_t||d  |	d  |
_t
|d\|
_|
_t|	|
_t||
_|
S )Nr,   r   r0   r-   r.   r1   )r2   r   r3   r   r4   r5   r   r7   r6   r"   r   r   r!   r   r   r    r   r   )r9   r#   r$   r%   r&   r'   r(   r)   r*   r+   r:   deltar;   r   r   r   r4     s"   



zAbsoluteDuration.__new__c                 C  s
   t | jS r>   )r7   r   r?   r   r   r   r5     s   
zAbsoluteDuration.total_secondsrR   c                 C  s   | j d u r| jdk | _ | j S rS   )rT   r   r?   r   r   r   rU     s   
zAbsoluteDuration.invertNr   )r#   r   r$   r   r%   r   r&   r   r'   r   r(   r   r)   r   r*   r   r+   r   r   r   r   r   )r{   r   r   r   r4   r5   r   rU   r   r   r   r   r     s    
&r   )r   r   r   r   r   r   )
__future__r   datetimer   typingr   r   r   ri   Zpendulum.constantsr   r   r	   r
   Zpendulum.utils._compatr   Ztyping_extensionsr   r   r   minmax
resolutionr   r   r   r   r   <module>   s0    
   0
