L iy. FdZddlZddlZddlZddlZddlZddlmZm Z m Z ddl m Z ddl mZerddlmZej"j$Z ddlZdejdej,d ejfd Z dd e eej2ejej fd e ede ej,d efd Z dde eej2ejej dfd e ede ej,d e efdZ dde ede ej,d e ejfdZde dd e ej,dffdZdejd efdZde d ejBfdZ"de ej2de d e e eej2ffdZ#y#e$rdZYOwxYw)aThis 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_CHECKINGOptionalUnion)warn)PTBDeprecationWarning)Botdatetimetzinforeturncb|tur|jtStjt5t |t jr|j|cdddS ddd|j|j|S|j|S#1swY8xYw)z%>%@@@+U|,"[00 ~+sxx(||11 K$6$6$@&2 &**,%,,.--nkJ  (&nf=N N113 3 cmm3 3N+N;;+s||,    %";7K+K88 (k):)C)C(DDXY ZZdt_objc6|tt|||SdS)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)r5rr s r to_timestampr7s.   v':F CDr4unixtimecd|ytjj|| tS|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)r8r s rfrom_timestampr:s6$ << % %h&.3 % UUf % UUr4botrcf|yt|dr"|jr|jjSy)z Extracts the timezone info from the default values of the bot. If the bot has no default values, :obj:`None` is returned. Ndefaults)hasattrr=r )r;s rextract_tzinfo_from_defaultsr?s/ {sJCLL||""" r4c|j*|jtjj}|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 rr!timezoneutc timestamp)r5s rr+r+s7 }}s||'7'78    r4rc tj|S#tj$r}tjd|d|d}~wwxYw)z|Wrapper around the `ZoneInfo` constructor with slightly more helpful error message in case tzdata is not installed. zNo 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)zoneinfoZoneInfoZoneInfoNotFoundError)rerrs r get_zone_inforIsW  $$  ) ),,*2$/? ?   sA AA value attributec|ytjddjjdvr|St t dd|dd |j x}jr 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_TIMEDELTAfalse)true1zv22.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) osgetenvlowerstriprrr$ is_integerr%)rJrKsecondss rget_timedelta_valuerYs0 } yy'*00288:mK  3I;?B B %*$7$7$99EEGG MTr4)NN)N)$__doc__rr r!rSr rEtypingrrrtelegram._utils.warningsrtelegram.warningsrtelegramrrArBrr ImportErrorr rr&r#r3r%r7r:r?r+strrFrIrYr4rrbs&  11)3 ll 's|| 'SZZ 'CLL '",0#'c[ucmmS\\388CDc[!%c[ SZZ c[ c[P,0#' % chhD E!% SZZ c] ($(VsmV SZZ VcllV0 huo % D@P:Q % c h// ' CMM "'/2' eC&'('W Ds FF F