Skip to content

Commit

Permalink
Fixes #30 Dates in far future and really old fails on *nix machines
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Boyce authored and benoitc committed Aug 5, 2010
1 parent e7a7cba commit 530d240
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions couchdbkit/schema/properties.py
Expand Up @@ -299,8 +299,7 @@ def to_python(self, value):
try:
value = value.split('.', 1)[0] # strip out microseconds
value = value.rstrip('Z') # remove timezone separator
timestamp = timegm(time.strptime(value, '%Y-%m-%dT%H:%M:%S'))
value = datetime.datetime.utcfromtimestamp(timestamp)
value = datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S')
except ValueError, e:
raise ValueError('Invalid ISO date/time %r' % value)
return value
Expand Down
17 changes: 13 additions & 4 deletions tests/test_schema.py
Expand Up @@ -573,10 +573,19 @@ def ftest():
test.field = "essai"

self.assertRaises(BadValueError, ftest)
test.field = datetime.datetime(2008, 11, 10, 8, 0, 0)
self.assert_(test._doc['field'] == "2008-11-10T08:00:00Z")
value = test.field
self.assert_(isinstance(value, datetime.datetime))
test_dates = [
([2008, 11, 10, 8, 0, 0], "2008-11-10T08:00:00Z"),
([9999, 12, 31, 23, 59, 59], '9999-12-31T23:59:59Z'),
([0001, 1, 1, 0, 0, 1], '0001-01-01T00:00:01Z'),

]
for date, date_str in test_dates:
test.field = datetime.datetime(*date)
self.assertEquals(test._doc['field'], date_str)
value = test.field
self.assert_(isinstance(value, datetime.datetime))



def testDateProperty(self):
class Test(Document):
Expand Down

0 comments on commit 530d240

Please sign in to comment.