Skip to content

Commit e29ad1e

Browse files
carltongibsonCarlton Gibson
authored andcommitted
JSONEncoder: Don’t strip microseconds from time
Closes #4749. This is the matching commit to the fix for `datetime` in #4256
1 parent ea894cd commit e29ad1e

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

rest_framework/utils/encoders.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ def default(self, obj):
3737
if timezone and timezone.is_aware(obj):
3838
raise ValueError("JSON can't represent timezone-aware times.")
3939
representation = obj.isoformat()
40-
if obj.microsecond:
41-
representation = representation[:12]
4240
return representation
4341
elif isinstance(obj, datetime.timedelta):
4442
return six.text_type(total_seconds(obj))

tests/test_encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_encode_time(self):
4444
Tests encoding a timezone
4545
"""
4646
current_time = datetime.now().time()
47-
assert self.encoder.default(current_time) == current_time.isoformat()[:12]
47+
assert self.encoder.default(current_time) == current_time.isoformat()
4848

4949
def test_encode_time_tz(self):
5050
"""

0 commit comments

Comments
 (0)