Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit 6425c16

Browse files
author
Zakaria Zajac
authored
Merge pull request #32 from romain-dartigues/suggestions
Suggestions: second are lost in default date serialization + XML test broken
2 parents 679474d + b789183 commit 6425c16

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/pythonjsonlogger/jsonlogger.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,8 @@ def __init__(self, *args, **kwargs):
6767
if not self.json_encoder and not self.json_default:
6868
def _default_json_handler(obj):
6969
'''Prints dates in ISO format'''
70-
if isinstance(obj, datetime.datetime):
71-
if obj.year < 1900:
72-
# strftime do not work with date < 1900
73-
return obj.isoformat()
74-
return obj.strftime(self.datefmt or '%Y-%m-%dT%H:%M')
75-
elif isinstance(obj, datetime.date):
70+
if isinstance(obj, (datetime.date, datetime.time)):
7671
return obj.isoformat()
77-
elif isinstance(obj, datetime.time):
78-
return obj.strftime('%H:%M')
7972
elif istraceback(obj):
8073
tb = ''.join(traceback.format_tb(obj))
8174
return tb.strip()

tests/tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ def testJsonDefaultEncoder(self):
123123
"otherdatetimeagain": datetime.datetime(1900, 1, 1)}
124124
self.logger.info(msg)
125125
logJson = json.loads(self.buffer.getvalue())
126-
self.assertEqual(logJson.get("adate"), "1999-12-31T23:59")
126+
self.assertEqual(logJson.get("adate"), "1999-12-31T23:59:00")
127127
self.assertEqual(logJson.get("otherdate"), "1789-07-14")
128128
self.assertEqual(logJson.get("otherdatetime"), "1789-07-14T23:59:00")
129129
self.assertEqual(logJson.get("otherdatetimeagain"),
130-
"1900-01-01T00:00")
130+
"1900-01-01T00:00:00")
131131

132132
def testJsonCustomDefault(self):
133133
def custom(o):
@@ -175,7 +175,7 @@ def testExcInfo(self):
175175
if len(sys.argv[1:]) > 0:
176176
if sys.argv[1] == 'xml':
177177
testSuite = unittest.TestLoader().loadTestsFromTestCase(
178-
testJsonLogger)
178+
TestJsonLogger)
179179
xmlrunner.XMLTestRunner(output='reports').run(testSuite)
180180
else:
181181
unittest.main()

0 commit comments

Comments
 (0)