Skip to content

Broken fidelity on datetime.fromtimestamp() #5

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
cognitivegears opened this issue Mar 5, 2021 · 4 comments
Closed

Broken fidelity on datetime.fromtimestamp() #5

cognitivegears opened this issue Mar 5, 2021 · 4 comments

Comments

@cognitivegears
Copy link
Contributor

Using datetime.fromtimestamp() is returning incorrect results due to a loss of precision in the underlying EPOC time. This causes the time to return the same result for multiple seconds, and then "jump", making the seconds value not reliable.

Tested on FeatherS2 and Raspberry Pi Pico.

Steps to reproduce:

import time
import adafruit_datetime as datetime
while True:
    datetime.datetime.fromtimestamp(time.time())
    time.sleep(1)

(observe the time not change second to second)

@cognitivegears
Copy link
Contributor Author

Ok, found out that #4 beat me to the punch on this one. I was comparing with the precompiled version of adafruit_datetime from several days ago, so didn't catch this change. Leaving this here, however, as in the integer case my version avoids an unnecessary conditional and round call, but functionally they are identical so this can be abandoned if you do not feel that it is worth it otherwise.

@tannewt
Copy link
Member

tannewt commented Mar 8, 2021

@jepler What do you think?

@cognitivegears
Copy link
Contributor Author

Made updates to the PR per code review

@jepler
Copy link
Contributor

jepler commented Mar 12, 2021

Thank you!

@jepler jepler closed this as completed Mar 12, 2021
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

No branches or pull requests

3 participants