Timezone aware datetime fix.
This commit is contained in:
@@ -214,8 +214,12 @@ class DateTime(Column):
|
|||||||
value = super(DateTime, self).to_database(value)
|
value = super(DateTime, self).to_database(value)
|
||||||
if not isinstance(value, datetime):
|
if not isinstance(value, datetime):
|
||||||
raise ValidationError("'{}' is not a datetime object".format(value))
|
raise ValidationError("'{}' is not a datetime object".format(value))
|
||||||
epoch = datetime(1970, 1, 1)
|
epoch = datetime(1970, 1, 1, tzinfo=value.tzinfo)
|
||||||
return long((value - epoch).total_seconds() * 1000)
|
offset = 0
|
||||||
|
if epoch.tzinfo:
|
||||||
|
offset_delta = epoch.tzinfo.utcoffset(epoch)
|
||||||
|
offset = offset_delta.days*24*3600 + offset_delta.seconds
|
||||||
|
return long(((value - epoch).total_seconds() - offset) * 1000)
|
||||||
|
|
||||||
|
|
||||||
class Date(Column):
|
class Date(Column):
|
||||||
|
|||||||
Reference in New Issue
Block a user