o
    .j                     @   sn   d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ edZG d	d
 d
Zd
gZdS )z*UTC-Offset property type from :rfc:`5545`.    N	timedelta)AnyClassVar)Self)JCalParsingError)
ParameterszI^(?P<sign>[+-])?(?P<hours>\d\d):(?P<minutes>\d\d)(?::(?P<seconds>\d\d))?$c                   @   s   e Zd ZU dZdZee ed< eed< dZ	d#de
eef dB defdd	Zd
efddZd$ded
efddZedd Zdd Zdd Zdd Zed
ee fddZddlmZ ded
efddZed ed
efd!d"ZdS )%
vUTCOffsetah  UTC Offset

    Value Name:
        UTC-OFFSET

    Purpose:
        This value type is used to identify properties that contain
        an offset from UTC to local time.

    Format Definition:
        This value type is defined by the following notation:

        .. code-block:: text

            utc-offset = time-numzone

            time-numzone = ("+" / "-") time-hour time-minute [time-second]

    Description:
        The PLUS SIGN character MUST be specified for positive
        UTC offsets (i.e., ahead of UTC).  The HYPHEN-MINUS character MUST
        be specified for negative UTC offsets (i.e., behind of UTC).  The
        value of "-0000" and "-000000" are not allowed.  The time-second,
        if present, MUST NOT be 60; if absent, it defaults to zero.

        Example:
            The following UTC offsets are given for standard time for
            New York (five hours behind UTC) and Geneva (one hour ahead of
            UTC):

        .. code-block:: ics

            -0500

            +0100

        .. code-block:: pycon

            >>> from icalendar.prop import vUTCOffset
            >>> utc_offset = vUTCOffset.from_ical('-0500')
            >>> utc_offset
            datetime.timedelta(days=-1, seconds=68400)
            >>> utc_offset = vUTCOffset.from_ical('+0100')
            >>> utc_offset
            datetime.timedelta(seconds=3600)
    z
UTC-OFFSETdefault_valueparamsFNtdc                C   s&   t |ts	td|| _t|| _d S )Nz)Offset value MUST be a timedelta instance)
isinstancer   	TypeErrorr   r   r   )selfr   r    r   Q/home/thesage/.local/lib/python3.10/site-packages/icalendar/prop/dt/utc_offset.py__init__I   s   
zvUTCOffset.__init__returnc                 C   s
   |  dS )zReturn the ical representation. )formatr   r   r   r   to_icalO   s   
zvUTCOffset.to_icalr   dividerc           	      C   s   | j tdk rd}td| j  }nd}| j }|j|j}}t|d |d  }t|d d }t|d }|rJ|d| |d| |d}|| S |d| |d}|| S )an  Represent the value with a possible divider.

        .. code-block:: pycon

            >>> from icalendar import vUTCOffset
            >>> from datetime import timedelta
            >>> utc_offset = vUTCOffset(timedelta(hours=-5))
            >>> utc_offset.format()
            '-0500'
            >>> utc_offset.format(divider=':')
            '-05:00'
        r   z-%sz+%s   i  <   02)r   r   dayssecondsabs)	r   r   signr   r   r   hoursminutesdurationr   r   r   r   S   s   zvUTCOffset.formatc              
   C   s   t || r|jS z+|dd t|dd t|dd t|dd p$df\}}}}t|||d}W n tyG } ztd| |d }~ww | jsY|tdd	krYtd
| |dkr`| S |S )Nr               r    r!   r   zExpected UTC offset, got: r   r    z'Offset must be less than 24 hours, was -)r   r   intr   	Exception
ValueErrorignore_exceptions)clsicalr   r    r!   r   offseter   r   r   	from_icals   s$   

zvUTCOffset.from_icalc                 C   s   t |tsdS | j|jkS )NF)r   r	   r   )r   otherr   r   r   __eq__   s   
zvUTCOffset.__eq__c                 C   s
   t | jS N)hashr   r   r   r   r   __hash__   s   
zvUTCOffset.__hash__c                 C   s   d| j dS )NzvUTCOffset())r   r   r   r   r   __repr__   s   zvUTCOffset.__repr__c                 C   s   | t dd| t dgS )zExamples of vUTCOffset.r$   r(   r   r   )r.   r   r   r   examples   s   
zvUTCOffset.examplesr   )VALUEnamec                 C   s   || j  | j | dgS )zBThe jCal representation of this property according to :rfc:`7265`.:)r   to_jcalr;   lowerr   )r   r<   r   r   r   r>      s   zvUTCOffset.to_jcaljcal_propertyc                 C   s   t ||  t|d }|du rt d|d|ddk}t|d}t|d}t|d	p5d
}t|||d}|rC| }| |t|S )zParse jCal from :rfc:`7265`.

        Parameters:
            jcal_property: The jCal property to parse.

        Raises:
            ~error.JCalParsingError: If the provided jCal is invalid.
        r$   NzCannot parse z as UTC-OFFSET.r   r)   r    r!   r   r   r'   )	r   validate_propertyUTC_OFFSET_JCAL_REGEXmatchgroupr*   r   r   from_jcal_property)r.   r@   rC   negativer    r!   r   tr   r   r   	from_jcal   s   
zvUTCOffset.from_jcalr5   )r   )__name__
__module____qualname____doc__r
   r   str__annotations__r   r-   dictr   r   r   r   r   classmethodr2   r4   r7   r9   listr   r:   icalendar.paramr;   r>   rH   r   r   r   r   r	      s&   
 /  
r	   )rL   redatetimer   typingr   r   icalendar.compatibilityr   icalendar.errorr   icalendar.parserr   compilerB   r	   __all__r   r   r   r   <module>   s     
)