
    Pi +                     L    d Z ddlmZ ddlmZmZ d Zd Z G d d          ZdS )	z
This module defines a Duration class.

The class Duration allows to define durations in years and months and can be
used as limited replacement for timedelta objects.
    )	timedelta)ROUND_FLOORDecimalc                     | |z
  ||z
  }}||z                       t                    }|||z  z
  }||z  }t          |          |fS )z-
    A divmod function with boundaries.

    )to_integralr   int)vallowhighabdivmods          d/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/isodate/duration.pyfquotmodr      sT     9dSjqAq5

k
*
*C
cAg+C 3JCs88S=    c                 X    |dv rdS |dv rdS | dz  dk    s| dz  dk    r| dz  dk    rd	S d
S )zO
    Determines the number of days of a specific month in a specific year.
    )               
         )      	         i  r   d   r          )yearmonths     r   max_days_in_monthr'      sX     '''rr	s
q00qQr2r   c                       e Zd ZdZ	 	 	 	 	 	 	 	 	 ddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd ZeZd ZeZd Zd Zd Zd ZddZdS )DurationaY  
    A class which represents a duration.

    The difference to datetime.timedelta is, that this class handles also
    differences given in years and months.
    A Duration treats differences given in year, months separately from all
    other components.

    A Duration can be used almost like any timedelta object, however there
    are some restrictions:
      * It is not really possible to compare Durations, because it is unclear,
        whether a duration of 1 year is bigger than 365 days or not.
      * Equality is only tested between the two (year, month vs. timedelta)
        basic components.

    A Duration can also be converted into a datetime object, but this requires
    a start date or an end date.

    The algorithm to add a duration to a date is defined at
    http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes
    r   c
           	         t          |t                    st          t          |                    }t          |	t                    st          t          |	                    }	|| _        |	| _        t          |||||||          | _        dS )zN
        Initialise this Duration instance with the given parameters.
        N)
isinstancer   strmonthsyearsr   tdelta)
selfdayssecondsmicrosecondsmillisecondsminuteshoursweeksr-   r.   s
             r   __init__zDuration.__init__A   s     &'** 	*S[[))F%)) 	(CJJ''E
'<wu
 
r   c                     | j         S N)__dict__r0   s    r   __getstate__zDuration.__getstate__Z   s
    }r   c                 :    | j                             |           d S r:   )r;   update)r0   states     r   __setstate__zDuration.__setstate__]   s    U#####r   c                 ,    t          | j        |          S )zU
        Provide direct access to attributes of included timedelta instance.
        )getattrr/   )r0   names     r   __getattr__zDuration.__getattr__`   s     t{D)))r   c                 ,   g }| j         r|                    d| j         z             | j        r,d}| j        dk    rd}|                    || j        z             |                    t          | j                             d                    |          S )zW
        Return a string representation of this duration similar to timedelta.
        z%d yearsz	%d monthsr   z%d monthz, )r.   appendr-   r,   r/   join)r0   paramsfmts      r   __str__zDuration.__str__f   s     : 	3MM*tz1222; 	-C{a MM#+,,,c$+&&'''yy   r   c                     d| j         j        | j         j        | j        j        | j        j        | j        j        | j        | j        fz  S )z=
        Return a string suitable for repr(x) calls.
        z&%s.%s(%d, %d, %d, years=%d, months=%d))		__class__
__module____name__r/   r1   r2   r3   r.   r-   r<   s    r   __repr__zDuration.__repr__u   sH     8N%N#KKK$JK;
 
 	
r   c                 D    t          | j        | j        | j        f          S )zp
        Return a hash of this instance so that it can be used in, for
        example, dicts and sets.
        )hashr/   r-   r.   r<   s    r   __hash__zDuration.__hash__   s    
 T[$+tz:;;;r   c                 Z    t          | j         | j                   }| j         |_        |S )zg
        A simple unary minus.

        Returns a new Duration instance with all it's negated.
        r.   r-   )r)   r.   r-   r/   )r0   negdurations     r   __neg__zDuration.__neg__   s0     dj[$+FFF"k\r   c                 T   t          |t                    rAt          | j        |j        z   | j        |j        z             }| j        |j        z   |_        |S 	 t          | j                                                  r&t          | j                                                  st          d          |j        | j        z   }t          |dd          \  }}|j
        | j        z   |z   }t          ||          }|j        |k    r|}n|j        }|                    t          |          t          |          t          |                    }| j        |z   S # t          $ r Y nw xY w	 t          | j        | j                  }| j        |z   |_        |S # t          $ r Y nw xY wt           S )ze
        Durations can be added with Duration, timedelta, date and datetime
        objects.
        rU   >fractional years or months not supported for date calculationsr      r%   r&   day)r+   r)   r.   r-   r/   float
is_integer
ValueErrorr&   r   r%   r'   r\   replacer   AttributeErrorNotImplemented)	r0   othernewdurationnewmonthcarrynewyearmaxdaysnewdaynewdts	            r   __add__zDuration.__add__   s   
 eX&& 	"j5;.t{U\7Q  K "&u|!;K	 $*%%0022 uT[7I7I7T7T7V7V  W   {T[0H&xB77OE8j4:-5G'::Gy7"" MM\\XCKK "  E ;&& 	 	 	D		 #DKHHHK!%u!4K 	 	 	D	 s%   C=E 
E#"E#'+F 
F F c                     t          |t                    r2t          | j        |z  | j        |z            }| j        |z  |_        |S t          S )NrU   )r+   r   r)   r.   r-   r/   rb   r0   rc   rd   s      r   __mul__zDuration.__mul__   sP    eS!! 	"e);DKRWDWXXXK!%u!4Kr   c                 6   t          |t                    rAt          | j        |j        z
  | j        |j        z
            }| j        |j        z
  |_        |S 	 t          | j        | j                  }| j        |z
  |_        |S # t
          $ r Y nw xY wt          S )zj
        It is possible to subtract Duration and timedelta objects from Duration
        objects.
        rU   )r+   r)   r.   r-   r/   	TypeErrorrb   rm   s      r   __sub__zDuration.__sub__   s    
 eX&& 	"j5;.t{U\7Q  K "&u|!;K	"DKHHHK!%u!4K 	 	 	D	 s   +B 
BBc                    t          |t                    rt                      }||_        || z
  S 	 t	          | j                                                  r&t	          | j                                                  st          d          |j	        | j        z
  }t          |dd          \  }}|j        | j        z
  |z   }t          ||          }|j        |k    r|}n|j        }|                    t          |          t          |          t          |                    }|| j        z
  S # t           $ r Y nw xY wt"          S )a@  
        It is possible to subtract Duration objects from date, datetime and
        timedelta objects.

        TODO: there is some weird behaviour in date - timedelta ...
              if timedelta has seconds or microseconds set, then
              date - timedelta != date + (-timedelta)
              for now we follow this behaviour to avoid surprises when mixing
              timedeltas with Durations, but in case this ever changes in
              the stdlib we can just do:
                return -self + other
              instead of all the current code
        rY   r   rZ   r[   )r+   r   r)   r/   r]   r.   r^   r-   r_   r&   r   r%   r'   r\   r`   r   ra   rb   )	r0   rc   tmpdurre   rf   rg   rh   ri   rj   s	            r   __rsub__zDuration.__rsub__   sQ    eY'' 	!ZZF!FMD= 	 $*%%0022 uT[7I7I7T7T7V7V  W   {T[0H&xB77OE8j4:-5G'::Gy7"" MM\\XCKK "  E 4;&& 	 	 	D	 s   C=D/ /
D<;D<c                     t          |t                    r:| j        dz  | j        z   |j        dz  |j        z   k    r| j        |j        k    rdS dS | j        dk    r| j        dk    r| j        |k    S dS )z
        If the years, month part and the timedelta part are both equal, then
        the two Durations are considered equal.
        r   TFr   r+   r)   r.   r-   r/   r0   rc   s     r   __eq__zDuration.__eq__  s    
 eX&& 	
R$+-b 5</ +--t5 :??t{a//;%''ur   c                     t          |t                    r:| j        dz  | j        z   |j        dz  |j        z   k    s| j        |j        k    rdS dS | j        dk    r| j        dk    r| j        |k    S dS )z
        If the years, month part or the timedelta part is not equal, then
        the two Durations are considered not equal.
        r   TFr   rv   rw   s     r   __ne__zDuration.__ne__  s    
 eX&& 	
R$+-b 5</ ,,t5 :??t{a//;%''tr   Nc                 r    ||t          d          ||t          d          ||| z   |z
  S ||| z
  z
  S )z
        Convert this duration into a timedelta object.

        This method requires a start datetime or end datetimem, but raises
        an exception if both are given.
        Nzstart or end requiredzonly start or end allowed)r_   )r0   startends      r   totimedeltazDuration.totimedelta/  sY     =S[45558999DLE))cDj!!r   )	r   r   r   r   r   r   r   r   r   )NN)rO   rN   __qualname____doc__r8   r=   rA   rE   rK   rP   rS   rW   rk   __radd__rn   __rmul__rq   rt   rx   rz   r~   r$   r   r   r)   r)   *   s6        0 
 
 
 
2  $ $ $* * *! ! !
 
 
< < <  - - -^ H   H  *( ( (T  "  "" " " " " "r   r)   N)	r   datetimer   decimalr   r   r   r'   r)   r$   r   r   <module>r      s           ( ( ( ( ( ( ( (  "
 
 
R" R" R" R" R" R" R" R" R" R"r   