|
53 | 53 | // - weekday is 0-6 for Mon-Sun |
54 | 54 | // - yearday is 1-366 |
55 | 55 | static mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { |
| 56 | + timeutils_struct_time_t tm; |
56 | 57 | if (n_args == 0 || args[0] == mp_const_none) { |
57 | 58 | // Get current date and time. |
58 | | - return mp_time_localtime_get(); |
| 59 | + mp_time_localtime_get(&tm); |
59 | 60 | } else { |
60 | 61 | // Convert given seconds to tuple. |
61 | 62 | mp_timestamp_t seconds = timeutils_obj_get_timestamp(args[0]); |
62 | | - timeutils_struct_time_t tm; |
63 | 63 | timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); |
64 | | - mp_obj_t tuple[8] = { |
65 | | - tuple[0] = mp_obj_new_int(tm.tm_year), |
66 | | - tuple[1] = mp_obj_new_int(tm.tm_mon), |
67 | | - tuple[2] = mp_obj_new_int(tm.tm_mday), |
68 | | - tuple[3] = mp_obj_new_int(tm.tm_hour), |
69 | | - tuple[4] = mp_obj_new_int(tm.tm_min), |
70 | | - tuple[5] = mp_obj_new_int(tm.tm_sec), |
71 | | - tuple[6] = mp_obj_new_int(tm.tm_wday), |
72 | | - tuple[7] = mp_obj_new_int(tm.tm_yday), |
73 | | - }; |
74 | | - return mp_obj_new_tuple(8, tuple); |
75 | 64 | } |
| 65 | + mp_obj_t tuple[8] = { |
| 66 | + mp_obj_new_int(tm.tm_year), |
| 67 | + mp_obj_new_int(tm.tm_mon), |
| 68 | + mp_obj_new_int(tm.tm_mday), |
| 69 | + mp_obj_new_int(tm.tm_hour), |
| 70 | + mp_obj_new_int(tm.tm_min), |
| 71 | + mp_obj_new_int(tm.tm_sec), |
| 72 | + mp_obj_new_int(tm.tm_wday), |
| 73 | + mp_obj_new_int(tm.tm_yday), |
| 74 | + }; |
| 75 | + return mp_obj_new_tuple(8, tuple); |
76 | 76 | } |
77 | 77 | MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_time_localtime_obj, 0, 1, time_localtime); |
78 | 78 |
|
|
0 commit comments