Permalink
Browse files

Fixes #30 Dates in far future and really old fails on *nix machines

  • Loading branch information...
Alan Boyce benoitc
Alan Boyce authored and benoitc committed Aug 1, 2010
1 parent e7a7cba commit 530d2403681b39b315a590fd4e5f2b4e5cb18d61
Showing with 14 additions and 6 deletions.
  1. +1 −2 couchdbkit/schema/properties.py
  2. +13 −4 tests/test_schema.py
@@ -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
View
@@ -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):

0 comments on commit 530d240

Please sign in to comment.