Skip to content

Commit afd11b7

Browse files
authored
Merge pull request #31 from FoamyGuy/timestamp_remove_microseconds
return _mktime() from timestamp()
2 parents 1795aff + 7315cd7 commit afd11b7

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

adafruit_datetime.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -1520,18 +1520,10 @@ def toordinal(self) -> int:
15201520
return _ymd2ord(self._year, self._month, self._day)
15211521

15221522
def timestamp(self) -> float:
1523-
"""Return POSIX timestamp as float.
1524-
1525-
Note that Floats on most boards are encoded in 30 bits
1526-
internally, with effectively 22 bits of precision. As a result,
1527-
for modern dates this value can be off by several minutes.
1528-
As a workaround you can access the function ``_mktime()``
1529-
to get an int version of the timestamp.
1530-
"""
1523+
"""Return POSIX timestamp as int, similar to the value returned by ``time.time()``."""
15311524
if not self._tzinfo is None:
15321525
return (self - _EPOCH).total_seconds()
1533-
s = self._mktime()
1534-
return s + self.microsecond / 1e6
1526+
return self._mktime()
15351527

15361528
def weekday(self) -> int:
15371529
"""Return the day of the week as an integer, where Monday is 0 and Sunday is 6."""

tests/test_datetime.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ def test_utcfromtimestamp(self):
527527
def test_timestamp_naive(self):
528528
t = self.theclass(1970, 1, 1)
529529
self.assertEqual(t.timestamp(), 18000.0)
530-
t = self.theclass(1970, 1, 1, 1, 2, 3, 4)
531-
self.assertEqual(t.timestamp(), 18000.0 + 3600 + 2 * 60 + 3 + 4 * 1e-6)
530+
t = self.theclass(1970, 1, 1, 1, 2, 3)
531+
self.assertEqual(t.timestamp(), 18000.0 + 3600 + 2 * 60 + 3)
532532
# Missing hour
533533
t0 = self.theclass(2012, 3, 11, 2, 30)
534534
t1 = t0.replace(fold=1)

0 commit comments

Comments
 (0)