
    Yi#              
          S r SSKrSSKrSSKJrJrJr  \(       a  SSKJ	r	  \R                  R                  r SSKr\R                  rS\R                  S\R                   S\R                  4S jr  SS	\\\R&                  \R                  \R                  4   S
\\   S\\R                      S\4S jjr  SS\\\R&                  \R                  \R                  S4   S
\\   S\\R                      S\\   4S jjr SS\\   S\\R                      S\\R                     4S jjrS\S   S\\R                   S4   4S jrS\R                  S\4S jrg! \ a    \r GNf = f)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)Botdatetimetzinforeturnc                 \    U[         L a  U R                  [         S9$ UR                  U 5      $ )zYLocalize the datetime, where UTC is handled depending on whether pytz is available or notr   )DTM_UTCreplacelocalize)r   r   s     C/app/.venv/lib/python3.13/site-packages/telegram/_utils/datetime.py	_localizer   0   s-    w//??8$$    time_objectreference_timestampc                    Uc  [         R                   " 5       nO*[        U [        R                  5      (       a  [	        S5      e[        U [        R
                  5      (       a  XR                  5       -   $ [        U [        [        45      (       a  X-   $ Uc  [        n[        U [        R                   5      (       a  [        R                  R                  XR                  =(       d    US9nUR                  5       nUR                  5       n[        R                  R                  X@5      nUR                  c  [        Xb5      nXVR                  5       :  a  U[        R
                  " SS9-  n[!        U5      $ [        U [        R                  5      (       a#  U R                  c  [        X5      n [!        U 5      $ [#        S[%        U 5      R&                   S35      e)aX  
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
        ``pytz.utc``, if available, and :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)time
isinstancedtmr   
ValueError	timedeltatotal_secondsintfloatUTC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_timestampr.   7   s~   t ""iik	K	.	.\]]+s}}--"%>%>%@@@+U|,,"00~+sxx((||11$6$6$@& 2 
 &**,%,,.--nJ  (&~>N 1133cmm33N+N;;+s||,,%#K8K+K88
(k):)C)C(DDXY
ZZr   dt_objc                 6    U b  [        [        XU5      5      $ 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   r.   )r/   r   r   s      r   to_timestampr1      s+      	vFCD r   unixtimec                 Z    U c  g[         R                  R                  Xc  [        S9$ US9$ )a=  
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!   )r2   r   s     r   from_timestampr4      s4    $ <<%%h.3%UUf%UUr   botr   c                 |    U c  g[        U S5      (       a'  U R                  (       a  U R                  R                  $ g)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)hasattrr7   r   )r5   s    r   extract_tzinfo_from_defaultsr9      s2     {sJCLL||"""r   c                     U R                   c'  U R                  [        R                  R                  S9n U R                  5       $ )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)r/   s    r   r&   r&      s7    
 }}s||'7'78r   )NN)N)__doc__r   r   r   typingr   r   r   telegramr   r;   r<   r   pytzr!   ImportErrorr   r   r    r   r.   r   r1   r4   r9   r&    r   r   <module>rD      s  &
   1 1 ,,


((C
% %cjj %S\\ % ,0#'[[ucmmS\\388CD[[!%[[ SZZ [[ 	[[@ ,0#'%chhDE!% SZZ  c]	( $(VsmVSZZ V cllV0huo %

D@P:Q  % E  
Cs   E E('E(