Skip to content

Commit 8d24b3c

Browse files
pierreluctghardbyte
authored andcommitted
Adding ms to ASC formatted date
1 parent c819526 commit 8d24b3c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

can/io/asc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class ASCWriter(BaseIOHandler, Listener):
131131
"""
132132

133133
FORMAT_MESSAGE = "{channel} {id:<15} Rx {dtype} {data}"
134-
FORMAT_DATE = "%a %b %m %I:%M:%S %p %Y"
134+
FORMAT_DATE = "%a %b %m %I:%M:%S.{} %p %Y"
135135
FORMAT_EVENT = "{timestamp: 9.6f} {message}\n"
136136

137137
def __init__(self, file, channel=1):
@@ -146,7 +146,7 @@ def __init__(self, file, channel=1):
146146
self.channel = channel
147147

148148
# write start of file header
149-
now = datetime.now().strftime("%a %b %m %I:%M:%S %p %Y")
149+
now = datetime.now().strftime("%a %b %m %I:%M:%S.%f %p %Y")
150150
self.file.write("date %s\n" % now)
151151
self.file.write("base hex timestamps absolute\n")
152152
self.file.write("internal events logged\n")
@@ -176,7 +176,8 @@ def log_event(self, message, timestamp=None):
176176
if not self.header_written:
177177
self.last_timestamp = (timestamp or 0.0)
178178
self.started = self.last_timestamp
179-
formatted_date = time.strftime(self.FORMAT_DATE, time.localtime(self.last_timestamp))
179+
mlsec = repr(self.last_timestamp).split('.')[1][:3]
180+
formatted_date = time.strftime(self.FORMAT_DATE.format(mlsec), time.localtime(self.last_timestamp))
180181
self.file.write("Begin Triggerblock %s\n" % formatted_date)
181182
self.header_written = True
182183
self.log_event("Start of measurement") # caution: this is a recursive call!

0 commit comments

Comments
 (0)