Fixed #2460 -- JSON serializer now correctly handles datetime objects. Thanks, siniy and jyrki.pulliainen@gmail.com.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3501 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2006-07-31 14:59:53 +00:00
parent f6fbdf575a
commit 2e598fb571
1 changed files with 3 additions and 3 deletions

View File

@ -41,11 +41,11 @@ class DateTimeAwareJSONEncoder(simplejson.JSONEncoder):
TIME_FORMAT = "%H:%M:%S" TIME_FORMAT = "%H:%M:%S"
def default(self, o): def default(self, o):
if isinstance(o, datetime.date): if isinstance(o, datetime.datetime):
return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
elif isinstance(o, datetime.date):
return o.strftime(self.DATE_FORMAT) return o.strftime(self.DATE_FORMAT)
elif isinstance(o, datetime.time): elif isinstance(o, datetime.time):
return o.strftime(self.TIME_FORMAT) return o.strftime(self.TIME_FORMAT)
elif isinstance(o, datetime.datetime):
return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
else: else:
return super(self, DateTimeAwareJSONEncoder).default(o) return super(self, DateTimeAwareJSONEncoder).default(o)