Repository navigation
ports/rtc: Inconsistencies between ports and the documentation. #10578
Description
Activity
You've probably seen #5553. Fixing this is long overdue but it will break code.
Should the
rtc.datetimetuple match the format oftime.localtime? (This would break even more code, though.)The section of the documentation which you changed is the only one which matches rtc.datetime(). But all the quickref paragraphs are wrong.My preference is in the post before in the last four bullets. I do not suggest to change rtc.datetime(), since it seems the only part which is consistent over the ports, if implemented at all.
How about adding a
rtc.localtimethat follow thetime.localtimeformat?
This way, there is a function that follows thetimeformat, and don't break any existing code.Why? rtc.datetime() and time.localtime() use the same hardware clock, if it exists. So there is no benefit in having a rtc,localtime().
What I really want, is a simple way of setting the RTC using something like Unix Timestamp.
It is possible to usetime.gmtimeto convert seconds to a datetime format, but this don't fit with thertc.datetimeas stated.An alternative solution is make a function like
rtc.set_epocor similar.
Then even libraries that can get the time, can be converted to epoc and used to set the RTC.For the SAMD port I had made an extension for boards without RTC, that you could supply a time value as seconds since epoch as argument to time.localtime() to set the time. But that's non-standard.
@dpgeorge Do you have a preference about how to proceed with reducing the inconsistencies of machine.RTC. I can at least make an initial PR to fix the documentation of rtc.datetime(), assuming that this method will not be changed.
Hi!
Correct me if I'm wrong, but I see a mistake in the doc for the rp2 RTC. We can read:
rtc.datetime((2017, 8, 23, 2, 12, 48, 0, 0)) # set a specific date and time, eg. 2017/8/23 1:12:48The code works ok, no problem. But the comment should be read: #... eg. 2017/8/23 12:48
As per the class RTC doc, The 8-tuple has the following format: (year, month, day, weekday, hours, minutes, seconds, subseconds)
So the time set is 12:48:00 not 1:12:48
- addedportsRelates to multiple ports, or a new/proposed portRelates to multiple ports, or a new/proposed port
on Sep 10, 2024
It looks like the machine.rtc() API is different for all ports and to the documentation.
So it seems as if the documentation of rtc.init() and rtc.now() only matches the cc3200 port. I can make that all consistent, but we should agree first on which class methods should be available. So a simple approach would be:
Edit: Created PR #10607