summaryrefslogtreecommitdiff
path: root/Lib/datetime.py
diff options
context:
space:
mode:
authorAmmar Askar <ammar_askar@hotmail.com>2018-07-25 09:54:58 -0700
committerAlexander Belopolsky <abalkin@users.noreply.github.com>2018-07-25 12:54:58 -0400
commit96d1e69a12ed8ab80203277e1abdaf573457a964 (patch)
treee6cdbe9b8eec222ba25cf313c0ba4361f2dd68d9 /Lib/datetime.py
parent74102c9a5f2327c4fc47feefa072854a53551d1f (diff)
downloadcpython-git-96d1e69a12ed8ab80203277e1abdaf573457a964.tar.gz
bpo-29097: Forego fold detection on windows for low timestamp values (GH-2385)
On Windows, passing a negative value to local results in an OSError because localtime_s on Windows does not support negative timestamps. Unfortunately this means that fold detection for timestamps between 0 and max_fold_seconds will result in this OSError since we subtract max_fold_seconds from the timestamp to detect a fold. However, since we know there haven't been any folds in the interval [0, max_fold_seconds) in any timezone, we can hackily just forego fold detection for this time range on Windows.
Diffstat (limited to 'Lib/datetime.py')
-rw-r--r--Lib/datetime.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py
index 5e922c80b0..cff92033c4 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -6,6 +6,7 @@ time zone and DST data sources.
import time as _time
import math as _math
+import sys
def _cmp(x, y):
return 0 if x == y else 1 if x > y else -1
@@ -1572,6 +1573,14 @@ class datetime(date):
# 23 hours at 1969-09-30 13:00:00 in Kwajalein.
# Let's probe 24 hours in the past to detect a transition:
max_fold_seconds = 24 * 3600
+
+ # On Windows localtime_s throws an OSError for negative values,
+ # thus we can't perform fold detection for values of time less
+ # than the max time fold. See comments in _datetimemodule's
+ # version of this method for more details.
+ if t < max_fold_seconds and sys.platform.startswith("win"):
+ return result
+
y, m, d, hh, mm, ss = converter(t - max_fold_seconds)[:6]
probe1 = cls(y, m, d, hh, mm, ss, us, tz)
trans = result - probe1 - timedelta(0, max_fold_seconds)