Debian Codegraph @

ansible_collections/community/general/plugins/module_utils/_datetime.py

raw
1 #
2 # Copyright (c) 2023 Felix Fontein <[email protected]>
3 # Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
4 # SPDX-License-Identifier: BSD-2-Clause
5
6 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
7 # Do not use this from other collections or standalone plugins/modules!
8
9 from __future__ import annotations
10
11 import datetime as _datetime
12
13
14 def ensure_timezone_info(value: _datetime.datetime) -> _datetime.datetime:
15 if value.tzinfo is not None:
16 return value
17 return value.astimezone(_datetime.timezone.utc)
18
19
20 def fromtimestamp(value: int | float) -> _datetime.datetime:
21 return _datetime.datetime.fromtimestamp(value, tz=_datetime.timezone.utc)
22
23
24 def now() -> _datetime.datetime:
25 return _datetime.datetime.now(tz=_datetime.timezone.utc)