From c4b9a0b63620dc3fe761d40fb024321d285cc0b4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 17 Jan 2025 09:52:14 -0600 Subject: [PATCH 1/3] return _mktime() from timestamp() --- adafruit_datetime.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/adafruit_datetime.py b/adafruit_datetime.py index 83dceef..2d97d1b 100755 --- a/adafruit_datetime.py +++ b/adafruit_datetime.py @@ -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 float.""" 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.""" From cdb02bf7fbff3641c4227c576d4a3cb77cc098a3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 17 Jan 2025 09:59:58 -0600 Subject: [PATCH 2/3] remove microseconds from timestamp naive test --- tests/test_datetime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_datetime.py b/tests/test_datetime.py index 6c4d5f1..bab3b64 100644 --- a/tests/test_datetime.py +++ b/tests/test_datetime.py @@ -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) From 7315cd7ffb078fe026c5e860a9a1e612a6a44dd1 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Fri, 17 Jan 2025 18:04:20 +0100 Subject: [PATCH 3/3] Update adafruit_datetime.py dosctring --- adafruit_datetime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_datetime.py b/adafruit_datetime.py index 2d97d1b..216ef5d 100755 --- a/adafruit_datetime.py +++ b/adafruit_datetime.py @@ -1520,7 +1520,7 @@ def toordinal(self) -> int: return _ymd2ord(self._year, self._month, self._day) def timestamp(self) -> float: - """Return POSIX timestamp as float.""" + """Return POSIX timestamp as int, similar to the value returned by ``time.time()``.""" if not self._tzinfo is None: return (self - _EPOCH).total_seconds() return self._mktime() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy