diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-01-10 12:06:49 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-01-10 12:08:27 +0200 |
commit | 8175877ad64a631e9ce0f9a5b66782d58ea5f48d (patch) | |
tree | 16ef5ffdc5a09a8c8d7a43c3fe54655d95723b9c /unix | |
parent | fe6756aa2d4fb0b2f39dce2fd09a69421c2d963a (diff) | |
download | micropython-8175877ad64a631e9ce0f9a5b66782d58ea5f48d.tar.gz micropython-8175877ad64a631e9ce0f9a5b66782d58ea5f48d.zip |
unix/modtime: strftime(): Support 2nd argument, but as time_t value.
Instead of struct tm like structure, as required by CPython.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/modtime.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/unix/modtime.c b/unix/modtime.c index b1b7a9079d..32a4a6c71f 100644 --- a/unix/modtime.c +++ b/unix/modtime.c @@ -155,8 +155,14 @@ STATIC mp_obj_t mod_time_sleep_us(mp_obj_t arg) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_us_obj, mod_time_sleep_us); STATIC mp_obj_t mod_time_strftime(mp_uint_t n_args, const mp_obj_t *args) { - assert(n_args == 1); - time_t t = time(NULL); + time_t t; + if (n_args == 1) { + t = time(NULL); + } else { + // CPython requires passing struct tm, but we allow to pass time_t + // (and don't support struct tm so far). + t = mp_obj_get_int(args[1]); + } struct tm *tm = localtime(&t); char buf[32]; size_t sz = strftime(buf, sizeof(buf), mp_obj_str_get_str(args[0]), tm); |