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.
This commit is contained in:
Oliver Joos 2020-12-16 22:35:52 +01:00 committed by Damien George
parent 419134bea4
commit 290dc1d5ee
1 changed files with 2 additions and 2 deletions

View File

@ -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