Skip to content

Commit

Permalink
format dates as ISO8601 (#1057)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
GRcharles and pre-commit-ci[bot] committed Dec 14, 2022
1 parent 1239e95 commit a7455bc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ipykernel/jsonutil.py
Expand Up @@ -8,7 +8,7 @@
import re
import types
from binascii import b2a_base64
from datetime import datetime
from datetime import date, datetime

from jupyter_client._version import version_info as jupyter_client_version

Expand Down Expand Up @@ -155,7 +155,7 @@ def json_clean(obj): # pragma: no cover
for k, v in obj.items():
out[str(k)] = json_clean(v)
return out
if isinstance(obj, datetime):
if isinstance(obj, datetime) or isinstance(obj, date):
return obj.strftime(ISO8601)

# we don't understand it, it's probably an unserializable object
Expand Down
3 changes: 2 additions & 1 deletion ipykernel/tests/test_jsonutil.py
Expand Up @@ -6,7 +6,7 @@
import json
import numbers
from binascii import a2b_base64
from datetime import datetime
from datetime import date, datetime

import pytest
from jupyter_client._version import version_info as jupyter_client_version
Expand Down Expand Up @@ -54,6 +54,7 @@ def test():
((x for x in range(3)), [0, 1, 2]),
(iter([1, 2]), [1, 2]),
(datetime(1991, 7, 3, 12, 00), "1991-07-03T12:00:00.000000"),
(date(1991, 7, 3), "1991-07-03T00:00:00.000000"),
(MyFloat(), 3.14),
(MyInt(), 389),
]
Expand Down

0 comments on commit a7455bc

Please sign in to comment.