diff options
author | Ngalim Siregar <ngalim.siregar@gmail.com> | 2019-08-09 14:22:16 (GMT) |
---|---|---|
committer | Paul Ganssle <pganssle@users.noreply.github.com> | 2019-08-09 14:22:16 (GMT) |
commit | 92c7e30adf5c81a54d6e5e555a6bdfaa60157a0d (patch) | |
tree | f7076888f795a4e3198ff4ca3ef189551891725b /Modules | |
parent | ed70a344b5fbddea85726ebc1964ee0cfdef9c40 (diff) | |
download | cpython-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 'Modules')
-rw-r--r-- | Modules/_datetimemodule.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index b55922c..6d28b3e 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1099,7 +1099,9 @@ new_timezone(PyObject *offset, PyObject *name) Py_INCREF(PyDateTime_TimeZone_UTC); return PyDateTime_TimeZone_UTC; } - if ((GET_TD_DAYS(offset) == -1 && GET_TD_SECONDS(offset) == 0) || + if ((GET_TD_DAYS(offset) == -1 && + GET_TD_SECONDS(offset) == 0 && + GET_TD_MICROSECONDS(offset) < 1) || GET_TD_DAYS(offset) < -1 || GET_TD_DAYS(offset) >= 1) { PyErr_Format(PyExc_ValueError, "offset must be a timedelta" " strictly between -timedelta(hours=24) and" @@ -1169,7 +1171,9 @@ call_tzinfo_method(PyObject *tzinfo, const char *name, PyObject *tzinfoarg) if (offset == Py_None || offset == NULL) return offset; if (PyDelta_Check(offset)) { - if ((GET_TD_DAYS(offset) == -1 && GET_TD_SECONDS(offset) == 0) || + if ((GET_TD_DAYS(offset) == -1 && + GET_TD_SECONDS(offset) == 0 && + GET_TD_MICROSECONDS(offset) < 1) || GET_TD_DAYS(offset) < -1 || GET_TD_DAYS(offset) >= 1) { Py_DECREF(offset); PyErr_Format(PyExc_ValueError, "offset must be a timedelta" @@ -6481,6 +6485,9 @@ PyInit__datetime(void) PyDateTime_TimeZone_UTC = x; CAPI.TimeZone_UTC = PyDateTime_TimeZone_UTC; + /* 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.*/ delta = new_delta(-1, 60, 0, 1); /* -23:59 */ if (delta == NULL) return NULL; |