o
    _oi:%                     @  s8  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 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 d dlmZ d dlmZ er|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 G dd deeZed d d e_edddde_edde_dS )    )annotationsN)time)	timedelta)TYPE_CHECKING)Optional)cast)overload)SECS_PER_HOUR)SECS_PER_MIN)USECS_PER_SEC)AbsoluteDuration)Duration)FormattableMixin)UTC)Literal)Self)SupportsIndex)FixedTimezone)Timezonec                      s0  e Zd ZdZeefdYdd	ZdZddZd[ddZd[ddZ		d\d]ddZ
	d\d]ddZd^d d!Zd^d"d#Zd_d%d&Zed`d(d)Zed_d*d)Zdad-d)Zed`d.d/Zed_d0d/Zdad1d/Zdbdcd9d:Z	2	;	2ddded?d@Z	2	2	2	2	3	dfdg fdIdJZdhdLdMZ	NdidjdRdSZdkdUdVZdldWdXZ  ZS )mTimezJ
    Represents a time instance as hour, minute, second, microsecond.
    tr   tz7str | Timezone | FixedTimezone | datetime.tzinfo | Nonereturnr   c                 C  s:   |j p|}|d urt|}| |j|j|j|j||jdS )Ntzinfofold)r   pendulumZ_safe_timezonehourminutesecondmicrosecondr   )clsr   r    r#   U/var/www/html/kuke-dev/django-kuke/venv/lib/python3.10/site-packages/pendulum/time.pyinstance%   s   

zTime.instancestrc              
   C  sZ   d}| j rd| j  }d}| jrd| j}| jj d| j d| j d| j | | d
S )N z, z	, tzinfo=())r!   r   	__class____name__r   r   r    )selfusr   r#   r#   r$   __repr__1   s$   
zTime.__repr__dt1Time | timedt2c                 C  sT   |  |j|j|j|j}|  |j|j|j|j}| | | | k r(|S |S )z9
        Get the closest time from the instance.
        r*   r   r   r    r!   diffZ
in_secondsr,   r/   r1   r#   r#   r$   closestA   
   zTime.closestc                 C  sT   |  |j|j|j|j}|  |j|j|j|j}| | | | kr(|S |S )z:
        Get the farthest time from the instance.
        r2   r4   r#   r#   r$   farthestM   r6   zTime.farthestr   hoursintminutessecondsmicrosecondsc                 C  8   ddl m} |j| j| j| j| jj||||d	 S )z
        Add duration to the instance.

        :param hours: The number of hours
        :param minutes: The number of minutes
        :param seconds: The number of seconds
        :param microseconds: The number of microseconds
        r   DateTimer8   r:   r;   r<   )
pendulum.datetimer?   EPOCHatr   r   r    r!   addr   r,   r8   r:   r;   r<   r?   r#   r#   r$   rD   [   s   zTime.addc                 C  r=   )av  
        Add duration to the instance.

        :param hours: The number of hours
        :type hours: int

        :param minutes: The number of minutes
        :type minutes: int

        :param seconds: The number of seconds
        :type seconds: int

        :param microseconds: The number of microseconds
        :type microseconds: int

        :rtype: Time
        r   r>   r@   )
rA   r?   rB   rC   r   r   r    r!   subtractr   rE   r#   r#   r$   rF   p   s   zTime.subtractdeltadatetime.timedeltac                 C      |j rtd| j|j|jdS )zg
        Add timedelta duration to the instance.

        :param delta: The timedelta instance
        z'Cannot add timedelta with days to Time.r;   r<   )days	TypeErrorrD   r;   r<   r,   rG   r#   r#   r$   add_timedelta      zTime.add_timedeltac                 C  rI   )zl
        Remove timedelta duration from the instance.

        :param delta: The timedelta instance
        z,Cannot subtract timedelta with days to Time.rJ   )rK   rL   rF   r;   r<   rM   r#   r#   r$   subtract_timedelta   rO   zTime.subtract_timedeltaotherc                 C  s   t |tstS | |S N)
isinstancer   NotImplementedrN   r,   rQ   r#   r#   r$   __add__   s   

zTime.__add__pendulum.Durationc                 C     d S rR   r#   rU   r#   r#   r$   __sub__      zTime.__sub__c                 C  rX   rR   r#   rU   r#   r#   r$   rY      rZ   time | datetime.timedeltapendulum.Duration | Timec                 C  sh   t |tttfs
tS t |tr| |S t |tr.|jd ur"td| |j	|j
|j|j}|| dS )N,Cannot subtract aware times to or from Time.F)rS   r   r   r   rT   rP   r   rL   r*   r   r   r    r!   r3   rU   r#   r#   r$   rY      s   



c                 C  rX   rR   r#   rU   r#   r#   r$   __rsub__   rZ   zTime.__rsub__c                 C  rX   rR   r#   rU   r#   r#   r$   r^      rZ   c                 C  sP   t |ttfs	tS t |tr#|jd urtd| |j|j|j	|j
}|| S )Nr]   )rS   r   r   rT   r   rL   r*   r   r   r    r!   rY   rU   r#   r#   r$   r^      s   


NTdttime | Noneabsboolr   c                 C  s   |du rt   }n| |j|j|j|j}| jt | jt	  | j t
 }|jt |jt	  |j t
 }t}|r;t}||| dS )z
        Returns the difference between two Time objects as an Duration.

        :param dt: The time to subtract from
        :param abs: Whether to return an absolute duration or not
        Nr<   )r   nowr   r*   r   r   r    r!   r	   r
   r   r   r   )r,   r_   ra   Zus1Zus2klassr#   r#   r$   r3      s   z	Time.diffFabsolutelocale
str | Nonec                 C  s2   |du }|rt   }| |}t ||||S )a	  
        Get the difference in a human readable format in the current locale.

        :param dt: The time to subtract from
        :param absolute: removes time difference modifiers ago, after, etc
        :param locale: The locale to use for localization
        N)r   rd   r   r3   Zformat_diff)r,   rQ   rf   rg   Zis_nowr3   r#   r#   r$   diff_for_humans   s
   
zTime.diff_for_humansr   SupportsIndex | Noner   r    r!   r   -bool | datetime.tzinfo | Literal[True] | Noner   c                   s   |du r| j }|d ur|n| j}|d ur|n| j}|d ur|n| j}|d ur(|n| j}t j||||ttt	j  ||d}| j
|j|j|j|j|j dS )NTr   )r   )r   r   r   r    r!   superreplacer   r   datetimer*   )r,   r   r   r    r!   r   r   r   r*   r#   r$   rm     s"   	zTime.replacetuple[Time]c                 C  s   | fS rR   r#   r,   r#   r#   r$   __getnewargs__*  s   zTime.__getnewargs__   protocolr   1tuple[int, int, int, int, datetime.tzinfo | None]c                 C  s   | j }| j| j| j| j|fS rR   )r   r   r   r    r!   )r,   rt   r   r#   r#   r$   
_get_state-  s   zTime._get_stateDtuple[type[Time], tuple[int, int, int, int, datetime.tzinfo | None]]c                 C  s
   |  dS )N   )__reduce_ex__rq   r#   r#   r$   
__reduce__4  s   
zTime.__reduce__c                 C  s   | j | |fS rR   )r*   rv   )r,   rt   r#   r#   r$   ry   9  s   zTime.__reduce_ex__)r   r   r   r   r   r   )r   r&   )r/   r0   r1   r0   r   r   )r   r   r   r   )
r8   r9   r:   r9   r;   r9   r<   r9   r   r   )rG   rH   r   r   )rQ   rH   r   r   )rQ   r   r   rW   )rQ   r[   r   r\   )NT)r_   r`   ra   rb   r   r   )NFN)rQ   r`   rf   rb   rg   rh   r   r&   )NNNNTr   )r   rj   r   rj   r    rj   r!   rj   r   rk   r   r9   r   r   )r   rp   )rs   )rt   r   r   ru   )r   rw   )rt   r   r   rw   )r+   
__module____qualname____doc__classmethodr   r%   r.   r5   r7   rD   rF   rN   rP   rV   r   rY   r^   r3   ri   rm   rr   rv   rz   ry   __classcell__r#   r#   ro   r$   r       sT    









r      ;   i?B    rc   ) 
__future__r   rn   r   r   typingr   r   r   r   r   Zpendulum.constantsr	   r
   r   Zpendulum.durationr   r   Zpendulum.mixins.defaultr   Zpendulum.tz.timezoner   Ztyping_extensionsr   r   r   r   r   r   minmax
resolutionr#   r#   r#   r$   <module>   s8      !