← index #3674Issue #10578
Likely Duplicate · high · value 4.055
QUERY · ISSUE

ESP32 machine.rtc datetime tuple parameters don't match documentation

openby ed-frenchopened 2018-03-19updated 2024-09-19
docsport-esp32

Micropython documentation: http://docs.micropython.org/en/latest/wipy/library/machine.RTC.html
Shows machine.rtc.init documented with tuple like this:

RTC.init(datetime)
Initialise the RTC. Datetime is a tuple of the form:

(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])

However, the code suggests a different order is used: https://github.com/micropython/micropython/blob/master/ports/esp32/machine_rtc.c

timeutils_seconds_since_2000(mp_obj_get_int(items[0]), mp_obj_get_int(items[1]), mp_obj_get_int(items[2]), mp_obj_get_int(items[4]), mp_obj_get_int(items[5]), mp_obj_get_int(items[6]))

Likewise with machine.rtc.datetime actually returns this order of parameters in the tuple:

r.datetime()
(2018, 3, 21, 2, 6, 8, 19, 258907)
r.datetime()
(2018, 3, 21, 2, 6, 8, 22, 828728)
r.datetime()
(2018, 3, 21, 2, 6, 9, 31, 888997)
r.init((2018,3,19,0,7,5,0,0))
r.datetime()
(2018, 3, 19, 0, 7, 5, 4, 368663)
r.datetime()
(2018, 3, 19, 0, 7, 5, 16, 608804)
r.datetime()
(2018, 3, 19, 0, 7, 5, 38, 98816)

CANDIDATE · ISSUE

ports/rtc: Inconsistencies between ports and the documentation.

closedby robert-hhopened 2023-01-24updated 2024-12-28
ports

It looks like the machine.rtc() API is different for all ports and to the documentation.

  • to start with the good part: In all ports rtc.datetime() matches the machine.RTC class documentation.
  • rtc.init() for the cc3200 works as documented
  • rtc.init() differs from the documentation in the item order of the datetime tuple for the ports esp32, samd, mimxrt.
  • no rtc.init() at the rp2 port.
  • rtc.init() at the stm32 and renesas.ra port just reinit's the RTC device and ignores the function argument.
  • rtc.now() is only available in the cc3200 and mimxrt port.
  • the documentation for rtc.datetime() is different between the machine.RTC class section and the quickref for the ports stm32, rp2, mimxrt, esp32, esp8266, renesas-ra,

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:

  • keep rtc.datetime() as it is now. Maybe add it to the cc3200 port. It is not consistent to CPython datetime.datetime, but that topic has been discussed several times already with the decision to keep the actual rtc.datetime format.
  • drop rtc.now() from the mimxrt port. Only keep it at the CC3200 port for legacy.
  • drop the set date/time functionality of rtc.init() and/or change at least the documentation.
  • fix the inconsistencies in the documentation.

Edit: Created PR #10607

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied