Skip to content

Commit

Permalink
Merge branch 'ngandhy-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahaja committed Jan 18, 2016
2 parents 74ee682 + 4da6667 commit 1c21733
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python/objToJSON.c
Expand Up @@ -182,9 +182,14 @@ static void *PyRawJSONToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, si
static void *PyDateTimeToINT64(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
PyObject *obj = (PyObject *) _obj;
PyObject *date, *ord;
PyObject *date, *ord, *utcoffset;
int y, m, d, h, mn, s, days;

utcoffset = PyObject_CallMethod(obj, "utcoffset", NULL);
if(utcoffset != Py_None){
obj = PyNumber_Subtract(obj, utcoffset);
}

y = PyDateTime_GET_YEAR(obj);
m = PyDateTime_GET_MONTH(obj);
d = PyDateTime_GET_DAY(obj);
Expand Down
17 changes: 17 additions & 0 deletions tests/tests.py
Expand Up @@ -10,6 +10,7 @@
import json
import math
import time
import pytz
if six.PY2:
import unittest2 as unittest
else:
Expand Down Expand Up @@ -361,6 +362,22 @@ def test_encodeDateConversion(self):
self.assertEqual(int(expected), json.loads(output))
self.assertEqual(int(expected), ujson.decode(output))

def test_encodeWithTimezone(self):
start_timestamp = 1383647400
a = datetime.datetime.utcfromtimestamp(start_timestamp)

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}
json_string = ujson.encode(d)
json_dict = ujson.decode(json_string)

self.assertEqual(json_dict.get('a'),start_timestamp)
self.assertEqual(json_dict.get('b'),start_timestamp)
self.assertEqual(json_dict.get('c'),start_timestamp)

def test_encodeToUTF8(self):
input = b"\xe6\x97\xa5\xd1\x88"
if six.PY3:
Expand Down

0 comments on commit 1c21733

Please sign in to comment.