diff options
author | Ammar Askar <ammar_askar@hotmail.com> | 2018-07-27 14:59:27 (GMT) |
---|---|---|
committer | Alexander Belopolsky <abalkin@users.noreply.github.com> | 2018-07-27 14:59:27 (GMT) |
commit | 6ea8a3a0ebf840ca57b6dba9cad26fbb0ddaa5d4 (patch) | |
tree | 95cbb72d7f8bd24ed85aa777bfda2e7f157ae397 /Modules | |
parent | 777cdd94b9bebd5b22df0fc293aa078d5537b988 (diff) | |
download | cpython-6ea8a3a0ebf840ca57b6dba9cad26fbb0ddaa5d4.zip cpython-6ea8a3a0ebf840ca57b6dba9cad26fbb0ddaa5d4.tar.gz cpython-6ea8a3a0ebf840ca57b6dba9cad26fbb0ddaa5d4.tar.bz2 |
[3.6] bpo-29097: Forego fold detection on windows for low timestamp values (GH-2385) (GH-8498)
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..
(cherry picked from commit 96d1e69a12ed8ab80203277e1abdaf573457a964)
Co-authored-by: Ammar Askar <ammar_askar@hotmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_datetimemodule.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 148bd80..64928b1 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4309,7 +4309,22 @@ datetime_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, int us, second = Py_MIN(59, tm.tm_sec); /* local timezone requires to compute fold */ - if (tzinfo == Py_None && f == _PyTime_localtime) { + if (tzinfo == Py_None && f == _PyTime_localtime + /* 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 time values between + * 0 and max_fold_seconds will result in an identical + * error since we subtract max_fold_seconds 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. + */ +#ifdef MS_WINDOWS + && (timet - max_fold_seconds > 0) +#endif + ) { long long probe_seconds, result_seconds, transition; result_seconds = utc_to_seconds(year, month, day, |