Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return _mktime() from timestamp() #31

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions adafruit_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,18 +1520,10 @@ def toordinal(self) -> int:
return _ymd2ord(self._year, self._month, self._day)

def timestamp(self) -> float:
"""Return POSIX timestamp as float.

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

def weekday(self) -> int:
"""Return the day of the week as an integer, where Monday is 0 and Sunday is 6."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ def test_utcfromtimestamp(self):
def test_timestamp_naive(self):
t = self.theclass(1970, 1, 1)
self.assertEqual(t.timestamp(), 18000.0)
t = self.theclass(1970, 1, 1, 1, 2, 3, 4)
self.assertEqual(t.timestamp(), 18000.0 + 3600 + 2 * 60 + 3 + 4 * 1e-6)
t = self.theclass(1970, 1, 1, 1, 2, 3)
self.assertEqual(t.timestamp(), 18000.0 + 3600 + 2 * 60 + 3)
# Missing hour
t0 = self.theclass(2012, 3, 11, 2, 30)
t1 = t0.replace(fold=1)
Expand Down
Loading