o
    ÌÄ.j‘  ã                   @  sh   d Z ddlmZ ddlmZmZ ddlmZmZ ddlm	Z	 ddl
mZ eƒ Zddd„Zdddd„ZdS )z)Utility functions for icalendar-searcher.é    )Úannotations)ÚIterableÚIterator)ÚdateÚdatetime)Útee)ÚTypesFactoryÚdt_valueúdate | datetimeÚreturnr   c                 C  sF   | du rdS t | dƒrt | dƒsddlm} t | |j¡ ¡ S |  ¡ S )zPConvert date to datetime for comparison, or return datetime as-is with timezone.NÚyearÚhourr   )Útime)Úhasattrr   r   ÚcombineÚminÚ
astimezone)r	   r   © r   úM/home/thesage/.local/lib/python3.10/site-packages/icalendar_searcher/utils.pyÚ_normalize_dt   s   r   FÚgr   Ú_debug_print_peekÚboolúbool | Iterablec                 C  sR   t | tƒst| ƒo
| S t| ƒ\}}zt|ƒ}|rt|ƒ |W S  ty(   Y dS w )a{  This method will return False if it's not possible to get an
    item from the iterable (which can only be done by utilizing
    `next`).  It will then return a new iterator that behaves like
    the original iterator (like if `next` wasn't used).

    Uses itertools.tee to create two independent iterators: one for
    checking if the iterator is empty, and one to return.
    F)Ú
isinstancer   r   r   ÚnextÚprintÚStopIteration)r   r   Úcheck_itÚ	result_itÚmy_valuer   r   r   Ú_iterable_or_false%   s   
	ÿr!   N)r	   r
   r   r   )F)r   r   r   r   r   r   )Ú__doc__Ú
__future__r   Úcollections.abcr   r   r   r   Ú	itertoolsr   Úicalendar.propr   Útypes_factoryr   r!   r   r   r   r   Ú<module>   s    
