summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/samd/modutime.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ports/samd/modutime.c b/ports/samd/modutime.c
index bbeedcfda..a54544e62 100644
--- a/ports/samd/modutime.c
+++ b/ports/samd/modutime.c
@@ -27,6 +27,9 @@
#include "py/runtime.h"
#include "extmod/utime_mphal.h"
#include "shared/timeutils/timeutils.h"
+#include "mphalport.h"
+
+static uint32_t time_offset = 0;
// localtime([secs])
STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
@@ -34,9 +37,10 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
mp_int_t seconds;
if (n_args == 0 || args[0] == mp_const_none) {
// seconds = pyb_rtc_get_us_since_epoch() / 1000 / 1000;
- seconds = mp_obj_get_int(args[0]);
+ seconds = mp_hal_ticks_ms_64() / 1000 + time_offset;
} else {
seconds = mp_obj_get_int(args[0]);
+ time_offset = seconds - mp_hal_ticks_ms_64() / 1000;
}
timeutils_seconds_since_epoch_to_struct_time(seconds, &tm);
mp_obj_t tuple[8] = {
@@ -72,7 +76,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime);
// time()
STATIC mp_obj_t time_time(void) {
- mp_raise_NotImplementedError("time");
+ return mp_obj_new_int_from_uint(mp_hal_ticks_ms_64() / 1000 + time_offset);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);