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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time.strptime too strict? should it assume current year? #46480
Comments
Some common python utilities had problems on Feb 29 this year when >>> time.strptime('Feb 29', '%b %d')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/_strptime.py", line 425, in strptime
julian = datetime_date(year, month, day).toordinal() - \
ValueError: day is out of range for month This is apparently because python assumes the year is 1900 unless it Applications can work around this by always adding a year and a %Y to But not all date manipulating applications care about years. In this http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468382 Should the year default to 1900 (the equivalent of what the much more I do believe this was a valid bug in fail2ban as assuming the current Python's strptime is much more strict than C strptime (glibc's C here's a C test case to play with its behavior: #include <assert.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[]) {
unsigned long ret, parsed;
assert(argc == 2);
struct tm tm = { 0 };
ret = strptime(argv[1], "%b %d", &tm);
parsed = ret - (unsigned long)(argv[1]);
printf("ret 0x%x parsed %d tm_mon %d tm_mday %d tm_year %d\n",
ret, parsed,
tm.tm_mon, tm.tm_mday, tm.tm_year);
} % ./foo 'Feb 28' |
The documentation already mentions that the default values when |
Here is a patch, hope it'll make it to 2.6 |
Applying the _strptime.diff patch broke the _strptime |
After having thought about this I have decided I am going to stick with |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: