Skip to content

Refactor timestamp factor calculations to use constants #1933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion can/io/blf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class BLFParseError(Exception):
TIME_TEN_MICS = 0x00000001
TIME_ONE_NANS = 0x00000002

TIME_TEN_MICS_FACTOR = Decimal("1e-5")
TIME_ONE_NANS_FACTOR = Decimal("1e-9")


def timestamp_to_systemtime(timestamp: float) -> TSystemTime:
if timestamp is None or timestamp < 631152000:
Expand Down Expand Up @@ -269,7 +272,7 @@ def _parse_data(self, data):
continue

# Calculate absolute timestamp in seconds
factor = Decimal("1e-5") if flags == 1 else Decimal("1e-9")
factor = TIME_TEN_MICS_FACTOR if flags == 1 else TIME_ONE_NANS_FACTOR
timestamp = float(Decimal(timestamp) * factor) + start_timestamp

if obj_type in (CAN_MESSAGE, CAN_MESSAGE2):
Expand Down
Loading