ó
k€
\c           @   sX   d  Z  d d l m Z d d l m Z m Z d „  Z d „  Z d e f d „  ƒ  YZ	 d S(	   s¨   
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.
iÿÿÿÿ(   t	   timedelta(   t   Decimalt   ROUND_FLOORc         C   sP   |  | | | } } | | j  t ƒ } | | | } | | 7} t | ƒ | f S(   s-   
    A divmod function with boundaries.

    (   t   to_integralR   t   int(   t   valt   lowt   hight   at   bt   divt   mod(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   fquotmod%   s
    
c         C   sX   | d k r d S| d k r  d S|  d d k sP |  d d k rT |  d	 d k rT d Sd S(   sO   
    Determines the number of days of a specific month in a specific year.
    i   i   i   i   i   i
   i   i   i   i   i	   i   i   i  i    id   i   i   (   i   i   i   i   i   i
   i   (   i   i   i	   i   (    (   t   yeart   month(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   max_days_in_month6   s    0t   Durationc        
   B   sÂ   e  Z d  Z d d d d d d d d 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 d „ Z RS(   sY  
    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
    i    c
   
      C   s   t  | t ƒ s$ t t | ƒ ƒ } n  t  |	 t ƒ sH t t |	 ƒ ƒ }	 n  | |  _ |	 |  _ t | | | | | | | ƒ |  _ d S(   sN   
        Initialise this Duration instance with the given parameters.
        N(   t
   isinstanceR   t   strt   monthst   yearsR    t   tdelta(
   t   selft   dayst   secondst   microsecondst   millisecondst   minutest   hourst   weeksR   R   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __init__Z   s    		c         C   s   |  j  S(   N(   t   __dict__(   R   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __getstate__h   s    c         C   s   |  j  j | ƒ d  S(   N(   R   t   update(   R   t   state(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __setstate__k   s    c         C   s   t  |  j | ƒ S(   sU   
        Provide direct access to attributes of included timedelta instance.
        (   t   getattrR   (   R   t   name(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __getattr__n   s    c         C   s‡   g  } |  j  r& | j d |  j  ƒ n  |  j rd d } |  j d k rM d } n  | j | |  j ƒ n  | j t |  j ƒ ƒ d j | ƒ S(   sW   
        Return a string representation of this duration similar to timedelta.
        s   %d yearss	   %d monthsi   s   %d months   , (   R   t   appendR   R   R   t   join(   R   t   paramst   fmt(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __str__t   s    			c         C   sA   d |  j  j |  j  j |  j j |  j j |  j j |  j |  j f S(   s=   
        Return a string suitable for repr(x) calls.
        s&   %s.%s(%d, %d, %d, years=%d, months=%d)(	   t	   __class__t
   __module__t   __name__R   R   R   R   R   R   (   R   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __repr__ƒ   s    c         C   s   t  |  j |  j |  j f ƒ S(   sp   
        Return a hash of this instance so that it can be used in, for
        example, dicts and sets.
        (   t   hashR   R   R   (   R   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __hash__Œ   s    c         C   s.   t  d |  j d |  j ƒ } |  j | _ | S(   sg   
        A simple unary minus.

        Returns a new Duration instance with all it's negated.
        R   R   (   R   R   R   R   (   R   t   negduration(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __neg__“   s    c   	      C   s€  t  | t ƒ rO t d |  j | j d |  j | j ƒ } |  j | j | _ | SyÒ t |  j ƒ j ƒ  oy t |  j ƒ j ƒ  s‹ t d ƒ ‚ n  | j |  j } t	 | d d ƒ \ } } | j
 |  j | } t | | ƒ } | j | k rî | } n	 | j } | j d | d | d | ƒ } |  j | SWn t k
 r4n Xy3 t d |  j d |  j ƒ } |  j | | _ | SWn t k
 r{n Xt S(	   se   
        Durations can be added with Duration, timedelta, date and datetime
        objects.
        R   R   s>   fractional years or months not supported for date calculationsi   i   R   R   t   day(   R   R   R   R   R   t   floatt
   is_integert
   ValueErrorR   R   R   R   R4   t   replacet   AttributeErrort   NotImplemented(	   R   t   othert   newdurationt   newmontht   carryt   newyeart   maxdayst   newdayt   newdt(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __add__   s6    		c         C   sJ   t  | t ƒ rF t d |  j | d |  j | ƒ } |  j | | _ | St S(   NR   R   (   R   R   R   R   R   R   R:   (   R   R;   R<   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __mul__Ë   s    c         C   sš   t  | t ƒ rO t d |  j | j d |  j | j ƒ } |  j | j | _ | Sy3 t d |  j d |  j ƒ } |  j | | _ | SWn t k
 r• n Xt S(   sj   
        It is possible to subtract Duration and timedelta objects from Duration
        objects.
        R   R   (   R   R   R   R   R   t	   TypeErrorR:   (   R   R;   R<   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __sub__Ö   s    c   	      C   s  t  | t ƒ r) t ƒ  } | | _ | |  SyÒ t |  j ƒ j ƒ  oS t |  j ƒ j ƒ  se t d ƒ ‚ n  | j	 |  j } t
 | d d ƒ \ } } | j |  j | } t | | ƒ } | j | k rÈ | } n	 | j } | j d | d | d | ƒ } | |  j SWn t k
 rn Xt S(   s?  
        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
        s>   fractional years or months not supported for date calculationsi   i   R   R   R4   (   R   R    R   R   R5   R   R6   R   R7   R   R   R   R   R4   R8   R9   R:   (	   R   R;   t   tmpdurR=   R>   R?   R@   RA   RB   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __rsub__ê   s(    				c         C   s€   t  | t ƒ rQ |  j d |  j | j d | j k rM |  j | j k rM t St S|  j d k r| |  j d k r| |  j | k St S(   s†   
        If the years, month part and the timedelta part are both equal, then
        the two Durations are considered equal.
        i   i    (   R   R   R   R   R   t   Truet   False(   R   R;   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __eq__  s    c         C   s€   t  | t ƒ rQ |  j d |  j | j d | j k sI |  j | j k rM t St S|  j d k r| |  j d k r| |  j | k St S(   s‡   
        If the years, month part or the timedelta part is not equal, then
        the two Durations are considered not equal.
        i   i    (   R   R   R   R   R   RI   RJ   (   R   R;   (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   __ne__#  s    c         C   sr   | d k r' | d k r' t d ƒ ‚ n  | d k	 rN | d k	 rN t d ƒ ‚ n  | d k	 rf | |  | S| | |  S(   s´   
        Convert this duration into a timedelta object.

        This method requires a start datetime or end datetimem, but raises
        an exception if both are given.
        s   start or end requireds   only start or end allowedN(   t   NoneR7   (   R   t   startt   end(    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   totimedelta4  s    N(   R.   R-   t   __doc__R   R    R#   R&   R+   R/   R1   R3   RC   t   __radd__RD   t   __rmul__RF   RH   RK   RL   RM   RP   (    (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyR   C   s&   								
	,				(		N(
   RQ   t   datetimeR    t   decimalR   R   R   R   t   objectR   (    (    (    sE   /data/av2000/b2b/venv/lib/python2.7/site-packages/isodate/duration.pyt   <module>    s
   		