8000 esp32/time: make utime conform to CPython and add SNTP by tve · Pull Request #5972 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

esp32/time: make utime conform to CPython and add SNTP #5972

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

Conversation

tve
Copy link
Contributor
@tve tve commented Apr 26, 2020

This PR attempts to start fixing some of the issues with utime and machine.RTC, per #5969, #5553, #5733. The overall idea is to flesh out utime B231 so it is (a) compatible with CPython and (b) fully-featured to manage the time and (internally) query/set the RTC. The RTC.datetime method would then be deprecated but left in-place for code compatibility and possibly for minimal ports that don't have utime (I have not looked at that aspect).

What this PR currently does is in the esp32 port:

  • change utime.localtime and utime.mktime to conform to the CPython standard 9-tuple (well, actually to the 9 11-tuple elements that have numeric indexes).
  • change the Epoch to be the POSIX 1970 Epoch.
  • add utime.gmtime and time.tzset so one can set a time zone and query UTC as well as local time. The implementation of tzset 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.
  • add utime.set_time and utime.adjtime as extensions WRT CPython so one can step the time or gradually adjust the time.
  • add a 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.

@tve tve closed this Apr 26, 2020
@tve
Copy link
Contributor Author
tve commented Apr 26, 2020

Oops, I wanted to create a "draft pull request" and hit the wrong button. See #5973.

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.

1 participant
0