Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 371deae

Browse files
committedMar 5, 2021
Corrected fidelity of datetime.fromtimestamp()
1 parent 25f8de0 commit 371deae

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
 

‎adafruit_datetime.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,16 +1284,18 @@ def _fromtimestamp(cls, t, utc, tz):
12841284
A timezone info object may be passed in as well.
12851285
"""
12861286
if isinstance(t, float):
1287-
frac, t = _math.modf(t)
1287+
frac = t - int(t)
1288+
t = int(t)
1289+
us = round(frac * 1e6)
1290+
if us >= 1000000:
1291+
t += 1
1292+
us -= 1000000
1293+
elif us < 0:
1294+
t -= 1
1295+
us += 1000000
12881296
else:
12891297
frac = 0
1290-
us = round(frac * 1e6)
1291-
if us >= 1000000:
1292-
t += 1
1293-
us -= 1000000
1294-
elif us < 0:
1295-
t -= 1
1296-
us += 1000000
1298+
us = 0
12971299

12981300
if utc:
12991301
raise NotImplementedError(

0 commit comments

Comments
 (0)
Please sign in to comment.