| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Fix :mod:`time` functions returning a negative year or failing to accept | ||
| their own output for large timestamps on platforms that support them. Avoid | ||
| reporting an incorrect year in errors raised by :mod:`datetime` for those | ||
| timestamps. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| Expand Up | @@ -487,7 +487,7 @@ tmtotuple(time_module_state *state, struct tm *p | |||||||
| #define SET(INDEX, VAL) \ | ||||||||
| SET_ITEM((INDEX), PyLong_FromLong((long) (VAL))) | ||||||||
|
|
||||||||
| SET(0, p->tm_year + 1900); | ||||||||
| SET_ITEM(0, PyLong_FromLongLong((long long)p->tm_year + 1900)); | ||||||||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis fixes the forward direction, but gettmarg() still reads the year into a C int: Lines 908 to 910 in e60a9da
We should preserve the round trip.
Sorry, something went wrong.
JelleZijlstra reacted with thumbs up emoji
All reactions
|
||||||||
| SET(1, p->tm_mon + 1); /* Want January == 1 */ | ||||||||
| SET(2, p->tm_mday); | ||||||||
| SET(3, p->tm_hour); | ||||||||
| Expand Down Expand Up | @@ -629,7 +629,7 @@ static int | |||||||
| gettmarg(time_module_state *state, PyObject *args, | ||||||||
| struct tm *p, const char *format) | ||||||||
| { | ||||||||
| int y; | ||||||||
| long long y; | ||||||||
|
|
||||||||
| memset((void *) p, '\0', sizeof(struct tm)); | ||||||||
|
|
||||||||
| Expand All | @@ -645,12 +645,12 @@ gettmarg(time_module_state *state, PyObject *args, | |||||||
| &p->tm_wday, &p->tm_yday, &p->tm_isdst)) | ||||||||
| return 0; | ||||||||
|
|
||||||||
| if (y < INT_MIN + 1900) { | ||||||||
| if (y < (long long)INT_MIN + 1900 || y > (long long)INT_MAX + 1900) { | ||||||||
| PyErr_SetString(PyExc_OverflowError, "year out of range"); | ||||||||
| return 0; | ||||||||
| } | ||||||||
|
|
||||||||
| p->tm_year = y - 1900; | ||||||||
| p->tm_year = (int)(y - 1900); | ||||||||
| p->tm_mon--; | ||||||||
| p->tm_wday = (p->tm_wday + 1) % 7; | ||||||||
| p->tm_yday--; | ||||||||
| Expand Down Expand Up | @@ -906,7 +906,7 @@ time_strftime(PyObject *module, PyObject *args) | |||||||
| return NULL; | ||||||||
| } | ||||||||
| else if (!gettmarg(state, tup, &buf, | ||||||||
| "iiiiiiiii;strftime(): illegal time tuple argument") || | ||||||||
| "Liiiiiiii;strftime(): illegal time tuple argument") || | ||||||||
| !checktm(&buf)) | ||||||||
| { | ||||||||
| return NULL; | ||||||||
| Expand All | @@ -918,7 +918,7 @@ time_strftime(PyObject *module, PyObject *args) | |||||||
| // physical devices (#123017). | ||||||||
| #if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX) \ | ||||||||
| || defined(__VXWORKS__) || defined(__ANDROID__) | ||||||||
| if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) { | ||||||||
| if (buf.tm_year < 1 - 1900 || buf.tm_year > 9999 - 1900) { | ||||||||
| PyErr_SetString(PyExc_ValueError, | ||||||||
| "strftime() requires year in [1; 9999]"); | ||||||||
| return NULL; | ||||||||
| Expand Down Expand Up | @@ -1041,12 +1041,12 @@ _asctime(struct tm *timeptr) | |||||||
| "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | ||||||||
| }; | ||||||||
| return PyUnicode_FromFormat( | ||||||||
| "%s %s%3d %.2d:%.2d:%.2d %d", | ||||||||
| "%s %s%3d %.2d:%.2d:%.2d %lld", | ||||||||
| wday_name[timeptr->tm_wday], | ||||||||
| mon_name[timeptr->tm_mon], | ||||||||
| timeptr->tm_mday, timeptr->tm_hour, | ||||||||
| timeptr->tm_min, timeptr->tm_sec, | ||||||||
| 1900 + timeptr->tm_year); | ||||||||
| (long long)timeptr->tm_year + 1900); | ||||||||
| } | ||||||||
|
|
||||||||
| /*[clinic input] | ||||||||
| Expand Down Expand Up | @@ -1074,7 +1074,7 @@ time_asctime_impl(PyObject *module, PyObject *tup) | |||||||
| return NULL; | ||||||||
| } | ||||||||
| else if (!gettmarg(state, tup, &buf, | ||||||||
| "iiiiiiiii;asctime(): illegal time tuple argument") || | ||||||||
| "Liiiiiiii;asctime(): illegal time tuple argument") || | ||||||||
| !checktm(&buf)) | ||||||||
| { | ||||||||
| return NULL; | ||||||||
| Expand Down Expand Up | @@ -1130,7 +1130,7 @@ time_mktime(PyObject *module, PyObject *tm_tuple) | |||||||
|
|
||||||||
| time_module_state *state = get_time_state(module); | ||||||||
| if (!gettmarg(state, tm_tuple, &tm, | ||||||||
| "iiiiiiiii;mktime(): illegal time tuple argument")) | ||||||||
| "Liiiiiiii;mktime(): illegal time tuple argument")) | ||||||||
| { | ||||||||
| return NULL; | ||||||||
| } | ||||||||
| Expand Down | ||||||||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWon't datetime have the same issue?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityFixed that too
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.