@@ -170,12 +170,19 @@ STATIC mp_obj_t time_ticks_cpu(void) {
170
170
STATIC MP_DEFINE_CONST_FUN_OBJ_0 (time_ticks_cpu_obj , time_ticks_cpu );
171
171
172
172
STATIC mp_obj_t time_ticks_diff (mp_obj_t start_in , mp_obj_t end_in ) {
173
- uint32_t start = mp_obj_get_int (start_in );
174
- uint32_t end = mp_obj_get_int (end_in );
175
- return mp_obj_new_int_from_uint (( end - start ) );
173
+ int32_t start = mp_obj_get_int_truncated (start_in );
174
+ int32_t end = mp_obj_get_int_truncated (end_in );
175
+ return mp_obj_new_int ( end - start );
176
176
}
177
177
STATIC MP_DEFINE_CONST_FUN_OBJ_2 (time_ticks_diff_obj , time_ticks_diff );
178
178
179
+ STATIC mp_obj_t time_ticks_add (mp_obj_t start_in , mp_obj_t delta_in ) {
180
+ int32_t start = mp_obj_get_int_truncated (start_in );
181
+ int32_t delta = mp_obj_get_int_truncated (delta_in );
182
+ return mp_obj_new_int (start + delta );
183
+ }
184
+ STATIC MP_DEFINE_CONST_FUN_OBJ_2 (time_ticks_add_obj , time_ticks_add );
185
+
179
186
/// \function time()
180
187
/// Returns the number of seconds, as an integer, since 1/1/1970.
181
188
STATIC mp_obj_t time_time (void ) {
@@ -208,6 +215,7 @@ STATIC const mp_map_elem_t time_module_globals_table[] = {
208
215
{ MP_OBJ_NEW_QSTR (MP_QSTR_ticks_ms ), (mp_obj_t )& time_ticks_ms_obj },
209
216
{ MP_OBJ_NEW_QSTR (MP_QSTR_ticks_us ), (mp_obj_t )& time_ticks_us_obj },
210
217
{ MP_OBJ_NEW_QSTR (MP_QSTR_ticks_cpu ), (mp_obj_t )& time_ticks_cpu_obj },
218
+ { MP_OBJ_NEW_QSTR (MP_QSTR_ticks_add ), (mp_obj_t )& time_ticks_add_obj },
211
219
{ MP_OBJ_NEW_QSTR (MP_QSTR_ticks_diff ), (mp_obj_t )& time_ticks_diff_obj },
212
220
{ MP_OBJ_NEW_QSTR (MP_QSTR_time ), (mp_obj_t )& time_time_obj },
213
221
{ MP_OBJ_NEW_QSTR (MP_QSTR_timezone ), (mp_obj_t )& time_timezone_obj },
0 commit comments