
    F2j                        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    h/home/thesage/.hermes/hermes-agent/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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$   r   r   c                    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__r6   rG   r   r   rD   r    s    r"   __repr__zOccurrence.__repr__l   s|    '  }.7 8  Z  	 
 #'-"8  	
r$   keep_recurrence_attributesboolr   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!   rM   	components      r"   rQ   zOccurrence.as_componentx   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!   rS   rT   s      r"   
is_in_spanzOccurrence.is_in_span   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!   rW   
self_startother_starts       r"   __lt__zOccurrence.__lt__   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!   rW   s     r"   __eq__zOccurrence.__eq__   s    w%(""r$   c                4    | j                                         S )zThe name of this component.)rG   r^   r    s    r"   r^   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!   rg   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   r5   )rM   rN   r   r   )rS   r   rT   r   r   rN   )rW   r>   r   rN   r   r   )r   rE   )rg   r
   r   rN   )r   r   )r6   r7   r8   r9   rH   rL   rQ   rV   r[   r   r_   rb   rd   r^   propertyr   rj   r1   r3   r$   r"   r>   r>   V   sB       ##
 "'+! ! ! ! !&

 

 

 

   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   rg   r
   parentComponentAdapter | Occurrencer   Nonec                j    t                                          |||           || _        || _        d S )N)superrH   rq   rg   )r!   rp   rg   rq   rK   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.)rM   r   )rq   rQ   rg   copyr   TRIGGERREPEATsubcomponents)r!   rM   rq   
alarm_onces       r"   rQ   zAlarmOccurrence.as_component   sU    ))'A * 
 
 Z__&&
!Z

 *|r$   r   c                    t                               | j                                        | j        j        | j        j        | j                  S r]   )r   r4   rq   r^   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)rJ   z at z of z in )rK   r6   r   rg   rq   r    s    r"   rL   zAlarmOccurrence.__repr__   sI    .' . .TZ . .
. . $. .	
r$   )rp   r   rg   r
   rq   rr   r   rs   rl   r5   )
r6   r7   r8   r9   rH   rQ   r   r_   rL   __classcell__)rK   s   @r"   ro   ro      s        &&     	 	 	 
 
 
 _

 
 
 
 
 
 
 
r$   ro   )ro   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>   ro   __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Y, Y, Y, Y, Y, Y, Y, Y,x'
 '
 '
 '
 '
j '
 '
 '
T  r$   