mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 16:01:55 +00:00
* Adjust all __future__ imports: for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i; done * Remove all UTF-8 encoding specifications for Python source files: for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i; done * Remove __metaclass__ = type: for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do sed -e '/^__metaclass__ = type/d' -i $i; done
30 lines
792 B
Python
30 lines
792 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
|
|
import sys
|
|
|
|
|
|
_USE_TIMEZONE = sys.version_info >= (3, 6)
|
|
|
|
|
|
def ensure_timezone_info(value):
|
|
if not _USE_TIMEZONE or value.tzinfo is not None:
|
|
return value
|
|
return value.astimezone(_datetime.timezone.utc)
|
|
|
|
|
|
def fromtimestamp(value):
|
|
if _USE_TIMEZONE:
|
|
return _datetime.fromtimestamp(value, tz=_datetime.timezone.utc)
|
|
return _datetime.utcfromtimestamp(value)
|
|
|
|
|
|
def now():
|
|
if _USE_TIMEZONE:
|
|
return _datetime.datetime.now(tz=_datetime.timezone.utc)
|
|
return _datetime.datetime.utcnow()
|