Skip to content

ntptime: Year 2036 fix. #837

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
May 15, 2024
Merged

Conversation

jonfoster
Copy link
Contributor

Fix a bug in the NTP client, where it would report the wrong time after 7 Feb 2036.

The NTP timestamp has a 32-bit count of seconds, which will wrap back to zero on 7 Feb 2036 at 06:28:16.

It's now March 2024. So we know that timestamps less than 1st Jan 2024 are impossible. So if the timestamp appears to be earlier than 1st Jan 2024, that probably means that the NTP time wrapped at 2^32 seconds. (Or someone set the wrong time on their NTP server, but we can't really do anything about that). So in that case, we need to add in those extra 2^32 seconds, to get the correct timestamp.

This means that this code will work until the year 2160.

(More precisely, this code will not work after 7th Feb 2160 at 06:28:15. Fixing that is someone else's problem, some time in the far future, by adjusting the NTP_DELTA and MIN_NTP_TIMESTAMP values. By just changing those two numbers, you can choose any 136-year span of time that will be supported).

This replaces #830 because apparently in GitHub, once I've made a Pull Request I can't change what branch it's pulling from, and I accidentally set up 830 to pull from my "master" branch.

@projectgus
Copy link
Contributor

Nice fix, @jonfoster . I wasn't familiar with this issue, but these articles gave me a pretty good background for anyone else who is curious: https://www.eecis.udel.edu/~mills/time.html

Fix NTP client - it would report the wrong time after 7 Feb 2036.

Signed-off-by: Jon Foster <[email protected]>
@dpgeorge dpgeorge force-pushed the ntptime-2036-pull branch from 5596efd to cb281a4 Compare May 15, 2024 05:38
@dpgeorge dpgeorge merged commit cb281a4 into micropython:master May 15, 2024
3 checks passed
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.

3 participants