Drop pytz

It can be replaced by the built-in datetime module.

Change-Id: Ib33163496fb8068b9578c4cb231bf6d070cc78b9
This commit is contained in:
Takashi Kajinami 2024-09-27 23:19:44 +09:00
parent 0f8cb1c461
commit 4c0da145f2
3 changed files with 19 additions and 15 deletions

View File

@ -1,6 +1,5 @@
WebOb>=1.8.0 WebOb>=1.8.0
simplegeneric simplegeneric
pytz
netaddr>=0.7.12 netaddr>=0.7.12
# TODO: Drop this when Python 3.10 is our minimum supported version # TODO: Drop this when Python 3.10 is our minimum supported version
importlib_metadata>=4.4 # Apache-2.0 importlib_metadata>=4.4 # Apache-2.0

View File

@ -1,6 +1,5 @@
import datetime import datetime
import unittest import unittest
import pytz
from wsme import utils from wsme import utils
@ -27,11 +26,14 @@ class TestUtils(unittest.TestCase):
good_times = [ good_times = [
('12:03:54', datetime.time(12, 3, 54)), ('12:03:54', datetime.time(12, 3, 54)),
('23:59:59.000004', datetime.time(23, 59, 59, 4)), ('23:59:59.000004', datetime.time(23, 59, 59, 4)),
('01:02:03+00:00', datetime.time(1, 2, 3, 0, pytz.UTC)), ('01:02:03+00:00', datetime.time(
('01:02:03+23:59', datetime.time(1, 2, 3, 0, 1, 2, 3, 0, datetime.timezone.utc)),
pytz.FixedOffset(1439))), ('01:02:03+23:59', datetime.time(
('01:02:03-23:59', datetime.time(1, 2, 3, 0, 1, 2, 3, 0,
pytz.FixedOffset(-1439))), datetime.timezone(datetime.timedelta(minutes=1439)))),
('01:02:03-23:59', datetime.time(
1, 2, 3, 0,
datetime.timezone(datetime.timedelta(minutes=-1439)))),
] ]
ill_formatted_times = [ ill_formatted_times = [
'24-12-2004' '24-12-2004'
@ -54,13 +56,16 @@ class TestUtils(unittest.TestCase):
('2012-05-14T23:59:59.000004', ('2012-05-14T23:59:59.000004',
datetime.datetime(2012, 5, 14, 23, 59, 59, 4)), datetime.datetime(2012, 5, 14, 23, 59, 59, 4)),
('1856-07-10T01:02:03+00:00', ('1856-07-10T01:02:03+00:00',
datetime.datetime(1856, 7, 10, 1, 2, 3, 0, pytz.UTC)), datetime.datetime(1856, 7, 10, 1, 2, 3, 0,
datetime.timezone.utc)),
('1856-07-10T01:02:03+23:59', ('1856-07-10T01:02:03+23:59',
datetime.datetime(1856, 7, 10, 1, 2, 3, 0, datetime.datetime(
pytz.FixedOffset(1439))), 1856, 7, 10, 1, 2, 3, 0,
datetime.timezone(datetime.timedelta(minutes=1439)))),
('1856-07-10T01:02:03-23:59', ('1856-07-10T01:02:03-23:59',
datetime.datetime(1856, 7, 10, 1, 2, 3, 0, datetime.datetime(
pytz.FixedOffset(-1439))), 1856, 7, 10, 1, 2, 3, 0,
datetime.timezone(datetime.timedelta(minutes=-1439)))),
] ]
ill_formatted_datetimes = [ ill_formatted_datetimes = [
'24-32-2004', '24-32-2004',

View File

@ -2,7 +2,6 @@ import builtins
import datetime import datetime
import decimal import decimal
from http import client as http_client from http import client as http_client
import pytz
import re import re
try: try:
@ -91,14 +90,15 @@ def parse_isodatetime(value):
def _parse_tzparts(parts): def _parse_tzparts(parts):
if 'tz_z' in parts and parts['tz_z'] == 'Z': if 'tz_z' in parts and parts['tz_z'] == 'Z':
return pytz.UTC return datetime.timezone.utc
if 'tz_min' not in parts or not parts['tz_min']: if 'tz_min' not in parts or not parts['tz_min']:
return None return None
tz_minute_offset = (int(parts['tz_hour']) * 60 + int(parts['tz_min'])) tz_minute_offset = (int(parts['tz_hour']) * 60 + int(parts['tz_min']))
tz_multiplier = -1 if parts['tz_sign'] == '-' else 1 tz_multiplier = -1 if parts['tz_sign'] == '-' else 1
minutes = tz_multiplier * tz_minute_offset
return pytz.FixedOffset(tz_multiplier * tz_minute_offset) return datetime.timezone(datetime.timedelta(minutes=minutes))
def is_valid_code(code_value): def is_valid_code(code_value):