
    i{                        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rd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e          Z G d d          Z G 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                      e Zd ZU dZded<   ded<   ded<   ded	<   ddZedd            Zedd            Z	e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                    d                     | j        | j        r| j                                        nd| j                                        | j        g          S )z*Return a string representation of this id.# )joinr   r   	isoformatr   r   selfs    [/root/projects/butler/venv/lib/python3.11/site-packages/recurring_ical_events/occurrence.py	to_stringzOccurrenceID.to_string)   sW    xx	262DL",,..."
$$&&	
 
 	
    
iso_stringc                x    t          |           dk    rt          j        |           S t          j        |           S )z1Create a datetime from the string representation.
   )lenr   fromisoformatr   )r%   s    r"   _dt_from_stringzOccurrenceID._dt_from_string4   s7     z??b  %j111%j111r$   	string_idc                    |                     dd          \  }}}} | |||r|                     |          nd|                     |                    S )z+Parse a string and return the component id.r      N)splitr*   )clsr+   r   r   r   r   s         r"   from_stringzOccurrenceID.from_string;   sf     +4//#q*A*A'mUCs2?IC...T&&	
 
 	
r$   recurrence_idsr   c                2     | |||r|d         n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   N )r/   r   r   r1   r   s        r"   from_occurrencezOccurrenceID.from_occurrenceF   s)     s4>KnQ//tUSSSr$   Nr   r   )r%   r   r   r   )r+   r   r   r   )r   r   r   r   r1   r   r   r   )__name__
__module____qualname____doc____annotations__r#   staticmethodr*   classmethodr0   r4   r3   r$   r"   r   r      s           IIIHHH!!!!KKK	
 	
 	
 	
 2 2 2 \2 
 
 
 [
 T T T [T T Tr$   r   c                      e Zd ZdZ	 	 	 d$d%dZd&dZd'dZd(dZed)d            Z	d*dZ
d(dZd+dZed+d            Zd,d!Zed-d#            ZdS ).
OccurrencezA repetition of an event.Nadapterr   r   Time | NoneendTime | None | timedeltasequenceintc                b    || _         ||j        n|| _        ||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   rB   rD   )r!   r@   r   rB   rD   s        r"   __init__zOccurrence.__init__Y   s8      &+mW]]
"%+7;;3 r$   keep_recurrence_attributesboolr   r   c                |    | j                             | j        | j        |          }| j        dk    r
| j        |d<   |S )zICreate a shallow copy of the source component and modify some attributes.r   SEQUENCE)rG   as_componentr   rB   rD   )r!   rI   	components      r"   rM   zOccurrence.as_componentl   sF    M..J"<
 
	 =A$(MIj!r$   
span_startr   	span_stopc                :    t          ||| j        | j                  S )z,Return whether the component is in the span.)r   r   rB   )r!   rO   rP   s      r"   
is_in_spanzOccurrence.is_in_spanu   s    '
Itz48TTTr$   otherc                J    t          | j        |j        f          \  }}||k     S )zfCompare two occurrences for sorting.

        See https://stackoverflow.com/a/4010558/1320237
        )r   r   )r!   rS   
self_startother_starts       r"   __lt__zOccurrence.__lt__y   s*    
 #24:u{2K"L"L
KK''r$   r   c                    t                               | j                                        | j        j        | j        j        | j                  S zThe id of the component.)r   r4   rG   component_namer   r1   r   r    s    r"   idzOccurrence.id   sB     ++M((**MM(J	
 
 	
r$   c                *    t          | j                  S )zHash this for an occurrence.)hashr[   r    s    r"   __hash__zOccurrence.__hash__   s    DG}}r$   c                "    | j         |j         k    S )zself == other)r[   )r!   rS   s     r"   __eq__zOccurrence.__eq__   s    w%(""r$   r   c                4    | j                                         S )zThe name of this component.)rG   rZ   r    s    r"   rZ   zOccurrence.component_name   s    }++---r$   c                    | j         j        S )zThe UID of this occurrence.)rG   r   r    s    r"   r   zOccurrence.uid   s     }  r$   alarmr
   c                    || j         j        v S )z(Wether this alarm is in this occurrence.)rG   alarms)r!   rc   s     r"   	has_alarmzOccurrence.has_alarm   s    ,,,r$   r   c                    | j         j        S )zThe recurrence ids.)rG   r1   r    s    r"   r1   zOccurrence.recurrence_ids   s     }++r$   )NNr?   )r@   r   r   rA   rB   rC   rD   rE   )rI   rJ   r   r   )rO   r   rP   r   r   rJ   )rS   r>   r   rJ   r   r   )r   rE   r5   )rc   r
   r   rJ   )r   r   )r6   r7   r8   r9   rH   rM   rR   rW   r   r[   r^   r`   rZ   propertyr   rf   r1   r3   r$   r"   r>   r>   V   s.       ##
 "'+! ! ! ! !&   U U U U( ( ( ( 
 
 
 _
   # # # #. . . . ! ! ! X!- - - - , , , X, , ,r$   r>   c                  J     e Zd ZdZd fd
Zd Zedd            ZddZ xZ	S )AlarmOccurrencezAdapter for absolute alarms.triggerr   rc   r
   parentComponentAdapter | Occurrencer   Nonec                j    t                                          |||           || _        || _        d S )N)superrH   rm   rc   )r!   rl   rc   rm   	__class__s       r"   rH   zAlarmOccurrence.__init__   s3     	111


r$   c                    | j                             |          }| j                                        }| j        |_        d|_        |g|_        |S )z2Return the alarm's parent as a modified component.)rI   r   )rm   rM   rc   copyr   TRIGGERREPEATsubcomponents)r!   rI   rm   
alarm_onces       r"   rM   zAlarmOccurrence.as_component   sU    ))'A * 
 
 Z__&&
!Z

 *|r$   r   c                    t                               | j                                        | j        j        | j        j        | j                  S rY   )r   r4   rm   rZ   r   r1   r   r    s    r"   r[   zAlarmOccurrence.id   sA     ++K&&((KOK&J	
 
 	
r$   r   c                P    d| j         j         d| j         d| j         d| j         S )z
repr(self)<z at z of z in )rr   r6   r   rc   rm   r    s    r"   __repr__zAlarmOccurrence.__repr__   sI    .' . .TZ . .
. . $. .	
r$   )rl   r   rc   r
   rm   rn   r   ro   rh   r5   )
r6   r7   r8   r9   rH   rM   r   r[   r|   __classcell__)rr   s   @r"   rk   rk      s        &&     	 	 	 
 
 
 _

 
 
 
 
 
 
 
r$   rk   )rk   r>   r   N)r9   
__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   r>   rk   __all__r3   r$   r"   <module>r      s   1 1 " " " " " " . . . . . . . . . . 6 6 6 6 6 6 6 6 6 6       E E E E E E           E''''''IIIIIIDDDDDDDDDD:T :T :T :T :T: :T :T :TzM, M, M, M, M, M, M, M,`'
 '
 '
 '
 '
j '
 '
 '
T  r$   