File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ def format(self, entry):
4747 elif isinstance (value , journal .Monotonic ):
4848 log .debug ("Converting %s" , field )
4949 value = value .timestamp .microseconds
50+ elif isinstance (value , datetime .timedelta ):
51+ log .debug ("Converting %s" , field )
52+ value = value .total_seconds () * 1000000 # microseconds
5053 elif isinstance (value , bytes ):
5154 log .debug ("Converting %s" , field )
5255 try :
Original file line number Diff line number Diff line change @@ -66,6 +66,20 @@ def test_monotonic(self):
6666 out = json .loads (formatter .format (entry ))
6767 assert out ['__MONOTONIC_TIMESTAMP' ] == us
6868
69+ def test_timedelta (self ):
70+ """
71+ Should be in microseconds
72+ """
73+
74+ sec = 1
75+ us = 700
76+ mono_ts = timedelta (0 , sec , us )
77+ entry = {'__MONOTONIC_TIMESTAMP' : mono_ts }
78+ formatter = get_formatter ('json' )
79+ out = json .loads (formatter .format (entry ))
80+ diff = out ['__MONOTONIC_TIMESTAMP' ] - (sec * 1000000 + us )
81+ assert diff < 0.001
82+
6983 @pytest .mark .parametrize (('bdata' , 'brepr' ), [
7084 (b'abc' , 'abc' ),
7185 (b'\x82 \xac ' , [0x82 , 0xac ]),
You can’t perform that action at this time.
0 commit comments