You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import time
from adafruit_datetime import datetime
dt = datetime(2024, 1, 26, 1, 2, 3)
print(int(dt.timestamp()))
print(time.mktime(dt.timetuple()))
Returns this:
>>> 1706230784
>>> 1706230923
The epoch timestamp from time.mktime() is correct while the timestamp from dt.timestamp() is 139 seconds early. This code is running on the Challenger RP2040 WIFI MkII with CircuitPython 8.2.9.
The text was updated successfully, but these errors were encountered:
I am not positive but I believe the difference is the effect of converting the float coming out of timestamp() to an int. I think there is more limited precision in CircuitPython than CPython. As an example removing this library and time concepts all together you can see it with this in the REPL:
As a workaround you can call dt._mktime() instead of dt.timestamp() which will basically give you the int version without making the detour into float type, that appears to yield the same result as time.mktime(dt.timetuple()) in my testing.
I'm going to close this as I believe it's a limitation of the platform more than an issue with this library specifically. If you ask in the discord or an issue in the core you may be able to get a better explanation of the specifics from one of the core devs.
Running this:
Returns this:
The epoch timestamp from time.mktime() is correct while the timestamp from dt.timestamp() is 139 seconds early. This code is running on the Challenger RP2040 WIFI MkII with CircuitPython 8.2.9.
The text was updated successfully, but these errors were encountered: