Skip to content

time.localtime: low timestamps when epoch is 2000 #4762

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

Merged
merged 1 commit into from
Jul 15, 2021
Merged
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
4 changes: 4 additions & 0 deletions shared-bindings/time/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {

mp_int_t secs = mp_obj_get_int(arg);

#if MICROPY_EPOCH_IS_1970
if (secs < 0 || (mp_uint_t)secs < TIMEUTILS_SECONDS_1970_TO_2000) {
#else
if (secs < 0) {
#endif
Comment on lines +251 to +255
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a conversion routine maybe be added to lib/timeutils that does this check, to isolate epoch checking in one place? I don't think lib/timeutils should necessarily throw an exception, but it could return success/failure on the conversion.

mp_raise_msg(&mp_type_OverflowError, translate("timestamp out of range for platform time_t"));
}

Expand Down