diff options
| author | Oliver Joos | 2020-12-16 22:35:52 +0100 |
|---|---|---|
| committer | Damien George | 2021-01-23 16:55:24 +1100 |
| commit | 290dc1d5eeba005bdc604a9eb2d781a922081c29 (patch) | |
| tree | e6d58e95bebb11b70950993f05e62c8b69790e40 /ports/unix | |
| parent | 419134bea47953888344d325220c376117f6b2b4 (diff) | |
unix/modtime: Fix time() precision on unix ports with non-double floats.
With MICROPY_FLOAT_IMPL_FLOAT the results of utime.time(), gmtime() and
localtime() change only every 129 seconds. As one consequence
tests/extmod/vfs_lfs_mtime.py will fail on a unix port with LFS support.
With this patch these functions only return floats if
MICROPY_FLOAT_IMPL_DOUBLE is used. Otherwise they return integers.
Diffstat (limited to 'ports/unix')
| -rw-r--r-- | ports/unix/modtime.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ports/unix/modtime.c b/ports/unix/modtime.c index e08409e20..91c0a1941 100644 --- a/ports/unix/modtime.c +++ b/ports/unix/modtime.c @@ -67,7 +67,7 @@ static inline int msec_sleep_tv(struct timeval *tv) { #endif STATIC mp_obj_t mod_time_time(void) { - #if MICROPY_PY_BUILTINS_FLOAT + #if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE struct timeval tv; gettimeofday(&tv, NULL); mp_float_t val = tv.tv_sec + (mp_float_t)tv.tv_usec / 1000000; @@ -137,7 +137,7 @@ STATIC mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, stru if (n_args == 0) { t = time(NULL); } else { - #if MICROPY_PY_BUILTINS_FLOAT + #if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE mp_float_t val = mp_obj_get_float(args[0]); t = (time_t)MICROPY_FLOAT_C_FUN(trunc)(val); #else |
