mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-19 21:11:04 +03:00
JSONEncoder: Don’t strip microseconds from time
Closes #4749. This is the matching commit to the fix for `datetime` in #4256
This commit is contained in:
parent
ea894cd90a
commit
e29ad1e7b3
|
@ -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):
|
||||||
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):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user