mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #26656 -- Added duration (timedelta) support to DjangoJSONEncoder.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import json
|
||||
import re
|
||||
@@ -302,3 +303,15 @@ class DjangoJSONEncoderTests(SimpleTestCase):
|
||||
json.dumps({'lang': ugettext_lazy("French")}, cls=DjangoJSONEncoder),
|
||||
'{"lang": "Fran\\u00e7ais"}'
|
||||
)
|
||||
|
||||
def test_timedelta(self):
|
||||
duration = datetime.timedelta(days=1, hours=2, seconds=3)
|
||||
self.assertEqual(
|
||||
json.dumps({'duration': duration}, cls=DjangoJSONEncoder),
|
||||
'{"duration": "P1DT02H00M03S"}'
|
||||
)
|
||||
duration = datetime.timedelta(0)
|
||||
self.assertEqual(
|
||||
json.dumps({'duration': duration}, cls=DjangoJSONEncoder),
|
||||
'{"duration": "P0DT00H00M00S"}'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user