Skip to content

Error with timestamp when write a blf file with BLFWriter and read with BLFReader #1266

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

Closed
shach934 opened this issue Feb 24, 2022 · 1 comment · Fixed by #1273
Closed

Error with timestamp when write a blf file with BLFWriter and read with BLFReader #1266

shach934 opened this issue Feb 24, 2022 · 1 comment · Fixed by #1273
Labels

Comments

@shach934
Copy link

Describe the bug

Write a blf file with a start_timestamp like: 1636485425.999908, then read with BLFReader, the start_timestamp cannot be interpreted and assigned to 0.

To Reproduce

Try to save a blf file with start_timestamp like 1636485425.999908. then read it with BLFReader.
The error is caused by the following(function systemtime_to_timestamp()) :

    t = datetime.datetime.fromtimestamp(timestamp)
    return (
        t.year,
        t.month,
        t.isoweekday() % 7,
        t.day,
        t.hour,
        t.minute,
        t.second,
        int(round(t.microsecond / 1000.0)),
    )¨

1636485425.999908 will become (2021, 11, 2, 9, 20, 17, 5, 1000). The microsecond part becomes 1000.
When read with BLFReader(function: timestamp_to_systemtime()):

t = datetime.datetime(
            systemtime[0],
            systemtime[1],
            systemtime[3],
            systemtime[4],
            systemtime[5],
            systemtime[6],
            systemtime[7] * 1000,
        )

An error with the microsecond part: systemtime[7] * 1000 is 1000000 over a valid range 0-99999. The start_timestamp will be 0. Information lost.

Suggest: dont round(t.microsecond/1000), instead use: t.microsecond//1000, to keep the first 3 digits.

Expected behavior

Keep the original timestamp.

Additional context

OS and version: Win10
Python version: 3.9.7
python-can version: 4.0.0
python-can interface/s (if applicable):

Traceback and logs
def func():
    return "hello, world!"
@shach934 shach934 added the bug label Feb 24, 2022
@christiansandberg
Copy link
Collaborator

Good catch! Would you be able to make a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants