Skip to content

Commit cada556

Browse files
committed
Don't convert dates via timestamp (fixes #142).
1 parent 8473929 commit cada556

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

couchdb/mapping.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,7 @@ def _to_python(self, value):
483483
try:
484484
value = value.split('.', 1)[0] # strip out microseconds
485485
value = value.rstrip('Z') # remove timezone separator
486-
timestamp = timegm(strptime(value, '%Y-%m-%dT%H:%M:%S'))
487-
value = datetime.utcfromtimestamp(timestamp)
486+
value = datetime(*strptime(value, '%Y-%m-%dT%H:%M:%S')[:6])
488487
except ValueError:
489488
raise ValueError('Invalid ISO date/time %r' % value)
490489
return value

couchdb/tests/mapping.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class Post(mapping.Document):
8080
post.store(self.db)
8181
self.assertEqual(len(list(self.db.view('_all_docs'))), 1)
8282

83+
def test_old_datetime(self):
84+
dt = mapping.DateTimeField()
85+
assert dt._to_python(u'1880-01-01T00:00:00Z')
8386

8487
class ListFieldTestCase(testutil.TempDatabaseMixin, unittest.TestCase):
8588

0 commit comments

Comments
 (0)