mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-37642: Update acceptable offsets in timezone (GH-14878)
This fixes an inconsistency between the Python and C implementations of the datetime module. The pure python version of the code was not accepting offsets greater than 23:59 but less than 24:00. This is an accidental legacy of the original implementation, which was put in place before tzinfo allowed sub-minute time zone offsets. GH-14878
This commit is contained in:
parent
ed70a344b5
commit
92c7e30adf
5 changed files with 44 additions and 5 deletions
|
@ -388,6 +388,31 @@ class TestTimeZone(unittest.TestCase):
|
|||
tz_copy = copy.deepcopy(tz)
|
||||
self.assertIs(tz_copy, tz)
|
||||
|
||||
def test_offset_boundaries(self):
|
||||
# Test timedeltas close to the boundaries
|
||||
time_deltas = [
|
||||
timedelta(hours=23, minutes=59),
|
||||
timedelta(hours=23, minutes=59, seconds=59),
|
||||
timedelta(hours=23, minutes=59, seconds=59, microseconds=999999),
|
||||
]
|
||||
time_deltas.extend([-delta for delta in time_deltas])
|
||||
|
||||
for delta in time_deltas:
|
||||
with self.subTest(test_type='good', delta=delta):
|
||||
timezone(delta)
|
||||
|
||||
# Test timedeltas on and outside the boundaries
|
||||
bad_time_deltas = [
|
||||
timedelta(hours=24),
|
||||
timedelta(hours=24, microseconds=1),
|
||||
]
|
||||
bad_time_deltas.extend([-delta for delta in bad_time_deltas])
|
||||
|
||||
for delta in bad_time_deltas:
|
||||
with self.subTest(test_type='bad', delta=delta):
|
||||
with self.assertRaises(ValueError):
|
||||
timezone(delta)
|
||||
|
||||
|
||||
#############################################################################
|
||||
# Base class for testing a particular aspect of timedelta, time, date and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue