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

Conversation

Neradoc
Copy link

@Neradoc Neradoc commented May 14, 2021

When the Epoch is set to 2000 instead of 1970 (MICROPY_EPOCH_IS_1970 set to 0), rejecting values lower than TIMEUTILS_SECONDS_1970_TO_2000in time.localtime() results in rejecting dates before 2030.

Comment on lines +251 to +255
#if MICROPY_EPOCH_IS_1970
if (secs < 0 || (mp_uint_t)secs < TIMEUTILS_SECONDS_1970_TO_2000) {
#else
if (secs < 0) {
#endif
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.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Thanks! This is fine for now; we can investigate refactoring later.

@dhalbert dhalbert merged commit 698a392 into adafruit:main Jul 15, 2021
@Neradoc Neradoc deleted the small-timestamps-if-epoch-2000 branch September 4, 2021 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants