adafruit / Adafruit_CircuitPython_datetime

Basic date and time types. Implements a subset of the CPython datetime module.
MIT License
4 stars 9 forks source link

Broken fidelity on datetime.fromtimestamp() #5

Closed cognitivegears closed 3 years ago

cognitivegears commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@jepler What do you think?

cognitivegears commented 3 years ago

Made updates to the PR per code review

jepler commented 3 years ago

Thank you!