mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue