← index #4394PR #7383
Related · high · value 2.725
QUERY · ISSUE

esp32 localtime and machine.RTC().datetime() inconformity

openby junhuanchenopened 2019-01-03updated 2026-03-24
port-esp32

see this

https://github.com/micropython/micropython/blob/b33f108cdeb57c9d84e5a4eff5a46aa49c6dd558/ports/esp32/modutime.c#L52

and this

https://github.com/micropython/micropython/blob/b9ec6037edf5e6ff6f8f400d70f7351d1b0af67d/ports/esp32/machine_rtc.c#L105

I know it seems to have been designed, but if I assign values like this, I won't be able to use the following code.

machine.RTC().datetime(time.localtime(546450051)) # 546450051 only a number.

Is there a better way to set seconds to RTC time.

Otherwise I'll fill in the third element to align the structures, is that so?

CANDIDATE · PULL REQUEST

mimxrt/machine_rtc: Change format of RTC.datetime to match other ports.

closedby dpgeorgeopened 2021-06-12updated 2021-06-12
port-mimxrt

Following on from #7318, and after discussion https://github.com/micropython/micropython/pull/6928#issuecomment-859513267 and also #5553.

The point of this PR is to change RTC.datetime() on the mimxrt port to take/return an 8-tuple in the same format as most of the existing ports (stm32, esp8266, esp32). In the first version of #7318 @robert-hh did already have it this way but I suggested to change it to match CPython's datetime format (see https://github.com/micropython/micropython/pull/7318#issuecomment-848497591). That suggestion was a bit eager because it just introduces too much incompatibility, see https://github.com/micropython/micropython/pull/6928#issuecomment-859480494 .

Changes in this PR:

  • change RTC.datetime() to take/return an 8-tuple with format (year, month, day, weekday, hour, minute, second, microsecond)
  • remove unnecessary RTC.weekday()
  • keep behaviour of RTC.now() so it returns (year, month, day, hour, minute, second, microsecond, tzinfo). This matches the docs and the cc3200 port (and no other port has this now() method).

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