summaryrefslogtreecommitdiff
path: root/ports/esp8266/modtime.c
diff options
context:
space:
mode:
authorYoctopuce dev <dev@yoctopuce.com>2025-07-01 13:16:20 +0200
committerDamien George <damien@micropython.org>2025-07-09 11:54:21 +1000
commitdf05caea6c6437a8b4756ec502a5e6210f4b6256 (patch)
tree4ffab6a3b85bb8a287e661d55a7ddc59f80357d9 /ports/esp8266/modtime.c
parentc4a88f2ce7da87d5f635ec25edba481917020fd8 (diff)
shared/timeutils: Standardize supported date range on all platforms.
This is code makes sure that time functions work properly on a reasonable date range, on all platforms, regardless of the epoch. The suggested minimum range is 1970 to 2099. In order to reduce code footprint, code to support far away dates is only enabled specified by the port. New types are defined to identify timestamps. The implementation with the smallest code footprint is when support timerange is limited to 1970-2099 and Epoch is 1970. This makes it possible to use 32 bit unsigned integers for all timestamps. On ARM4F, adding support for dates up to year 3000 adds 460 bytes of code. Supporting dates back to 1600 adds another 44 bytes of code. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
Diffstat (limited to 'ports/esp8266/modtime.c')
-rw-r--r--ports/esp8266/modtime.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ports/esp8266/modtime.c b/ports/esp8266/modtime.c
index 090300559..e99d920fd 100644
--- a/ports/esp8266/modtime.c
+++ b/ports/esp8266/modtime.c
@@ -31,7 +31,7 @@
// Return the localtime as an 8-tuple.
static mp_obj_t mp_time_localtime_get(void) {
- mp_int_t seconds = pyb_rtc_get_us_since_epoch() / 1000 / 1000;
+ mp_uint_t seconds = pyb_rtc_get_us_since_epoch() / 1000u / 1000u;
timeutils_struct_time_t tm;
timeutils_seconds_since_epoch_to_struct_time(seconds, &tm);
mp_obj_t tuple[8] = {
@@ -50,5 +50,5 @@ static mp_obj_t mp_time_localtime_get(void) {
// Returns the number of seconds, as an integer, since the Epoch.
static mp_obj_t mp_time_time_get(void) {
// get date and time
- return mp_obj_new_int(pyb_rtc_get_us_since_epoch() / 1000 / 1000);
+ return timeutils_obj_from_timestamp(pyb_rtc_get_us_since_epoch() / 1000 / 1000);
}