Commit e29ad1e7 by Carlton Gibson Committed by Carlton Gibson

JSONEncoder: Don’t strip microseconds from `time`

Closes #4749.

This is the matching commit to the fix for `datetime` in #4256
parent ea894cd9
...@@ -37,8 +37,6 @@ class JSONEncoder(json.JSONEncoder): ...@@ -37,8 +37,6 @@ class JSONEncoder(json.JSONEncoder):
if timezone and timezone.is_aware(obj): if timezone and timezone.is_aware(obj):
raise ValueError("JSON can't represent timezone-aware times.") raise ValueError("JSON can't represent timezone-aware times.")
representation = obj.isoformat() representation = obj.isoformat()
if obj.microsecond:
representation = representation[:12]
return representation return representation
elif isinstance(obj, datetime.timedelta): elif isinstance(obj, datetime.timedelta):
return six.text_type(total_seconds(obj)) return six.text_type(total_seconds(obj))
......
...@@ -44,7 +44,7 @@ class JSONEncoderTests(TestCase): ...@@ -44,7 +44,7 @@ class JSONEncoderTests(TestCase):
Tests encoding a timezone Tests encoding a timezone
""" """
current_time = datetime.now().time() current_time = datetime.now().time()
assert self.encoder.default(current_time) == current_time.isoformat()[:12] assert self.encoder.default(current_time) == current_time.isoformat()
def test_encode_time_tz(self): def test_encode_time_tz(self):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment