Skip to content

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

@astralblue

Description

@astralblue

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions