Skip to content

Commit

Permalink
update start time in asc file to be the started time instead of file …
Browse files Browse the repository at this point in the history
…created time
  • Loading branch information
Aman Aggarwal committed Dec 16, 2024
1 parent 654a02a commit 4ba1914
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions can/io/asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ def __init__(
self.channel = channel

# write start of file header
start_time = self._format_header_datetime(datetime.now())
self.file.write(f"date {start_time}\n")
self.start_time = self._format_header_datetime(datetime.now())
self.file.write(f"date {self.start_time}\n")
self.file.write("base hex timestamps absolute\n")
self.file.write("internal events logged\n")

Expand All @@ -393,6 +393,14 @@ def _format_header_datetime(self, dt: datetime) -> str:
def stop(self) -> None:
# This is guaranteed to not be None since we raise ValueError in __init__
if not self.file.closed:
if self.started is not None:
formatted_date = self._format_header_datetime(
datetime.fromtimestamp(self.started)
)
self.file.seek(0)
self.file.write(f"date {formatted_date}\n")
else:
logger.warning("No messages logged; 'started' timestamp is None.")
self.file.write("End TriggerBlock\n")
super().stop()

Expand Down

0 comments on commit 4ba1914

Please sign in to comment.