
    11i +                     D    S r SSKJr  SSKJrJr  S rS r " S S5      rg)	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                 n    X-
  X!-
  pCX4-  R                  [        5      nX5U-  -
  nXa-  n[        U5      U4$ )z%
A divmod function with boundaries.

)to_integralr   int)vallowhighabdivmods          J/home/james-whalen/.local/lib/python3.13/site-packages/isodate/duration.pyfquotmodr      sC     9djq5

k
*C
Ag+C JCs8S=    c                 X    US;   a  gUS;   a  gU S-  S:X  d  U S-  S:w  a
  U S-  S:X  a  g	g
)zG
Determines the number of days of a specific month in a specific year.
)               
         )      	         i  r   d   r          )yearmonths     r   max_days_in_monthr'      sB     ''	s
q0qQr   c                       \ rS rSrSr         SS jrS rS rS rS r	S r
S	 rS
 rS r\rS r\rS rS rS rS rSS jrSrg)Duration*   a  
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
c
           	          [        U[        5      (       d  [        [        U5      5      n[        U	[        5      (       d  [        [        U	5      5      n	Xl        Xl        [        XX4XVU5      U l        g)z>
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__Duration.__init__A   sY     &'**S[)F%))CJ'E
<wu
r   c                     U R                   $ N)__dict__r1   s    r   __getstate__Duration.__getstate__Z   s    }}r   c                 :    U R                   R                  U5        g r<   )r=   update)r1   states     r   __setstate__Duration.__setstate__]   s    U#r   c                 .    [        U R                  U5      $ )zE
Provide direct access to attributes of included timedelta instance.
)getattrr0   )r1   names     r   __getattr__Duration.__getattr__`   s     t{{D))r   c                 R   / nU R                   (       a  UR                  SU R                   -  5        U R                  (       a1  SnU R                  S::  a  SnUR                  X R                  -  5        UR                  [        U R                  5      5        SR                  U5      $ )zG
Return a string representation of this duration similar to timedelta.
z%d yearsz	%d monthsr   z%d monthz, )r/   appendr.   r-   r0   join)r1   paramsfmts      r   __str__Duration.__str__f   sy     ::MM*tzz12;;C{{a MM#+,c$++&'yy  r   c                 
   SU R                   R                  U R                   R                  U R                  R                  U R                  R
                  U R                  R                  U R                  U R                  4-  $ )z-
Return a string suitable for repr(x) calls.
z&%s.%s(%d, %d, %d, years=%d, months=%d))		__class__
__module____name__r0   r2   r3   r4   r/   r.   r>   s    r   __repr__Duration.__repr__u   se     8NN%%NN##KKKKKK$$JJKK;
 
 	
r   c                 Z    [        U R                  U R                  U R                  45      $ )zX
Return a hash of this instance so that it can be used in, for
example, dicts and sets.
)hashr0   r.   r/   r>   s    r   __hash__Duration.__hash__   s"    
 T[[$++tzz:;;r   c                 j    [        U R                  * U R                  * S9nU R                  * Ul        U$ )zO
A simple unary minus.

Returns a new Duration instance with all it's negated.
r/   r.   )r)   r/   r.   r0   )r1   negdurations     r   __neg__Duration.__neg__   s0     djj[$++F"kk\r   c                    [        U[        5      (       aX  [        U R                  UR                  -   U R                  UR                  -   S9nU R                  UR                  -   Ul        U$  [        U R                  5      R                  5       (       a(  [        U R                  5      R                  5       (       d  [        S5      eUR                  U R                  -   n[        USS5      u  pCUR                  U R                  -   U-   n[        XS5      nUR                  U:  a  UnOUR                  nUR                  [        U5      [        U5      [        U5      S9nU R                  U-   $ ! [         a     Of = f [        U R                  U R                  S9nU R                  U-   Ul        U$ ! [         a     [         $ f = f)zM
Durations can be added with Duration, timedelta, date and datetime
objects.
r]   >fractional years or months not supported for date calculationsr      r%   r&   day)r,   r)   r/   r.   r0   float
is_integer
ValueErrorr&   r   r%   r'   re   replacer   AttributeErrorNotImplemented)	r1   othernewdurationnewmonthcarrynewyearmaxdaysnewdaynewdts	            r   __add__Duration.__add__   s   
 eX&&"jj5;;.t{{U\\7QK "&u||!;K	 $**%0022uT[[7I7T7T7V7V W  {{T[[0H&xB7OEjj4::-5G':Gyy7" MM\XCK " E ;;&& 			 #DKKHK!%u!4K 			s%   /DE3 3
F ?F 3F8 8
G
	G
c                     [        U[        5      (       a:  [        U R                  U-  U R                  U-  S9nU R
                  U-  Ul        U$ [        $ )Nr]   )r,   r   r)   r/   r.   r0   rk   r1   rl   rm   s      r   __mul__Duration.__mul__   sK    eS!!"e);DKKRWDWXK!%u!4Kr   c                 p   [        U[        5      (       aX  [        U R                  UR                  -
  U R                  UR                  -
  S9nU R                  UR                  -
  Ul        U$  [        U R                  U R                  S9nU R                  U-
  Ul        U$ ! [
         a     [        $ f = f)zR
It is possible to subtract Duration and timedelta objects from Duration
objects.
r]   )r,   r)   r/   r.   r0   	TypeErrorrk   rw   s      r   __sub__Duration.__sub__   s    
 eX&&"jj5;;.t{{U\\7QK "&u||!;K	"DKKHK!%u!4K 		s   /3B# #
B54B5c                    [        U[        5      (       a  [        5       nXl        X -
  $  [	        U R
                  5      R                  5       (       a(  [	        U R                  5      R                  5       (       d  [        S5      eUR                  U R                  -
  n[        USS5      u  pCUR                  U R
                  -
  U-   n[        XS5      nUR                  U:  a  UnOUR                  nUR                  [        U5      [        U5      [        U5      S9nXR                  -
  $ ! [          a     ["        $ f = f)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
rb   r   rc   rd   )r,   r   r)   r0   rf   r/   rg   r.   rh   r&   r   r%   r'   re   ri   r   rj   rk   )	r1   rl   tmpdurrn   ro   rp   rq   rr   rs   s	            r   __rsub__Duration.__rsub__   s    eY''ZF!M= 	 $**%0022uT[[7I7T7T7V7V W  {{T[[0H&xB7OEjj4::-5G':Gyy7" MM\XCK " E ;;&& 		s   DD. .
E ?E c                 8   [        U[        5      (       aV  U R                  S-  U R                  -   UR                  S-  UR                  -   :X  a  U R                  UR                  :X  a  ggU R                  S:X  a  U R                  S:X  a  U R                  U:H  $ g)zn
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.   r0   r1   rl   s     r   __eq__Duration.__eq__  s    
 eX&&

R$++-b 5<</++- ::?t{{a/;;%''r   c                 8   [        U[        5      (       aV  U R                  S-  U R                  -   UR                  S-  UR                  -   :w  d  U R                  UR                  :w  a  ggU R                  S:X  a  U R                  S:X  a  U R                  U:g  $ g)zo
If the years, month part or the timedelta part is not equal, then
the two Durations are considered not equal.
r   TFr   r   r   s     r   __ne__Duration.__ne__  s    
 eX&&

R$++-b 5<</, ::?t{{a/;;%''r   Nc                 h    Uc  Uc  [        S5      eUb  Ub  [        S5      eUb  X-   U-
  $ X"U -
  -
  $ )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.
zstart or end requiredzonly start or end allowed)rh   )r1   startends      r   totimedeltaDuration.totimedelta/  sO     =S[455899LE))Dj!!r   )r.   r0   r/   )	r   r   r   r   r   r   r   r   r   )NN)rU   rT   __qualname____firstlineno____doc__r9   r?   rD   rI   rP   rV   rZ   r_   rt   __radd__rx   __rmul__r|   r   r   r   r   __static_attributes__r$   r   r   r)   r)   *   s    0 
2$*!
<-^ H H*(T"""r   r)   N)	r   datetimer   decimalr   r   r   r'   r)   r$   r   r   <module>r      s(     ("
R" R"r   