diff --git a/cloudkitty/utils/__init__.py b/cloudkitty/utils/__init__.py index f3170af6..3af69f6f 100644 --- a/cloudkitty/utils/__init__.py +++ b/cloudkitty/utils/__init__.py @@ -67,21 +67,24 @@ def iso8601_from_timestamp(timestamp, microsecond=False): """Returns an iso8601 formatted date from timestamp""" # Python provides a similar instance method for datetime.datetime - # objects called isoformat() and utcfromtimestamp(). The format - # of the strings generated by isoformat() and utcfromtimestamp() + # objects called isoformat() and fromtimestamp(). The format + # of the strings generated by isoformat() and fromtimestamp() # have a couple of problems: # 1) The method iso8601_from_timestamp in oslo_utils is realized # by isotime, the strings generated by isotime are used in # tokens and other public APIs that we can't change without a # deprecation period. The strings generated by isoformat are # not the same format, so we can't just change to it. - # 2) The strings generated by isoformat() and utcfromtimestamp() + # 2) The strings generated by isoformat() and fromtimestamp() # do not include the microseconds if the value happens to be 0. # This will likely show up as random failures as parsers may be # written to always expect microseconds, and it will parse # correctly most of the time. - return isotime(datetime.datetime.utcfromtimestamp(timestamp), microsecond) + return isotime( + datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc), + microsecond + ) def dt2ts(orig_dt): @@ -100,7 +103,8 @@ def ts2dt(timestamp): """timestamp to datetime format.""" if not isinstance(timestamp, float): timestamp = float(timestamp) - return datetime.datetime.utcfromtimestamp(timestamp) + return datetime.datetime.fromtimestamp( + timestamp, tz=datetime.timezone.utc).replace(tzinfo=None) def ts2iso(timestamp):