3
@VB                 @   s@   d dl mZ d dlmZmZ G dd deZdd Zdd Zd	S )
    )division)	timedeltatzinfoc               @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )FixedOffseta  
    Represent a timezone with a fixed offset from UTC and no adjustment for
    DST.

    >>> FixedOffset(4,0)
    <UTC+04:00>
    >>> FixedOffset(-4,0)
    <UTC-04:00>
    >>> FixedOffset(4,30)
    <UTC+04:30>

    >>> tz = FixedOffset(-5,0)
    >>> tz.dst(None)
    datetime.timedelta(0)

    The class tries to do the right thing with the sign
    of the time zone offset:

    >>> FixedOffset(-9,30)
    <UTC-09:30>
    >>> FixedOffset(-9,-30)
    Traceback (most recent call last):
    ...
    ValueError: minutes must not be negative

    Offsets must thus be normalized so that the minute value is positive:

    >>> FixedOffset(-8,30)
    <UTC-08:30>

    c             C   sP   t j|  |dk rtd|dk r*|d9 }t||d| _dtt| j | _dS )zK
        Create a new FixedOffset instance with the given offset.

        r   zminutes must not be negative   )hoursminutesZUTCN)r   __init__
ValueErrorr   _FixedOffset__offsettimezonetimedelta_seconds_FixedOffset__name)selfr   r    r   1/usr/lib/python3/dist-packages/pyrfc3339/utils.pyr
   '   s    

zFixedOffset.__init__c             C   s   t dS )zG
        Return offset for DST.  Always returns timedelta(0).

        r   )r   )r   dtr   r   r   dst5   s    zFixedOffset.dstc             C   s   | j S )z*
        Return offset from UTC.

        )r   )r   r   r   r   r   	utcoffset<   s    zFixedOffset.utcoffsetc             C   s   | j S )z+
        Return name of timezone.

        )r   )r   r   r   r   r   tznameC   s    zFixedOffset.tznamec             C   s   dj | jd S )Nz<{0}>)formatr   )r   r   r   r   __repr__J   s    zFixedOffset.__repr__N)	__name__
__module____qualname____doc__r
   r   r   r   r   r   r   r   r   r      s   r   c             C   sT   yt t| j S  tk
rN   | j}| j}| j}t t|d | |d  S X dS )a  
    Return the offset stored by a :class:`datetime.timedelta` object as an
    integer number of seconds.  Microseconds, if present, are rounded to
    the nearest second.

    Delegates to
    :meth:`timedelta.total_seconds() <datetime.timedelta.total_seconds()>`
    if available.

    >>> timedelta_seconds(timedelta(hours=1))
    3600
    >>> timedelta_seconds(timedelta(hours=-1))
    -3600
    >>> timedelta_seconds(timedelta(hours=1, minutes=30))
    5400
    >>> timedelta_seconds(timedelta(hours=1, minutes=30,
    ... microseconds=300000))
    5400
    >>> timedelta_seconds(timedelta(hours=1, minutes=30,
    ...	microseconds=900000))
    5401

    iQ i@B N)introundZtotal_secondsAttributeErrordayssecondsmicroseconds)Ztdr    r!   r"   r   r   r   r   N   s    r   c             C   sJ   t t| d\}}tt|d }| dkr0d}nd}dj|t|t|S )z
    Return a string representing the timezone offset.
    Remaining seconds are rounded to the nearest minute.

    >>> timezone(3600)
    '+01:00'
    >>> timezone(5400)
    '+01:30'
    >>> timezone(-28800)
    '-08:00'

    i  <   r   +-z{0}{1:02d}:{2:02d})divmodabsr   floatr   r   )r   r   r!   r   Zsignr   r   r   r   q   s    r   N)Z
__future__r   Zdatetimer   r   r   r   r   r   r   r   r   <module>   s   H#