flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

weekday not set in datetime_timestamp_to_datetime

Open mdaskalov opened this issue 1 year ago • 1 comments
trafficstars

Describe the bug.

In the function datetime_timestamp_to_datetime (in the file /lib/datatime/datatime.c of release 0.99.0-rc) the datatime->weekday is left unchanged / uninitialized.

It is also present in the function furi_hal_rtc_datetime_to_timestamp of the current release (0.98.3) but in different file: fury_hal_rtc.c.

You can use following to update it (01.01.1970 was a Thursday):

datatime->weekday = ((days + 4) % 7) + 1;

Reproduction

Exemple test code:

    uint32_t test_value = 1709748421;

    DateTime datetime = {0};
    datetime_timestamp_to_datetime(test_value, &datetime);

    mu_assert_int_eq(datetime.weekday, 3);

Target

f7-firmware-D

Logs

No response

Anything else?

No response

mdaskalov avatar Mar 06 '24 18:03 mdaskalov

To add to that, the current layout of DateTime is sub-optimal, with the size of 10 bytes. Had weekday been moved ahead of year, it'd fit in the padding added there to align year to 2 bytes and reduce the size of this structure to 8 bytes.

Consider moving weekday before day, so it stays grouped logically while also not generating 2 bytes of padding.

CookiePLMonster avatar Mar 06 '24 21:03 CookiePLMonster

struct packing is coming later

skotopes avatar Mar 11 '24 13:03 skotopes