Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-80620: Support negative values infromtimestamp
on Windows using 0 +timedelta
#134461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes from1 commit
6704876
a3e5749
7453c3c
15c5520
329db66
34c999f
0dd521f
44bcfd9
e675d63
02082f7
cb2f911
057dd79
5d9db9d
77a8b11
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1037,7 +1037,7 @@ def fromtimestamp(cls, t): | ||
"Construct a date from a POSIX timestamp (like time.time())." | ||
if t is None: | ||
raise TypeError("'NoneType' object cannot be interpreted as an integer") | ||
if t < 0 andos.name == 'nt': | ||
# Windows converters throw an OSError for negative values. | ||
y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(0) | ||
result = cls(y, m, d) | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
@@ -1869,7 +1869,7 @@ def _fromtimestamp(cls, t, utc, tz): | ||
us += 1000000 | ||
converter = _time.gmtime if utc else _time.localtime | ||
if t < 0 andos.name == 'nt': | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
# Windows converters throw an OSError for negative values. | ||
y, m, d, hh, mm, ss, weekday, jday, dst = converter(0) | ||
result = cls(y, m, d, hh, mm, ss, 0, tz) | ||
@@ -1887,7 +1887,7 @@ def _fromtimestamp(cls, t, utc, tz): | ||
# 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 andos.name == 'nt': | ||
return result | ||
y, m, d, hh, mm, ss = converter(t - max_fold_seconds)[:6] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3267,9 +3267,17 @@ date_fromtimestamp(PyObject *cls, PyObject *obj) | ||
tm.tm_mon + 1, | ||
tm.tm_mday, | ||
cls); | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if (date == NULL) { | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return NULL; | ||
} | ||
PyObject *result = NULL; | ||
PyObject *delta = new_delta(0, (int)t, 0, normalize); | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if (delta == NULL) { | ||
goto error; | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
result = add_date_timedelta(PyDate_CAST(date), PyDelta_CAST(delta), negate); | ||
Py_XDECREF(delta); | ||
error: | ||
Py_XDECREF(date); | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return result; | ||
} | ||
@@ -5559,9 +5567,17 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, PyObject *timestamp, | ||
if (timet < 0) { | ||
int normalize = 1, factor = 1; | ||
PyObject *dt = datetime_from_timet_and_us(cls, f, 0, 0, tzinfo); | ||
if (dt == NULL) { | ||
return NULL; | ||
} | ||
PyObject *result = NULL; | ||
PyObject *delta = new_delta(0, (int)timet, us, normalize); | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if (delta == NULL) { | ||
goto error; | ||
} | ||
result = add_datetime_timedelta(PyDateTime_CAST(dt), PyDelta_CAST(delta), factor); | ||
Py_XDECREF(delta); | ||
error: | ||
Py_XDECREF(dt); | ||
return result; | ||
} | ||
Uh oh!
There was an error while loading.Please reload this page.