summaryrefslogtreecommitdiffstats
path: root/Lib/datetime.py
diff options
context:
space:
mode:
authorNgalim Siregar <ngalim.siregar@gmail.com>2019-08-09 14:22:16 (GMT)
committerPaul Ganssle <pganssle@users.noreply.github.com>2019-08-09 14:22:16 (GMT)
commit92c7e30adf5c81a54d6e5e555a6bdfaa60157a0d (patch)
treef7076888f795a4e3198ff4ca3ef189551891725b /Lib/datetime.py
parented70a344b5fbddea85726ebc1964ee0cfdef9c40 (diff)
downloadcpython-92c7e30adf5c81a54d6e5e555a6bdfaa60157a0d.zip
cpython-92c7e30adf5c81a54d6e5e555a6bdfaa60157a0d.tar.gz
cpython-92c7e30adf5c81a54d6e5e555a6bdfaa60157a0d.tar.bz2
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
Diffstat (limited to 'Lib/datetime.py')
-rw-r--r--Lib/datetime.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py
index d4c7a1f..0adf1dd 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -2269,7 +2269,7 @@ class timezone(tzinfo):
raise TypeError("fromutc() argument must be a datetime instance"
" or None")
- _maxoffset = timedelta(hours=23, minutes=59)
+ _maxoffset = timedelta(hours=24, microseconds=-1)
_minoffset = -_maxoffset
@staticmethod
@@ -2293,8 +2293,11 @@ class timezone(tzinfo):
return f'UTC{sign}{hours:02d}:{minutes:02d}'
timezone.utc = timezone._create(timedelta(0))
-timezone.min = timezone._create(timezone._minoffset)
-timezone.max = timezone._create(timezone._maxoffset)
+# bpo-37642: These attributes are rounded to the nearest minute for backwards
+# compatibility, even though the constructor will accept a wider range of
+# values. This may change in the future.
+timezone.min = timezone._create(-timedelta(hours=23, minutes=59))
+timezone.max = timezone._create(timedelta(hours=23, minutes=59))
_EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)
# Some time zone algebra. For a datetime x, let