From feb7e2e864639d82cc22729d4011b8ea663e9d1d Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Sun, 20 Jun 2021 11:49:56 +0200 Subject: [PATCH] rp2/machine_rtc: In RTC.datetime, compute weekday automatically. Calculating the weekday each time you want to set a date is error prone and tiresome. MicroPython can do it on its own - hardware on some ports do not support storing weekday in hardware and always computes it on the fly, ignoring the value given to the constructor. During discussion for #7432 the conclusion was that there seems to be no obvious reason to let user set the weekday to an incorrect value so it makes sense to just ignore the provided weekday value and always compute the correct value. This patch introduces this change for the rp2 port. Signed-off-by: Krzysztof Adamski --- ports/rp2/machine_rtc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/rp2/machine_rtc.c b/ports/rp2/machine_rtc.c index 797bee5ed3..a7c55b616b 100644 --- a/ports/rp2/machine_rtc.c +++ b/ports/rp2/machine_rtc.c @@ -94,11 +94,12 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { .year = mp_obj_get_int(items[0]), .month = mp_obj_get_int(items[1]), .day = mp_obj_get_int(items[2]), - .dotw = mp_obj_get_int(items[3]), .hour = mp_obj_get_int(items[4]), .min = mp_obj_get_int(items[5]), .sec = mp_obj_get_int(items[6]), }; + // Deliberately ignore the weekday argument and compute the proper value + t.dotw = timeutils_calc_weekday(t.year, t.month, t.day); if (!rtc_set_datetime(&t)) { mp_raise_OSError(MP_EINVAL);