fix dates < 1900
This commit is contained in:
parent
f7e9605828
commit
1e65f3e478
2 changed files with 14 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
import datetime
|
||||
from django.utils import datetime_safe
|
||||
from django.http import HttpResponse, Http404
|
||||
try:
|
||||
import simplejson as json
|
||||
|
|
@ -18,7 +19,10 @@ def json_response(data=None, status=200, text='ok'):
|
|||
return {'status': {'code': status, 'text': text}, 'data': data}
|
||||
|
||||
def _to_json(python_object):
|
||||
if isinstance(python_object, datetime.datetime):
|
||||
if isinstance(python_object, datetime.datetime):
|
||||
value = datetime_safe.datetime.fromordinal(python_object.toordinal())
|
||||
return value.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
if isinstance(python_object, datetime_safe.datetime):
|
||||
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue