forked from ansible-collections/community.general
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid deprecated utcnow() (ansible-collections#8222)
Avoid deprecated utcnow().
- Loading branch information
1 parent
17afd0e
commit 7e1a5d5
Showing
19 changed files
with
142 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
minor_changes: | ||
- "Use offset-aware ``datetime.datetime`` objects (with timezone UTC) instead of offset-naive UTC timestamps, | ||
which are deprecated in Python 3.12 (https://github.com/ansible-collections/community.general/pull/8222)." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Felix Fontein <[email protected]> | ||
# 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 (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.