
    YPiy.              
       F   d Z ddlZddlZddlZddlZddlZddlmZm	Z	m
Z
 ddlmZ ddlmZ erddlmZ ej"                  j$                  Z	 ddlZdej                  dej,                  d	ej                  fd
Z	 	 dde
eej2                  ej                  ej
                  f   de	e   de	ej,                     d	efdZ	 	 dde
eej2                  ej                  ej
                  df   de	e   de	ej,                     d	e	e   fdZ	 dde	e   de	ej,                     d	e	ej                     fdZde	d   d	e
ej,                  df   fdZdej                  d	efdZde d	ejB                  fdZ"de	ej2                     de d	e	e
eej2                  f      fdZ#y# e$ r dZY Ow xY w)a  This module contains helper functions related to datetime and timestamp conversations.

.. versionchanged:: 20.0
   Previously, the contents of this module were available through the (no longer existing)
   module ``telegram._utils.helpers``.

Warning:
    Contents of this module are intended to be used internally by the library and *not* by the
    user. Changes to this module are not considered breaking changes and may not be documented in
    the changelog.
    N)TYPE_CHECKINGOptionalUnion)warn)PTBDeprecationWarning)Botdatetimetzinforeturnc                 b   |t         u r| j                  t               S t        j                  t              5  t        |t        j                        r|j                  |       cddd       S 	 ddd       | j                  | j                  |      S | j                  |      S # 1 sw Y   8xY w)z<Localize the datetime, both for pytz and zoneinfo timezones.r
   N)UTCreplace
contextlibsuppressAttributeError
isinstancepytz
BaseTzInfolocalizer
   
astimezone)r	   r
   s     N/root/twitch_bot/venv/lib/python3.12/site-packages/telegram/_utils/datetime.pyr   r   3   s    }s++			^	, -fdoo.??8,- -.-
 v..v&&- -s   +B%%B.time_objectreference_timestampc                    |t        j                          }n%t        | t        j                        rt	        d      t        | t        j
                        r|| j                         z   S t        | t        t        f      r|| z   S |t        }t        | t        j                         rt        j                  j                  || j                  xs |      }|j                         }|j                         }t        j                  j                  ||       }|j                  t        ||      }||j                         kD  r|t        j
                  d      z  }t!        |      S t        | t        j                        r#| j                  t        | |      } t!        |       S t#        dt%        |       j&                   d      )a  
    Converts a given time object to a float POSIX timestamp.
    Used to convert different time specifications to a common format. The time object
    can be relative (i.e. indicate a time increment, or a time of day) or absolute.
    Objects from the :class:`datetime` module that are timezone-naive will be assumed
    to be in UTC, if ``bot`` is not passed or ``bot.defaults`` is :obj:`None`.

    Args:
        time_object (:obj:`float` | :obj:`datetime.timedelta` |             :obj:`datetime.datetime` | :obj:`datetime.time`):
            Time value to convert. The semantics of this parameter will depend on its type:

            * :obj:`float` will be interpreted as "seconds from :paramref:`reference_t`"
            * :obj:`datetime.timedelta` will be interpreted as
              "time increment from :paramref:`reference_timestamp`"
            * :obj:`datetime.datetime` will be interpreted as an absolute date/time value
            * :obj:`datetime.time` will be interpreted as a specific time of day

        reference_timestamp (:obj:`float`, optional): POSIX timestamp that indicates the absolute
            time from which relative calculations are to be performed (e.g. when
            :paramref:`time_object` is given as an :obj:`int`, indicating "seconds from
            :paramref:`reference_time`"). Defaults to now (the time at which this function is
            called).

            If :paramref:`time_object` is given as an absolute representation of date & time (i.e.
            a :obj:`datetime.datetime` object), :paramref:`reference_timestamp` is not relevant
            and so its value should be :obj:`None`. If this is not the case, a :exc:`ValueError`
            will be raised.
        tzinfo (:class:`datetime.tzinfo`, optional): If :paramref:`time_object` is a naive object
            from the :mod:`datetime` module, it will be interpreted as this timezone. Defaults to
            :attr:`datetime.timezone.utc` otherwise.

            Note:
                Only to be used by ``telegram.ext``.

    Returns:
        :obj:`float` | :obj:`None`:
            The return value depends on the type of argument :paramref:`time_object`.
            If :paramref:`time_object` is given as a time increment (i.e. as a :obj:`int`,
            :obj:`float` or :obj:`datetime.timedelta`), then the return value will be
            :paramref:`reference_timestamp` + :paramref:`time_object`.

            Else if it is given as an absolute date/time value (i.e. a :obj:`datetime.datetime`
            object), the equivalent value as a POSIX timestamp will be returned.

            Finally, if it is a time of the day without date (i.e. a :obj:`datetime.time`
            object), the return value is the nearest future occurrence of that time of day.

    Raises:
        TypeError: If :paramref:`time_object` s type is not one of those described above.
        ValueError: If :paramref:`time_object` is a :obj:`datetime.datetime` and
            :paramref:`reference_timestamp` is not :obj:`None`.
    zAt is an (absolute) datetime while reference_timestamp is not Nonetz   )dayszUnable to convert z object to timestamp)timer   dtmr	   
ValueError	timedeltatotal_secondsintfloatr   fromtimestampr
   datetimetzcombiner   _datetime_to_float_timestamp	TypeErrortype__name__)r   r   r
   reference_dtreference_datereference_timeaware_datetimes          r   to_float_timestampr3   B   s   t ""iik	K	.\]]+s}}-"[%>%>%@@@+U|,"[00~ +sxx(||11K$6$6$@& 2 
 &**,%,,.--nkJ  ( &nf=N N1133cmm33N+N;;+s||,%";7K+K88
(k):)C)C(DDXY
ZZ    dt_objc                 6    | t        t        | ||            S dS )z
    Wrapper over :func:`to_float_timestamp` which returns an integer (the float value truncated
    down to the nearest integer).

    See the documentation for :func:`to_float_timestamp` for more details.
    N)r%   r3   )r5   r   r
   s      r   to_timestampr7      s.      	v':FCD r4   unixtimec                 d    | yt         j                  j                  | |t              S |      S )ai  
    Converts an (integer) unix timestamp to a timezone aware datetime object.
    :obj:`None` s are left alone (i.e. ``from_timestamp(None)`` is :obj:`None`).

    Args:
        unixtime (:obj:`int`): Integer POSIX timestamp.
        tzinfo (:obj:`datetime.tzinfo`, optional): The timezone to which the timestamp is to be
            converted to. Defaults to :obj:`None`, in which case the returned datetime object will
            be timezone aware and in UTC.

    Returns:
        Timezone aware equivalent :obj:`datetime.datetime` value if :paramref:`unixtime` is not
        :obj:`None`; else :obj:`None`.
    Nr   )r!   r	   r'   r   )r8   r
   s     r   from_timestampr:      s6    $ <<%%h&.3%UUf%UUr4   botr   c                 f    | yt        | d      r"| j                  r| j                  j                  S y)z
    Extracts the timezone info from the default values of the bot.
    If the bot has no default values, :obj:`None` is returned.
    Ndefaults)hasattrr=   r
   )r;   s    r   extract_tzinfo_from_defaultsr?      s/     {sJCLL||"""r4   c                     | j                   *| j                  t        j                  j                        } | j                         S )z
    Converts a datetime object to a float timestamp (with sub-second precision).
    If the datetime object is timezone-naive, it is assumed to be in UTC.
    r   )r
   r   r!   timezoneutc	timestamp)r5   s    r   r+   r+      s7    
 }}s||'7'78r4   r   c                     	 t        j                  |       S # t         j                  $ r}t        j                  d|  d      |d}~ww xY w)z|Wrapper around the `ZoneInfo` constructor with slightly more helpful error message
    in case tzdata is not installed.
    zNo time zone found with key z. Make sure to use a valid time zone name and correctly install the tzdata (https://pypi.org/project/tzdata/) package if your system does not provide the time zone data.N)zoneinfoZoneInfoZoneInfoNotFoundError)r   errs     r   get_zone_inforI      sW      $$)) ,,*2$ /? ?

 	s    A	AA	value	attributec                    | yt        j                  dd      j                         j                         dv r| S t	        t        dd| d      d	       | j                         x}j                         rt        |      S |S )
aP  
    Convert a `datetime.timedelta` to seconds or return it as-is, based on environment config.

    This utility is part of the migration process from integer-based time representations
    to using `datetime.timedelta`. The behavior is controlled by the `PTB_TIMEDELTA`
    environment variable.

    Note:
        When `PTB_TIMEDELTA` is not enabled, the function will issue a deprecation warning.

    Args:
        value (:obj:`datetime.timedelta`): The timedelta value to process.
        attribute (:obj:`str`): The name of the attribute at the caller scope, used for
            warning messages.

    Returns:
        - :obj:`None` if :paramref:`value` is None.
        - :obj:`datetime.timedelta` if `PTB_TIMEDELTA=true` or ``PTB_TIMEDELTA=1``.
        - :obj:`int` if the total seconds is a whole number.
        - float: otherwise.
    NPTB_TIMEDELTAfalse)true1zv22.2z%In a future major version attribute `z` will be of type `datetime.timedelta`. You can opt-in early by setting `PTB_TIMEDELTA=true` or ``PTB_TIMEDELTA=1`` as an environment variable.   )
stacklevel)	osgetenvlowerstripr   r   r$   
is_integerr%   )rJ   rK   secondss      r   get_timedelta_valuerY      s    0 }	yy'*00288:mK3I; ?B B	
  %*$7$7$99EEGGMTr4   )NN)N)$__doc__r   r	   r!   rS   r    rE   typingr   r   r   telegram._utils.warningsr   telegram.warningsr   telegramr   rA   rB   r   r   ImportErrorr
   r   r&   r#   r3   r%   r7   r:   r?   r+   strrF   rI   rY    r4   r   <module>rb      s  &
   	   1 1 ) 3	ll
's|| 'SZZ 'CLL '" ,0#'c[ucmmS\\388CDc[!%c[ SZZ c[ 	c[P ,0#'%chhDE!% SZZ  c]	( $(VsmVSZZ V cllV0huo %

D@P:Q  % c h// 'CMM"'/2'eC&'('W  Ds   F F F 