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:
Takashi Kajinami 2024-01-27 19:44:33 +09:00
parent dd61a91864
commit bc57ccbc8b
3 changed files with 7 additions and 8 deletions

View File

@ -20,7 +20,6 @@ CONF() because it sets up configuration options.
"""
import datetime
import functools
import pytz
from oslo_db import exception as db_exception
from oslo_db import options as db_options
@ -148,7 +147,7 @@ class DateTimeInt(sql_types.TypeDecorator):
"""
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
# https://docs.sqlalchemy.org/en/14/core/custom_types.html# \
# sqlalchemy.types.TypeDecorator.cache_ok
@ -163,7 +162,7 @@ class DateTimeInt(sql_types.TypeDecorator):
raise ValueError(_('Programming Error: value to be stored '
'must be a datetime object.'))
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
# preserve microsecond data by moving the decimal. This is easier
# 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
# after the decimal) from what was stored to the DB
value = float(value) / 1000000
# NOTE(morgan): Explictly use timezone "pytz.UTC" to ensure we are
# not adjusting the actual datetime object from what we stored.
dt_obj = datetime.datetime.fromtimestamp(value, tz=pytz.UTC)
# NOTE(morgan): Explictly use timezone "datetime.timezone.utc" to
# ensure we are not adjusting the actual datetime object from what
# we stored.
dt_obj = datetime.datetime.fromtimestamp(value,
tz=datetime.timezone.utc)
# Return non-tz aware datetime object (as keystone expects)
return timeutils.normalize_time(dt_obj)

View File

@ -38,4 +38,3 @@ jsonschema>=3.2.0 # MIT
pycadf!=2.0.0,>=1.1.0 # Apache-2.0
msgpack>=0.5.0 # Apache-2.0
osprofiler>=1.4.0 # Apache-2.0
pytz>=2013.6 # MIT

View File

@ -3,7 +3,6 @@ flake8-docstrings
bashate~=2.1.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0
freezegun>=0.3.6 # Apache-2.0
pytz>=2013.6 # MIT
# Include drivers for opportunistic testing.
oslo.db[fixtures,mysql,postgresql]>=6.0.0 # Apache-2.0