o
    .j                     @  s   d Z ddlmZ ddlmZmZmZ ddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZmZ erPddl
mZ ddlmZ ddlmZ dd	lmZmZmZ G d
d deZG dd dZG dd deZg dZdS )z+Occurrences of events and other components.    )annotations)datedatetime	timedelta)TYPE_CHECKING
NamedTupleOptional)Alarm)ComponentAdapter)cached_propertymake_comparabletime_span_contains_event)	Component)UIDRecurrenceIDsTimec                   @  sf   e Zd ZU dZded< ded< ded< ded	< dddZedddZedddZ	edddZ
dS )OccurrenceIDa.  The ID of a component's occurrence to identify it clearly.

    Attributes:
        name: The name of the component, e.g. "VEVENT"
        uid: The UID of the component.
        recurrence_id: The Recurrence-ID of the component in UTC but without tzinfo.
        start: The start of the component

    strnamer   uidzOptional[Time]recurrence_idr   startreturnc                 C  s,   d | j| jr| j nd| j | jgS )z*Return a string representation of this id.# )joinr   r   	isoformatr   r   self r   U/home/thesage/.local/lib/python3.10/site-packages/recurring_ical_events/occurrence.py	to_string)   s   zOccurrenceID.to_string
iso_stringc                 C  s    t | dkrt| S t| S )z1Create a datetime from the string representation.
   )lenr   fromisoformatr   )r"   r   r   r    _dt_from_string4   s   

zOccurrenceID._dt_from_string	string_idc                 C  s6   | dd\}}}}| |||r| |nd| |S )z+Parse a string and return the component id.r      N)splitr&   )clsr'   r   r   r   r   r   r   r    from_string;   s   zOccurrenceID.from_stringrecurrence_idsr   c                 C  s   | |||r|d |S d|S )aS  Create a new OccurrenceID from the given values.

        Args:
            name: The component name.
            uid: The UID string.
            recurrence_ids: The recurrence ID tuple.
                This is expected as UTC with tzinfo being None.
            start: start time of the component either with or without timezone
        r   Nr   )r*   r   r   r,   r   r   r   r    from_occurrenceF   s   zOccurrenceID.from_occurrenceNr   r   )r"   r   r   r   )r'   r   r   r   )r   r   r   r   r,   r   r   r   )__name__
__module____qualname____doc____annotations__r!   staticmethodr&   classmethodr+   r-   r   r   r   r    r      s   
 


r   c                   @  s   e Zd ZdZ			d1d2ddZd3ddZd4ddZd5ddZd6ddZe	d7d d!Z
d8d"d#Zd6d$d%Zd3d&d'Zed3d(d)Zd9d,d-Zed:d/d0ZdS );
OccurrencezA repetition of an event.Nadapterr
   r   Time | NoneendTime | None | timedeltasequenceintc                 C  s8   || _ |du r
|jn|| _|du r|jn|| _|| _dS )zCreate an event repetition.

        - source - the icalendar Event
        - start - the start date/datetime to replace
        - stop - the end date/datetime to replace
        - sequence - if positive or 0, this sets the SEQUENCE property
        N)_adapterr   r:   r<   )r   r8   r   r:   r<   r   r   r    __init__Y   s   
zOccurrence.__init__r   r   c                 C  s>   d| j j d| jj j d| j d| j d| j d| jj dS )zThe string representation.<z	 adapter=z UID=z start=z
 sequence=z component.sequence=z >)	__class__r/   r>   r   r   r<   r   r   r   r    __repr__l   s   zOccurrence.__repr__keep_recurrence_attributesboolr   c                 C  s,   | j | j| j|}| jdkr| j|d< |S )zICreate a shallow copy of the source component and modify some attributes.r   SEQUENCE)r>   as_componentr   r:   r<   )r   rC   	componentr   r   r    rF   x   s   


zOccurrence.as_component
span_startr   	span_stopc                 C  s   t ||| j| jS )z,Return whether the component is in the span.)r   r   r:   )r   rH   rI   r   r   r    
is_in_span   s   zOccurrence.is_in_spanotherc                 C  s   t | j|jf\}}||k S )zfCompare two occurrences for sorting.

        See https://stackoverflow.com/a/4010558/1320237
        )r   r   )r   rK   
self_startother_startr   r   r    __lt__   s   zOccurrence.__lt__r   c                 C      t | j | jj| jj| jS zThe id of the component.)r   r-   r>   component_namer   r,   r   r   r   r   r    id      zOccurrence.idc                 C  s
   t | jS )zHash this for an occurrence.)hashrR   r   r   r   r    __hash__      
zOccurrence.__hash__c                 C  s   | j |j kS )zself == other)rR   )r   rK   r   r   r    __eq__      zOccurrence.__eq__c                 C  s
   | j  S )zThe name of this component.)r>   rQ   r   r   r   r    rQ      rV   zOccurrence.component_namec                 C     | j jS )zThe UID of this occurrence.)r>   r   r   r   r   r    r         zOccurrence.uidalarmr	   c                 C  s   || j jv S )z(Wether this alarm is in this occurrence.)r>   alarms)r   r[   r   r   r    	has_alarm   rX   zOccurrence.has_alarmr   c                 C  rY   )zThe recurrence ids.)r>   r,   r   r   r   r    r,      rZ   zOccurrence.recurrence_ids)NNr7   )r8   r
   r   r9   r:   r;   r<   r=   r.   )rC   rD   r   r   )rH   r   rI   r   r   rD   )rK   r6   r   rD   r   r   )r   r=   )r[   r	   r   rD   )r   r   )r/   r0   r1   r2   r?   rB   rF   rJ   rN   r   rR   rU   rW   rQ   propertyr   r]   r,   r   r   r   r    r6   V   s(    


	

	


r6   c                      sB   e Zd ZdZd fd
dZdd ZedddZdddZ  Z	S )AlarmOccurrencezAdapter for absolute alarms.triggerr   r[   r	   parentComponentAdapter | Occurrencer   Nonec                   s    t  ||| || _|| _d S )N)superr?   rb   r[   )r   ra   r[   rb   rA   r   r    r?      s   
zAlarmOccurrence.__init__c                 C  s2   | j j|d}| j }| j|_d|_|g|_|S )z2Return the alarm's parent as a modified component.)rC   r   )rb   rF   r[   copyr   TRIGGERREPEATsubcomponents)r   rC   rb   
alarm_oncer   r   r    rF      s   
zAlarmOccurrence.as_componentr   c                 C  rO   rP   )r   r-   rb   rQ   r   r,   r   r   r   r   r    rR      rS   zAlarmOccurrence.idr   c                 C  s&   d| j j d| j d| j d| j S )z
repr(self)r@   z at z of z in )rA   r/   r   r[   rb   r   r   r   r    rB      s   zAlarmOccurrence.__repr__)ra   r   r[   r	   rb   rc   r   rd   r^   r.   )
r/   r0   r1   r2   r?   rF   r   rR   rB   __classcell__r   r   rf   r    r`      s    
	r`   )r`   r6   r   N)r2   
__future__r   r   r   r   typingr   r   r   	icalendarr	   (recurring_ical_events.adapters.componentr
   recurring_ical_events.utilr   r   r   icalendar.calr   recurring_ical_events.typesr   r   r   r   r6   r`   __all__r   r   r   r    <module>   s     =\*