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

jsonify() silently strips timezone from datetime objects #2459

Closed
codl opened this issue Aug 31, 2017 · 1 comment
Closed

jsonify() silently strips timezone from datetime objects #2459

codl opened this issue Aug 31, 2017 · 1 comment

Comments

@codl
Copy link

codl commented Aug 31, 2017

Expected Behavior

When given a tz-aware datetime object, I would expect jsonify to either raise an exception (because there is no native representation of a datetime in json) or at least convert it to a string format while keeping the timezone intact

import flask
from datetime import datetime, timezone, timedelta

app = flask.Flask(__name__)

@app.route('/')
def index():
    tz = timezone(timedelta(hours=2))
    t = datetime(2017, 1, 1, 12, 0, 0, tzinfo=tz)
    return flask.jsonify(t)

with app.app_context():
    resp = app.test_client().get('/')
    print(resp.data)

Actual Behavior

The datetime object is converted to a RFC 1123 date string, ignoring the timezone entirely and assuming GMT

b'"Sun, 01 Jan 2017 12:00:00 GMT"\n'

Environment

  • Python version: 3.6
  • Flask version: 0.12.2
  • Werkzeug version: 0.12.2
@davidism
Copy link
Member

closed by #2374

@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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants