esnme/ultrajson — pull request #153 by ngandhy (2014-11-07 22:54:02+00:00)
Title: datetime -> epoch ignores timezone re#119

This is a new pull request based on the conversation of issue #119
https://github.com/esnme/ultrajson/issues/119

"Hi. First, thanks for ultrajson and ultramysql!

Problem

When given a UTC time and a timezoned version of the same value (e.g America/New_York) they give different values when "jsonified". They should give you the same epoch value.

Repro:

import datetime, pytz, ujson
a = datetime.datetime.utcfromtimestamp(1383647400)
a = a.replace(tzinfo=pytz.utc)
b = a.astimezone(pytz.timezone('America/New_York'))
c = b.astimezone(pytz.utc)
d = {'a':a, 'b':b, 'c':c}
ujson.dumps(d)

Result: (Notice 'b' is wrong)

'{"a":1383647400,"c":1383647400,"b":1383629400}'

Should be:

'{"a":1383647400,"c":1383647400,"b":1383647400}'
"