
    iR!                         d Z ddlmZmZmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlm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  G d de          ZdgZdS )z&PERIOD property type from :rfc:`5545`.    )datedatetime	timedelta)AnyClassVar)Self)JCalParsingError)
Parameters)tzp)is_datetimenormalize_pytz   )TimeBase)	vDatetime)	vDurationc                      e Zd ZU dZdZee         ed<   eed<   e	ed<   e
ed<   e
ed<   eed<   	 dd
ee
e
ez  f         deeef         d	z  fdZd Zd Zedd            Zd Zed             ZddlmZ edee         fd            ZddlmZ dedefdZedeez  dee
e
f         ee
ef         z  fd            Zededefd            Z d	S )vPerioda 	  Period of Time

    Value Name:
        PERIOD

    Purpose:
        This value type is used to identify values that contain a
        precise period of time.

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

        .. code-block:: text

            period     = period-explicit / period-start

           period-explicit = date-time "/" date-time
           ; [ISO.8601.2004] complete representation basic format for a
           ; period of time consisting of a start and end.  The start MUST
           ; be before the end.

           period-start = date-time "/" dur-value
           ; [ISO.8601.2004] complete representation basic format for a
           ; period of time consisting of a start and positive duration
           ; of time.

    Description:
        If the property permits, multiple "period" values are
        specified by a COMMA-separated list of values.  There are two
        forms of a period of time.  First, a period of time is identified
        by its start and its end.  This format is based on the
        [ISO.8601.2004] complete representation, basic format for "DATE-
        TIME" start of the period, followed by a SOLIDUS character
        followed by the "DATE-TIME" of the end of the period.  The start
        of the period MUST be before the end of the period.  Second, a
        period of time can also be defined by a start and a positive
        duration of time.  The format is based on the [ISO.8601.2004]
        complete representation, basic format for the "DATE-TIME" start of
        the period, followed by a SOLIDUS character, followed by the
        [ISO.8601.2004] basic format for "DURATION" of the period.

    Example:
        The period starting at 18:00:00 UTC, on January 1, 1997 and
        ending at 07:00:00 UTC on January 2, 1997 would be:

        .. code-block:: ics

            19970101T180000Z/19970102T070000Z

        The period start at 18:00:00 on January 1, 1997 and lasting 5 hours
        and 30 minutes would be:

        .. code-block:: ics

            19970101T180000Z/PT5H30M

        .. code-block:: pycon

            >>> from icalendar.prop import vPeriod
            >>> period = vPeriod.from_ical('19970101T180000Z/19970102T070000Z')
            >>> period = vPeriod.from_ical('19970101T180000Z/PT5H30M')
    PERIODdefault_valueparamsby_durationstartenddurationNperc                    |\  }}t          |t          t          f          st          d          t          |t          t          t          f          st          d          t          |t                    }|r|}t          ||z             }n|}t          ||z
            }||k    rt          d          t          |pddi          | _        | j        	                    |           || _
        || _        || _        || _        d S )Nz/Start value MUST be a datetime or date instancez>end_or_duration MUST be a datetime, date or timedelta instancez#Start time is greater than end timevaluer   )
isinstancer   r   	TypeErrorr   r   
ValueErrorr
   r   update_tzid_fromr   r   r   r   )selfr   r   r   end_or_durationr   r   r   s           S/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/prop/dt/period.py__init__zvPeriod.__init__X   s   
 "%58T"233 	OMNNN?XtY,GHH 	P   !)<< 	3&H !122CC!C%cEk22H3;;BCCC !>GX+>?? 	$$U+++
&     c                     | j         |j         k    r|                    |           S | j         |j         cxk    o
| j        k     nc S N)r   overlapsr   )r"   others     r$   r)   zvPeriod.overlapsx   sK    :##>>$'''zU[33334833333r&   c                 P   | j         rPt          | j                                                  dz   t	          | j                                                  z   S t          | j                                                  dz   t          | j                                                  z   S )N   /)r   r   r   to_icalr   r   r   r"   s    r$   r-   zvPeriod.to_ical}   s     	$*%%--//DM**22445
 $$,,..5	$(8K8K8S8S8U8UUUr&   c                     ddl m} 	 |                     d          \  }}|                    ||          }|                    ||          }n%# t          $ r}t          d|            |d }~ww xY w||fS )Nr   )	vDDDTypes/)timezonezExpected period format, got: )icalendar.prop.dt.typesr0   split	from_ical	Exceptionr    )icalr2   r0   r   r#   es         r$   r5   zvPeriod.from_ical   s    555555	L%)ZZ__"E?'''AAE'11/H1UUOO 	L 	L 	LCTCCDD!K	L''s   AA 
A1A,,A1c                 T    | j         r| j        | j        fn| j        | j        f}d|dS )NzvPeriod())r   r   r   r   )r"   ps     r$   __repr__zvPeriod.__repr__   s7    +/+;WTZ''$*dhAW !    r&   c                 :    | j         | j        r| j        n| j        fS )z-Make this cooperate with the other vDDDTypes.)r   r   r   r   r.   s    r$   dtz
vPeriod.dt   s!     
d.>LT]]DHNNr&   r   )FBTYPEreturnc                     t          t          ddddd          t          dd          f          t          t          ddddd          t          dddd	d
          f          gS )zExamples of vPeriod.i     
      #   r      )hoursminutes      )r   r   r   )clss    r$   exampleszvPeriod.examples   sm     XdBB33YQPR5S5S5STUUXdBB33XdBBPQ5R5RSTT
 	
r&   )VALUEnamec                    t          | j                                      |          d         g}| j        rA|                    t          | j                                      |          d                    n@|                    t          | j                                      |          d                    || j                            d          | j	        
                                |gS )zBThe jCal representation of this property according to :rfc:`7265`.T)exclude_utc)r   r   to_jcalr   appendr   r   r   r   rM   lower)r"   rN   r   s      r$   rR   zvPeriod.to_jcal   s    4:&&..t44R89 	@LL4=1199$??CDDDDLL48,,44T::2>???dk))d);;TZ=M=M=O=OQVWWr&   jcalc                    t          |t                    rd|v r|                    d          }t          |t                    rt	          |          dk    rt          d| |          t          j        d          5  t          j        |d                   }ddd           n# 1 swxY w Y   t          j        d          5  t          j	        |d         t          |            |d         
                    d          rt          j        |d                   }nG	 t          j        |d                   }n+# t
          $ r}t          d	| |d                   |d}~ww xY wddd           n# 1 swxY w Y   ||fS )
zParse a jCal value.

        Raises:
            ~error.JCalParsingError: If the period is not a list with exactly two items,
                or it can't parse a date-time or duration.
        r1      z-A period must be a list with exactly 2 items.)r   r   Nr   )Pz-Pz+Pz#Cannot parse date-time or duration.)r   strr4   listlenr	   reraise_with_path_addedr   parse_jcal_valuevalidate_value_type
startswithr   )rK   rU   r   r#   r8   s        r$   r]   zvPeriod.parse_jcal_value   s    dC   	#SD[[::c??D$%% 	Ta"?D    5a88 	8 	8.tAw77E	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	85a88 	 	0a#sCCCAw!!"344 
"+"<T!W"E"E&/&@a&I&IOO'   *="1g   		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 o%%sI   =B$$B(+B(AE.D76E.7
EEEE..E25E2jcal_propertyc                    t          j        ||            t          j        d          5  |                     |d                   \  }}ddd           n# 1 swxY w Y   t	          j        |          }|j        }|r9t          j        ||          }t          |          rt          j        ||          } | ||f|          S )zParse jCal from :rfc:`7265`.

        Parameters:
            jcal_property: The jCal property to parse.

        Raises:
            ~error.JCalParsingError: If the provided jCal is invalid.
           N)r   )
r	   validate_propertyr\   r]   r
   from_jcal_propertytzidr   localizer   )rK   r`   r   r#   r   re   s         r$   	from_jcalzvPeriod.from_jcal   s    	*=#>>>5a88 	L 	L%(%9%9-:J%K%K"E?	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L.}=={ 	FL--E?++ F"%,"E"EsE?+F;;;;s   AAAr(   )!__name__
__module____qualname____doc__r   r   rY   __annotations__r
   boolr   r   tupledictr   r%   r)   r-   staticmethodr5   r<   propertyr>   icalendar.paramr?   classmethodrZ   r   rL   rM   rR   r]   rg    r&   r$   r   r      s        = =~ $,M8C=+++OOO	MMM
 )-! !8X	112! S#X%! ! ! !@4 4 4
V V V 	( 	( 	( \	(! ! ! O O XO '&&&&&
d 
 
 
 [
 &%%%%%XC XD X X X X &:&	x!	"U8Y+>%?	?& & & [&B <d <t < < < [< < <r&   r   N)rk   r   r   r   typingr   r   icalendar.compatibilityr   icalendar.errorr	   icalendar.parserr
   icalendar.timezoner   icalendar.toolsr   r   baser   r   r   r   r   __all__rt   r&   r$   <module>r}      s   , , . . . . . . . . . .                 ( ( ( ( ( ( , , , , , , ' ' ' ' ' ' " " " " " " 7 7 7 7 7 7 7 7                  V< V< V< V< V<h V< V< V<r +r&   