Remove dependency on pytz
pytz will be removed from RHEL/CentOS 10 because of the built-in zoneinfo[1]. Because the current usage of pytz can be very easily replaced, this removes the dependency on pytz. [1] https://issues.redhat.com/browse/RHEL-219 Change-Id: Ib90acd5ebb9a0c2cffd643bda0ecdafa97552008
This commit is contained in:
@@ -20,7 +20,6 @@ CONF() because it sets up configuration options.
|
|||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
import pytz
|
|
||||||
|
|
||||||
from oslo_db import exception as db_exception
|
from oslo_db import exception as db_exception
|
||||||
from oslo_db import options as db_options
|
from oslo_db import options as db_options
|
||||||
@@ -148,7 +147,7 @@ class DateTimeInt(sql_types.TypeDecorator):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
impl = sql.BigInteger
|
impl = sql.BigInteger
|
||||||
epoch = datetime.datetime.fromtimestamp(0, tz=pytz.UTC)
|
epoch = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
|
||||||
# NOTE(ralonsoh): set to True as any other TypeDecorator in SQLAlchemy
|
# NOTE(ralonsoh): set to True as any other TypeDecorator in SQLAlchemy
|
||||||
# https://docs.sqlalchemy.org/en/14/core/custom_types.html# \
|
# https://docs.sqlalchemy.org/en/14/core/custom_types.html# \
|
||||||
# sqlalchemy.types.TypeDecorator.cache_ok
|
# sqlalchemy.types.TypeDecorator.cache_ok
|
||||||
@@ -163,7 +162,7 @@ class DateTimeInt(sql_types.TypeDecorator):
|
|||||||
raise ValueError(_('Programming Error: value to be stored '
|
raise ValueError(_('Programming Error: value to be stored '
|
||||||
'must be a datetime object.'))
|
'must be a datetime object.'))
|
||||||
value = timeutils.normalize_time(value)
|
value = timeutils.normalize_time(value)
|
||||||
value = value.replace(tzinfo=pytz.UTC)
|
value = value.replace(tzinfo=datetime.timezone.utc)
|
||||||
# NOTE(morgan): We are casting this to an int, and ensuring we
|
# NOTE(morgan): We are casting this to an int, and ensuring we
|
||||||
# preserve microsecond data by moving the decimal. This is easier
|
# preserve microsecond data by moving the decimal. This is easier
|
||||||
# than being concerned with the differences in Numeric types in
|
# than being concerned with the differences in Numeric types in
|
||||||
@@ -177,9 +176,11 @@ class DateTimeInt(sql_types.TypeDecorator):
|
|||||||
# Convert from INT to appropriate micro-second float (microseconds
|
# Convert from INT to appropriate micro-second float (microseconds
|
||||||
# after the decimal) from what was stored to the DB
|
# after the decimal) from what was stored to the DB
|
||||||
value = float(value) / 1000000
|
value = float(value) / 1000000
|
||||||
# NOTE(morgan): Explictly use timezone "pytz.UTC" to ensure we are
|
# NOTE(morgan): Explictly use timezone "datetime.timezone.utc" to
|
||||||
# not adjusting the actual datetime object from what we stored.
|
# ensure we are not adjusting the actual datetime object from what
|
||||||
dt_obj = datetime.datetime.fromtimestamp(value, tz=pytz.UTC)
|
# we stored.
|
||||||
|
dt_obj = datetime.datetime.fromtimestamp(value,
|
||||||
|
tz=datetime.timezone.utc)
|
||||||
# Return non-tz aware datetime object (as keystone expects)
|
# Return non-tz aware datetime object (as keystone expects)
|
||||||
return timeutils.normalize_time(dt_obj)
|
return timeutils.normalize_time(dt_obj)
|
||||||
|
|
||||||
|
|||||||
@@ -38,4 +38,3 @@ jsonschema>=3.2.0 # MIT
|
|||||||
pycadf!=2.0.0,>=1.1.0 # Apache-2.0
|
pycadf!=2.0.0,>=1.1.0 # Apache-2.0
|
||||||
msgpack>=0.5.0 # Apache-2.0
|
msgpack>=0.5.0 # Apache-2.0
|
||||||
osprofiler>=1.4.0 # Apache-2.0
|
osprofiler>=1.4.0 # Apache-2.0
|
||||||
pytz>=2013.6 # MIT
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ flake8-docstrings
|
|||||||
bashate~=2.1.0 # Apache-2.0
|
bashate~=2.1.0 # Apache-2.0
|
||||||
stestr>=1.0.0 # Apache-2.0
|
stestr>=1.0.0 # Apache-2.0
|
||||||
freezegun>=0.3.6 # Apache-2.0
|
freezegun>=0.3.6 # Apache-2.0
|
||||||
pytz>=2013.6 # MIT
|
|
||||||
|
|
||||||
# Include drivers for opportunistic testing.
|
# Include drivers for opportunistic testing.
|
||||||
oslo.db[fixtures,mysql,postgresql]>=6.0.0 # Apache-2.0
|
oslo.db[fixtures,mysql,postgresql]>=6.0.0 # Apache-2.0
|
||||||
|
|||||||
Reference in New Issue
Block a user