Skip to content

Add optional timezone argument to BLFReader and BLFWriter - #2111

Open
smoltafet wants to merge 1 commit into
hardbyte:mainfrom
smoltafet:feat/blf-timezone
Open

smoltafet wants to merge 1 commit into
hardbyte:mainfrom
smoltafet:feat/blf-timezone

Conversation

@smoltafet

Copy link
Copy Markdown

Summary of Changes

  • BLFReader and BLFWriter accept a new optional tz argument (a datetime.tzinfo), following the existing tz parameter of the ASC reader/writer.
  • The BLF header stores the measurement start/stop times as a timezone-less SYSTEMTIME. It is now interpreted (reader, and writer in append mode) and written (writer) in the given timezone instead of always UTC. Message timestamps are relative to the header start time, so they shift accordingly.
  • The module-level helpers systemtime_to_timestamp and timestamp_to_systemtime gained the same optional parameter; their defaults are unchanged.
  • Default behavior is unchanged: without tz, everything keeps assuming UTC.

This addresses the compatibility problem from the issue: CANoe writes the header timestamps in the local time of the recording computer, so reading such a file shifted all timestamps unless you happened to be in UTC. Now you can pass e.g. tz=ZoneInfo("Europe/Berlin") (or the matching fixed offset) on both sides.

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

Tests: new TestBlfTimezone in test/logformats_test.py covers the SYSTEMTIME conversion helpers, a write/read round-trip with a timezone (including that reading without tz shifts the timestamps by exactly the offset), and append mode keeping the start timestamp. Full logformats suite passes (82 passed, 10 skipped); ruff check (project pin) and black --check are clean on the changed files.

@smoltafet

Copy link
Copy Markdown
Author

Hi @zariiii9003, could you take a look at this when you have a moment? Happy to fix up anything that needs changing. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BLFReader and BLFWriter should have a timezone optional argument

1 participant