Skip to content

Commit a7455bc

Browse files
format dates as ISO8601 (#1057)
* format dates as ISO8601 format dates as ISO8601 - currently works for datetimes, but not dates. Follow up to #18 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test_jsonutil.py * Update jsonutil.py * Update test_jsonutil.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test_jsonutil.py * fix date test Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1239e95 commit a7455bc

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

ipykernel/jsonutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import re
99
import types
1010
from binascii import b2a_base64
11-
from datetime import datetime
11+
from datetime import date, datetime
1212

1313
from jupyter_client._version import version_info as jupyter_client_version
1414

@@ -155,7 +155,7 @@ def json_clean(obj): # pragma: no cover
155155
for k, v in obj.items():
156156
out[str(k)] = json_clean(v)
157157
return out
158-
if isinstance(obj, datetime):
158+
if isinstance(obj, datetime) or isinstance(obj, date):
159159
return obj.strftime(ISO8601)
160160

161161
# we don't understand it, it's probably an unserializable object

ipykernel/tests/test_jsonutil.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import numbers
88
from binascii import a2b_base64
9-
from datetime import datetime
9+
from datetime import date, datetime
1010

1111
import pytest
1212
from jupyter_client._version import version_info as jupyter_client_version
@@ -54,6 +54,7 @@ def test():
5454
((x for x in range(3)), [0, 1, 2]),
5555
(iter([1, 2]), [1, 2]),
5656
(datetime(1991, 7, 3, 12, 00), "1991-07-03T12:00:00.000000"),
57+
(date(1991, 7, 3), "1991-07-03T00:00:00.000000"),
5758
(MyFloat(), 3.14),
5859
(MyInt(), 389),
5960
]

0 commit comments

Comments
 (0)