Skip to content

Commit e7fc806

Browse files
authored
Throw a NotImplementedError for time functions on boards without long ints
Fix for Issue #2812. Instead of reporting a missing attribute for functions such as time.time() and time.mktime(); platforms that do not have long integer support will raise a NotImplementedError
1 parent 4e786fa commit e7fc806

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

shared-bindings/time/__init__.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) {
188188
tm->tm_yday = mp_obj_get_int(elems[7]);
189189
// elems[8] tm_isdst is not supported
190190
}
191+
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
192+
// Function to return a NotImplementedError on platforms that don't
193+
// support long integers
194+
STATIC mp_obj_t time_not_implemented(void) {
195+
mp_raise_NotImplementedError(translate("No long integer support"));
196+
}
197+
MP_DEFINE_CONST_FUN_OBJ_0(time_not_implemented_obj, time_not_implemented);
198+
#endif
191199

192200
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
193201
mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
@@ -307,6 +315,12 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
307315
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
308316
{ MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_monotonic_ns_obj) },
309317
#endif
318+
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
319+
{ MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_not_implemented_obj) },
320+
{ MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_not_implemented_obj) },
321+
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_not_implemented_obj) },
322+
{ MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_not_implemented_obj) },
323+
#endif
310324
};
311325

312326
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);

0 commit comments

Comments
 (0)