Skip to content

Commit 06d64fb

Browse files
authored
Merge pull request datalad#7598 from yarikoptic/bf-dtime
BF: tools/dtime to handle log line having non-increment timestamp
2 parents ffe92b7 + c9beb93 commit 06d64fb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tools/dtime

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ reg = re.compile('^\d{4}-\d{2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2},\d{1,3}')
1515
prevt = None
1616
maxl = 0
1717
prevl = None
18+
warned_negative = False
1819

1920
if len(sys.argv) <= 1:
2021
in_ = sys.stdin
@@ -30,7 +31,14 @@ for l in in_:
3031
t = datetime.strptime(l[:end], '%Y-%m-%d %H:%M:%S,%f')
3132
if prevt is not None:
3233
dt = t - prevt
33-
ms = dt.microseconds // 1000 + dt.seconds*1000
34+
secs = dt.total_seconds()
35+
# negative dt has very weird form of -1 day + huge number of seconds
36+
if secs < 0:
37+
if not warned_negative:
38+
sys.stderr.write(f"Negative delta of {secs} seconds detected. Might be due to threading etc\n")
39+
warned_negative = True
40+
41+
ms = secs * 1000
3442
dtstr = ("%5d" % ms if ms else ' 0')
3543

3644
maxl = max(maxl, len(dtstr))

0 commit comments

Comments
 (0)