Skip to content

Commit c2b7164

Browse files
authored
Merge pull request #6 from cognitivegears/master
Corrected fidelity of datetime.fromtimestamp()
2 parents c0faca0 + d1f502f commit c2b7164

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

adafruit_datetime.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1285,15 +1285,15 @@ def _fromtimestamp(cls, t, utc, tz):
12851285
"""
12861286
if isinstance(t, float):
12871287
frac, t = _math.modf(t)
1288+
us = round(frac * 1e6)
1289+
if us >= 1000000:
1290+
t += 1
1291+
us -= 1000000
1292+
elif us < 0:
1293+
t -= 1
1294+
us += 1000000
12881295
else:
1289-
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
1296+
us = 0
12971297

12981298
if utc:
12991299
raise NotImplementedError(

0 commit comments

Comments
 (0)