MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / from_timestamp

Function from_timestamp

src/telegram/_utils/datetime.py:186–207  ·  view source on GitHub ↗

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

(
    unixtime: int | None,
    tzinfo: dtm.tzinfo | None = None,
)

Source from the content-addressed store, hash-verified

184
185
186def from_timestamp(
187 unixtime: int | None,
188 tzinfo: dtm.tzinfo | None = None,
189) -> dtm.datetime | None:
190 """
191 Converts an (integer) unix timestamp to a timezone aware datetime object.
192 :obj:`None` s are left alone (i.e. ``from_timestamp(None)`` is :obj:`None`).
193
194 Args:
195 unixtime (:obj:`int`): Integer POSIX timestamp.
196 tzinfo (:obj:`datetime.tzinfo`, optional): The timezone to which the timestamp is to be
197 converted to. Defaults to :obj:`None`, in which case the returned datetime object will
198 be timezone aware and in UTC.
199
200 Returns:
201 Timezone aware equivalent :obj:`datetime.datetime` value if :paramref:`unixtime` is not
202 :obj:`None`; else :obj:`None`.
203 """
204 if unixtime is None:
205 return None
206
207 return dtm.datetime.fromtimestamp(unixtime, tz=UTC if tzinfo is None else tzinfo)
208
209
210def extract_tzinfo_from_defaults(bot: "Bot | None") -> dtm.tzinfo | None:

Callers 15

de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
de_jsonMethod · 0.90
_de_jsonMethod · 0.90
de_jsonMethod · 0.90

Calls

no outgoing calls

Tested by 9

test_ban_chat_memberMethod · 0.72
test_de_jsonMethod · 0.72
chat_boostFunction · 0.72
removed_chat_boostFunction · 0.72
chat_member_updatedFunction · 0.72
star_transaction_factoryFunction · 0.72
test_de_jsonMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…