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,
)
| 184 | |
| 185 | |
| 186 | def 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 | |
| 210 | def extract_tzinfo_from_defaults(bot: "Bot | None") -> dtm.tzinfo | None: |
no outgoing calls
searching dependent graphs…