Skip to content

Commit

Permalink
Correctly encode aware, non-UTC datetime objects
Browse files Browse the repository at this point in the history
http_date() requires timetuple in UTC, but JSONEncoder.default() was
passing a local timetuple instead.
  • Loading branch information
Eugene M. Kim committed Jun 14, 2017
1 parent d75d83d commit cc94b66
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion flask/json/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import io
import uuid
from datetime import date
from datetime import date, datetime
from flask.globals import current_app, request
from flask._compat import text_type, PY2

Expand Down Expand Up @@ -62,6 +62,8 @@ def default(self, o):
return list(iterable)
return JSONEncoder.default(self, o)
"""
if isinstance(o, datetime):
return http_date(o.utctimetuple())
if isinstance(o, date):
return http_date(o.timetuple())
if isinstance(o, uuid.UUID):
Expand Down

0 comments on commit cc94b66

Please sign in to comment.