mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
* Add basic typing for module_utils.
* Apply some suggestions.
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* Make pass again.
* Add more types as suggested.
* Normalize extra imports.
* Add more type hints.
* Improve typing.
* Add changelog fragment.
* Reduce changelog.
* Apply suggestions from code review.
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* Fix typo.
* Cleanup.
* Improve types and make type checking happy.
* Let's see whether older Pythons barf on this.
* Revert "Let's see whether older Pythons barf on this."
This reverts commit 9973af3dbe.
* Add noqa.
---------
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
22 lines
687 B
Python
22 lines
687 B
Python
#
|
|
# Copyright (c) 2023 Felix Fontein <felix@fontein.de>
|
|
# Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
from __future__ import annotations
|
|
|
|
import datetime as _datetime
|
|
|
|
|
|
def ensure_timezone_info(value: _datetime.datetime) -> _datetime.datetime:
|
|
if value.tzinfo is not None:
|
|
return value
|
|
return value.astimezone(_datetime.timezone.utc)
|
|
|
|
|
|
def fromtimestamp(value: int | float) -> _datetime.datetime:
|
|
return _datetime.datetime.fromtimestamp(value, tz=_datetime.timezone.utc)
|
|
|
|
|
|
def now() -> _datetime.datetime:
|
|
return _datetime.datetime.now(tz=_datetime.timezone.utc)
|