Skip to content

Commit a960a51

Browse files
author
Aman Aggarwal
committed
update start time in asc file to be the started time instead of file created time
1 parent 654a02a commit a960a51

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

can/io/asc.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ def __init__(
371371
self.channel = channel
372372

373373
# write start of file header
374-
start_time = self._format_header_datetime(datetime.now())
375-
self.file.write(f"date {start_time}\n")
374+
self.start_time = self._format_header_datetime(datetime.now())
375+
self.file.write(f"date {self.start_time}\n")
376376
self.file.write("base hex timestamps absolute\n")
377377
self.file.write("internal events logged\n")
378378

@@ -394,6 +394,14 @@ def stop(self) -> None:
394394
# This is guaranteed to not be None since we raise ValueError in __init__
395395
if not self.file.closed:
396396
self.file.write("End TriggerBlock\n")
397+
if self.started is not None:
398+
formatted_date = self._format_header_datetime(
399+
datetime.fromtimestamp(self.started)
400+
)
401+
self.file.seek(0)
402+
self.file.write(f"date {formatted_date}\n")
403+
else:
404+
logger.warning("No messages logged; 'started' timestamp is None.")
397405
super().stop()
398406

399407
def log_event(self, message: str, timestamp: Optional[float] = None) -> None:

0 commit comments

Comments
 (0)