§
    ôl¶aô0  ã                   óN   — d Z ddlmZ ddlmZmZ d„ Zd„ Z G d„ de¦  «        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)ÚDecimalÚROUND_FLOORc                 óŒ   — | |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          ú2/usr/lib/python3/dist-packages/isodate/duration.pyÚfquotmodr   %   sT   € ð �‰9�d˜S‘j€q€AØˆq‰5×
Ò
�kÑ
*Ô
*€CØ
ˆc�A‰g‰+€Cð ˆ3�J€CÝˆs‰8Œ8�Sˆ=Ðó    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'   6   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__Z   s€   € õ
 ˜&¥'Ñ*Ô*ð 	*Ý�S ™[œ[Ñ)Ô)ˆFÝ˜%¥Ñ)Ô)ð 	(Ý�C ™JœJÑ'Ô'ˆEØˆŒØˆŒ
Ý  g¨|¸\Ø '¨°ñ7ô 7ˆŒˆˆr   c                 ó   — | j         S ©N)Ú__dict__©r0   s    r   Ú__getstate__zDuration.__getstate__h   s
   € ØŒ}Ðr   c                 ó:   — | j                              |¦  «         d S r:   )r;   Úupdate)r0   Ústates     r   Ú__setstate__zDuration.__setstate__k   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__n   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__t   s”   € ð ˆØŒ:ð 	3Ø�MŠM˜* t¤zÑ1Ñ2Ô2Ð2ØŒ;ð 	-ØˆCØŒ{˜aÒÐØ �Ø�MŠM˜# ¤Ñ+Ñ,Ô,Ð,Ø�Š•c˜$œ+Ñ&Ô&Ñ'Ô'Ð'Ø�yŠy˜Ñ Ô Ð 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__ƒ   sD   € ð 8ØŒNÔ% t¤~Ô'>ØŒKÔ˜dœkÔ1ØŒKÔ$ d¤j°$´+ð;?ñ ?ð 	?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”[ $¤+¨t¬zÐ:Ñ;Ô;Ð;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   € õ  d¤j [¸$¼+¸Ð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Ï  € õ
 �e�XÑ&Ô&ð 	Ý"¨¬°e´kÑ)AØ*.¬+¸¼Ñ*DðFñ Fô FˆKà!%¤¨u¬|Ñ!;ˆKÔØÐð	õ ˜$œ*Ñ%Ô%×0Ò0Ñ2Ô2ð ;Ý˜$œ+Ñ&Ô&×1Ò1Ñ3Ô3ð;å ð ":ñ ;ô ;ð ;à”{ T¤[Ñ0ˆHÝ& x°°BÑ7Ô7‰OˆE�8Ø”j 4¤:Ñ-°Ñ5ˆGÝ'¨°Ñ:Ô:ˆGØŒy˜7Ò"Ð"Ø ��àœ�Ø—M’MÝ˜‘\”\­¨X©¬½CÀ¹K¼Kð "ñ ô ˆEð ”; Ñ&Ð&øÝð 	ð 	ð 	àˆDð	øøøð	õ #¨¬¸D¼KÐHÑHÔHˆKØ!%¤¨uÑ!4ˆKÔØÐøÝð 	ð 	ð 	àˆ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__Í   sY   € Ý�e�SÑ!Ô!ð 	Ý"Ø”j 5Ñ(Ø”{ UÑ*ð,ñ ,ô ,ˆKð "&¤¨uÑ!4ˆKÔØÐÝÐ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³   € õ
 �e�XÑ&Ô&ð 	Ý"¨¬°e´kÑ)AØ*.¬+¸¼Ñ*DðFñ Fô FˆKà!%¤¨u¬|Ñ!;ˆKÔØÐð	å"¨¬¸D¼KÐHÑHÔHˆKØ!%¤¨uÑ!4ˆKÔØÐøÝð 	ð 	ð 	àˆ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 objecs 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__ì   sR  € õ �e�YÑ'Ô'ð 	!Ý‘Z”ZˆFØ!ˆFŒMØ˜D‘=Ð ð	õ ˜$œ*Ñ%Ô%×0Ò0Ñ2Ô2ð ;Ý˜$œ+Ñ&Ô&×1Ò1Ñ3Ô3ð;å ð ":ñ ;ô ;ð ;à”{ T¤[Ñ0ˆHÝ& x°°BÑ7Ô7‰OˆE�8Ø”j 4¤:Ñ-°Ñ5ˆGÝ'¨°Ñ:Ô:ˆGØŒy˜7Ò"Ð"Ø ��àœ�Ø—M’MÝ˜‘\”\­¨X©¬½CÀ¹K¼Kð "ñ ô ˆ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…   € õ
 �e�XÑ&Ô&ð 	Ø”*˜r‘/ D¤KÑ/Ø”+ Ñ" U¤\Ñ1ò3ð 3à” ¤Ò,Ð,Ø�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…   € õ
 �e�XÑ&Ô&ð 	Ø”*˜r‘/ D¤KÑ/Ø”+ Ñ" U¤\Ñ1ò3ð 3à” ¤Ò,Ð,Ø�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.totimedelta8  sY   € ð ˆ=˜S˜[ÝÐ4Ñ5Ô5Ð5ØÐ  ÝÐ8Ñ9Ô9Ð9ØÐØ˜D‘L EÑ)Ð)Ø�c˜D‘jÑ!Ð!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)   C   s#  € € € € € ðð ð, HIØ>?ð7ð 7ð 7ð 7ðð ð ð$ð $ð $ð*ð *ð *ð!ð !ð !ð?ð ?ð ?ð<ð <ð <ðð ð ð,ð ,ð ,ð\ €Hðð ð ð €Hðð ð ð((ð (ð (ðTð ð ð"ð ð ð""ð "ð "ð "ð "ð "r   r)   N)
r€   Údatetimer   Údecimalr   r   r   r'   Úobjectr)   r$   r   r   ú<module>r†      s—   ðð6ð ð Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (ðð ð ð"
ð 
ð 
ðB"ð B"ð B"ð B"ð B"ˆvñ B"ô B"ð B"ð B"ð B"r   