
    i                        d Z ddlmZ ddlmZmZmZ ddlmZmZ erddl	m
Z
mZ dd
ZddZddZddZddZddZg dZdS )z Utility functions for icalendar.    )annotations)datedatetimetzinfo)TYPE_CHECKINGcast)	TypeGuardTypeIsdtdate | datetimereturnboolc                X    t          | t                    ot          | t                     S )a  Check if a value is a date but not a datetime.

    This function distinguishes between ``date`` and ``datetime`` objects,
    returning ``True`` only for pure ``date`` instances.

    Parameters:
        dt: The date or datetime object to check.

    Returns:
        ``True`` if the value is a ``date`` but not a ``datetime``,
        ``False`` otherwise.

    Example:
        .. code-block:: pycon

            >>> from datetime import date, datetime
            >>> from icalendar.tools import is_date
            >>> is_date(date(2024, 1, 15))
            True
            >>> is_date(datetime(2024, 1, 15, 10, 30))
            False
    )
isinstancer   r   r   s    J/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/tools.pyis_dater      s&    . b$@
2x(@(@$@@    TypeIs[datetime]c                ,    t          | t                    S )a  Check if a value is a datetime.

    Parameters:
        dt: The date or datetime object to check.

    Returns:
        ``True`` if the value is a ``datetime``, ``False`` if it is
        only a ``date``.

    Example:
        .. code-block:: pycon

            >>> from datetime import date, datetime
            >>> from icalendar.tools import is_datetime
            >>> is_datetime(datetime(2024, 1, 15, 10, 30))
            True
            >>> is_datetime(date(2024, 1, 15))
            False
    )r   r   r   s    r   is_datetimer   &   s    ( b(###r   r   c                    t          |           r t          | j        | j        | j                  S t          d|           S )a  Convert a date to a datetime.

    If the input is already a ``datetime``, it is returned unchanged.
    If the input is a ``date``, it is converted to a ``datetime`` at midnight.

    Parameters:
        dt: The date or datetime to convert.

    Returns:
        A ``datetime`` object. If the input was a ``date``, the time
        component will be set to midnight (00:00:00).

    Example:
        .. code-block:: pycon

            >>> from datetime import date, datetime
            >>> from icalendar.tools import to_datetime
            >>> to_datetime(date(2024, 1, 15))
            datetime.datetime(2024, 1, 15, 0, 0)
            >>> to_datetime(datetime(2024, 1, 15, 10, 30))
            datetime.datetime(2024, 1, 15, 10, 30)
    r   )r   r   yearmonthdayr   r   s    r   to_datetimer   =   s:    . r{{ 326222
Br   tzr   c                "    t          | d          S )ao  Check if a timezone is a pytz timezone.

    pytz timezones require special handling with ``localize()`` and
    ``normalize()`` methods for correct timezone calculations.

    Parameters:
        tz: The timezone info object to check.

    Returns:
        ``True`` if the timezone is a pytz timezone (has a ``localize``
        attribute), ``False`` otherwise.
    localize)hasattr)r   s    r   is_pytzr!   Y   s     2z"""r   TypeGuard[datetime]c                T    t          |           o| j        x}duot          |          S )av  Check if a datetime uses a pytz timezone.

    This function checks whether the datetime has a timezone attached
    and whether that timezone is a pytz timezone requiring special handling.

    Parameters:
        dt: The date or datetime object to check.

    Returns:
        ``True`` if the value is a ``datetime`` with a pytz timezone,
        ``False`` otherwise.
    N)r   r   r!   )r   r   s     r   
is_pytz_dtr$   i   s,     r??T") 3D@TWV__Tr   c                X    t          |           r| j                            |           S | S )a  Normalize a datetime after calculations when using pytz.

    pytz requires the ``normalize()`` function to be called after arithmetic
    operations to correctly adjust the timezone offset, especially around
    daylight saving time transitions.

    Parameters:
        dt: The date or datetime to normalize.

    Returns:
        The normalized datetime if it uses pytz, otherwise the input unchanged.
    )r$   r   	normalizer   s    r   normalize_pytzr'   y   s-     "~~ 'y""2&&&Ir   )r   r   r!   r$   r'   r   N)r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r"   )r   r   r   r   )__doc__
__future__r   r   r   r   typingr   r   icalendar.compatibilityr	   r
   r   r   r   r!   r$   r'   __all__ r   r   <module>r.      s   & & " " " " " " + + + + + + + + + + & & & & & & & & :99999999A A A A4$ $ $ $.       8# # # # U U U U    $  r   