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:
committed by
Damien George
parent
419134bea4
commit
290dc1d5ee
@@ -67,7 +67,7 @@ static inline int msec_sleep_tv(struct timeval *tv) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC mp_obj_t mod_time_time(void) {
|
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;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
mp_float_t val = tv.tv_sec + (mp_float_t)tv.tv_usec / 1000000;
|
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) {
|
if (n_args == 0) {
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
} else {
|
} 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]);
|
mp_float_t val = mp_obj_get_float(args[0]);
|
||||||
t = (time_t)MICROPY_FLOAT_C_FUN(trunc)(val);
|
t = (time_t)MICROPY_FLOAT_C_FUN(trunc)(val);
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user