Issue1777412
Created on 2007-08-20 03:36 by benno, last changed 2008-05-10 21:04 by skip.montanaro.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
strftime-pre-1900.patch
|
davidfraser,
2008-05-10 15:35
|
patch to use strftime directly from datetime instead of going through the time module, and remove the pre-1900 restriction |
|
|
| msg55156 (view) |
Author: Benno Rice (benno) |
Date: 2007-08-20 03:36 |
|
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.date(1876, 2, 3).strftime('%Y-%m-%d')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: year=1876 is before 1900; the datetime strftime() methods require year >= 1900
Apparently this is due to platform-specific weirdnesses in implementations of strftime. It is still very annoying however. Perhaps a good implementation of strftime could be found and incorporated into Python itself?
|
| msg55157 (view) |
Author: Martin v. Löwis (loewis) |
Date: 2007-08-21 08:15 |
|
This is not a bug report, but a feature request. Python works correctly as-is.
|
| msg66535 (view) |
Author: David Fraser (davidfraser) |
Date: 2008-05-10 15:35 |
|
I have a patch for this, but I don't know which platforms have the
problem. On Linux, strftime seems to work fine. Attaching the patch as a
work in progress...
|
| msg66541 (view) |
Author: Skip Montanaro (skip.montanaro) |
Date: 2008-05-10 16:45 |
|
Which version of Python are you using? I could have sworn we just fixed
this problem in CVS a couple weeks ago.
|
| msg66584 (view) |
Author: David Fraser (davidfraser) |
Date: 2008-05-10 20:41 |
|
> Which version of Python are you using? I could have sworn we just fixed
this problem in CVS a couple weeks ago.
This was on the latest Python 2.6 svn... but looking at the py3k branch
with viewsvn the code is definitely still there too...
The relevant commit seems to be r30224 in 2002:
> I give up: unless I write my own strftime by hand, datetime just can't
be trusted with years before 1900, so now we raise ValueError if a date or
datetime or datetimetz .strftime() method is called with a year before
1900.
Of course I'm not dealing with any of this in the attached patch, but
then I don't have the information on which platforms have the problem...
but according to the above writing strftime by hand would be the only
solution...
|
| msg66585 (view) |
Author: Skip Montanaro (skip.montanaro) |
Date: 2008-05-10 21:04 |
|
Ah, I remember now. It was a special case for xmlrpclib to allow
its Date objects to operate before 1900.
|
|
| Date |
User |
Action |
Args |
| 2008-05-10 21:04:51 | skip.montanaro | set | messages:
+ msg66585 |
| 2008-05-10 20:41:48 | davidfraser | set | messages:
+ msg66584 |
| 2008-05-10 16:45:27 | skip.montanaro | set | nosy:
+ skip.montanaro messages:
+ msg66541 |
| 2008-05-10 15:35:25 | davidfraser | set | files:
+ strftime-pre-1900.patch nosy:
+ davidfraser messages:
+ msg66535 keywords:
+ patch |
| 2007-08-20 03:36:14 | benno | create | |
|