esp32/time: make utime conform to CPython and add SNTP #5972
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to start fixing some of the issues with
utime
andmachine.RTC
, per #5969, #5553, #5733. The overall idea is to flesh oututime
B231 so it is (a) compatible with CPython and (b) fully-featured to manage the time and (internally) query/set the RTC. TheRTC.datetime
method would then be deprecated but left in-place for code compatibility and possibly for minimal ports that don't haveutime
(I have not looked at that aspect).What this PR currently does is in the esp32 port:
utime.localtime
andutime.mktime
to conform to the CPython standard 9-tuple (well, actually to the 9 11-tuple elements that have numeric indexes).utime.gmtime
andtime.tzset
so one can set a time zone and query UTC as well as local time. The implementation oftzset
does not conform to CPython in that it takes a zone specification whereas in CPython it takes no argument and the zone is set via the TZ environment variable.utime.set_time
andutime.adjtime
as extensions WRT CPython so one can step the time or gradually adjust the time.network.SNTP
class with methods to start SNTP, stop SNTP, and get the SNTP status (this is only partially implemented in this PR and is intended to leverage the LwIP SNTP implementation).I believe that this ends up producing a clean interface to time that can be fully implemented on the bigger ports using newlib and LwIP, and that can be stripped down, e.g. without time-zone support, for smaller ports. It somewhat side-steps the incompatibilities between RTC implementations by leaving that class along for legacy use, as well as for minimal ports without
utime
.I volunteer to port this PR to the unix and stm32 ports so these are in-sync.