Skip to content

Commit 8175877

Browse files
committed
unix/modtime: strftime(): Support 2nd argument, but as time_t value.
Instead of struct tm like structure, as required by CPython.
1 parent fe6756a commit 8175877

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

unix/modtime.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,14 @@ STATIC mp_obj_t mod_time_sleep_us(mp_obj_t arg) {
155155
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_us_obj, mod_time_sleep_us);
156156

157157
STATIC mp_obj_t mod_time_strftime(mp_uint_t n_args, const mp_obj_t *args) {
158-
assert(n_args == 1);
159-
time_t t = time(NULL);
158+
time_t t;
159+
if (n_args == 1) {
160+
t = time(NULL);
161+
} else {
162+
// CPython requires passing struct tm, but we allow to pass time_t
163+
// (and don't support struct tm so far).
164+
t = mp_obj_get_int(args[1]);
165+
}
160166
struct tm *tm = localtime(&t);
161167
char buf[32];
162168
size_t sz = strftime(buf, sizeof(buf), mp_obj_str_get_str(args[0]), tm);

0 commit comments

Comments
 (0)