Message154621
| Author |
Martin.Morrison |
| Recipients |
Martin.Morrison |
| Date |
2012年02月29日.11:57:47 |
| SpamBayes Score |
4.097595e-10 |
| Marked as misclassified |
No |
| Message-id |
<1330516668.55.0.549591415618.issue14157@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
time.strptime without a year fails on Feb 29 with:
>>> time.strptime("Feb 29", "%b %d")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/_strptime.py", line 454, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.6/_strptime.py", line 440, in _strptime
datetime_date(year, 1, 1).toordinal() + 1
ValueError: day is out of range for month
This is due to the use of "1900" as the default year when parsing. It would be nice to have an optional "defaults" keyword argument to the strptime function that can be used to override the defaults, thus allowing leap year dates to be parsed without specifying the date.
(Note: the code in question attempted to set the year *after* the parse so that ultimately there is a valid struct_time, but since the parse never succeeds, this can't work). |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年02月29日 11:57:48 | Martin.Morrison | set | recipients:
+ Martin.Morrison |
| 2012年02月29日 11:57:48 | Martin.Morrison | set | messageid: <1330516668.55.0.549591415618.issue14157@psf.upfronthosting.co.za> |
| 2012年02月29日 11:57:47 | Martin.Morrison | link | issue14157 messages |
| 2012年02月29日 11:57:47 | Martin.Morrison | create |
|