From 876b9c93e81980c6e9338dada1889197b9c397f6 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 22 Sep 2017 12:03:05 +0200 Subject: [PATCH] =?UTF-8?q?JSONEncoder:=20Don=E2=80=99t=20strip=20microsec?= =?UTF-8?q?onds=20from=20`time`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4749. This is the matching commit to the fix for `datetime` in #4256 --- rest_framework/utils/encoders.py | 2 -- tests/test_encoders.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py index 8896e4f2c..33dbb1bb4 100644 --- a/rest_framework/utils/encoders.py +++ b/rest_framework/utils/encoders.py @@ -37,8 +37,6 @@ class JSONEncoder(json.JSONEncoder): if timezone and timezone.is_aware(obj): raise ValueError("JSON can't represent timezone-aware times.") representation = obj.isoformat() - if obj.microsecond: - representation = representation[:12] return representation elif isinstance(obj, datetime.timedelta): return six.text_type(total_seconds(obj)) diff --git a/tests/test_encoders.py b/tests/test_encoders.py index 8f8694c47..27136df87 100644 --- a/tests/test_encoders.py +++ b/tests/test_encoders.py @@ -44,7 +44,7 @@ class JSONEncoderTests(TestCase): Tests encoding a timezone """ 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): """