Skip to content

Update time.struct_time() #4930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions shared-bindings/time/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,26 @@ mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp
if (n_args != 1 || (kw_args != NULL && kw_args->used > 0)) {
return namedtuple_make_new(type, n_args, args, kw_args);
}
if (mp_obj_get_type(args[0])->getiter != mp_obj_tuple_getiter || ((mp_obj_tuple_t *)MP_OBJ_TO_PTR(args[0]))->len != 9) {
size_t len = 0;
mp_obj_t *items = NULL;
if (mp_obj_is_type(args[0], &mp_type_list)) {
len = ((mp_obj_list_t *)args[0])->len;
items = ((mp_obj_list_t *)args[0])->items;
} else if (mp_obj_is_type(args[0], &mp_type_tuple)) {
len = ((mp_obj_tuple_t *)args[0])->len;
items = ((mp_obj_tuple_t *)args[0])->items;
}
if (len != 9) {
mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence"));
}

mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(args[0]);
return namedtuple_make_new(type, 9, tuple->items, NULL);
return namedtuple_make_new(type, len, items, NULL);
}

//| class struct_time:
//| def __init__(self, time_tuple: Tuple[int, int, int, int, int, int, int, int, int]) -> None:
//| """Structure used to capture a date and time. Note that it takes a tuple!
//| def __init__(self, time: Tuple[int, int, int, int, int, int, int, int, int]) -> None:
//| """Structure used to capture a date and time. Note that it takes list or a tuple!
//|
//| :param tuple time_tuple: Tuple of time info: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
//| :param time: ``(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)``
//|
//| * ``tm_year``: the year, 2017 for example
//| * ``tm_mon``: the month, range [1, 12]
Expand Down