Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONEncoder encodes aware datetime objects in non-UTC timezone incorrectly as being in GMT. #2372

Closed
astralblue opened this issue Jun 14, 2017 · 0 comments · Fixed by #2374
Closed

Comments

@astralblue
Copy link

flask.json.JSONEncoder() encodes aware datetime objects in non-UTC timezone incorrectly using local time tuple with GMT.

Expected Behavior

The following code segment should print "Sun, 01 Jan 2017 20:34:56 GMT" (12:34:56 PST8PDT is 20:34:56 GMT):

from datetime import datetime
from pytz import timezone
dt = timezone('PST8PDT').localize(datetime(2017, 1, 1, 12, 34, 56))

from flask.json import JSONEncoder
encoder = JSONEncoder()
print(encoder.encode(dt))

Actual Behavior

The preceding code segment prints "Sun, 01 Jan 2017 12:34:56 GMT" instead, that is, local timetuple() appended with GMT.

Environment

  • Python version: 3.5.3
  • Flask version: 0.12.2
  • Werkzeug version: 0.12.2
astralblue pushed a commit to astralblue/flask that referenced this issue Jun 14, 2017
test_encode_aware_datetime() fails for non-UTC timezones due to the bug.
astralblue pushed a commit to astralblue/flask that referenced this issue Jun 14, 2017
test_encode_aware_datetime() fails for non-UTC timezones due to the bug.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants