jur9526 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

DateTimeField._to_python does not work on old dates #142

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. test = couchdb.mapping.DateTimeField()
2. test._to_python(u'1880-01-01T00:00:00Z') raises an exception
3.

What is the expected output? What do you see instead?
It should return a datetime.datetime object.
It raises ValueError: Invalid ISO date/time.

What version of the product are you using? On what operating system?
couchdb 0.7
python 2.6.4
mac os 10.5

Please provide any additional information below.
It is actually the call to datetime.utcfromtimestamp that is raising the 
exception ValueError:  timestamp out of range for platform time_t
Instead of:
                timestamp = timegm(strptime(value, '%Y-%m-%dT%H:%M:%S'))
                value = datetime.utcfromtimestamp(timestamp)
maybe use this?:
                value = datetime.strptime(value, '%Y-%m-%dT%H:%M:%S')

Original issue reported on code.google.com by megago...@gmail.com on 19 Jul 2010 at 9:18

GoogleCodeExporter commented 9 years ago
We can't use datetime.strptime() because we want to support 2.4 for now, but 
I've implemented a similar fix in rd837043825f0. Thanks for the bug and test 
case!

Original comment by djc.ochtman on 7 Aug 2010 at 2:33