Skip to content

sys/rtc_utils: correctly handle units rolling under#22357

Open
HendrikVE wants to merge 2 commits into
RIOT-OS:masterfrom
HendrikVE:hendrik/sys/rtc_utils/handle-rolling-under-units
Open

sys/rtc_utils: correctly handle units rolling under#22357
HendrikVE wants to merge 2 commits into
RIOT-OS:masterfrom
HendrikVE:hendrik/sys/rtc_utils/handle-rolling-under-units

Conversation

@HendrikVE

Copy link
Copy Markdown
Contributor

Contribution description

The existing implementation of rtc_tm_normalize would leave you e.g. with negative seconds if the input tm_sec was negative. In addition, the hack of checking for t->tm_mday == 0 was removed, as setting tm_mday to 0 is not the correct behaviour. Since the range is given as [1 to 31] by definition tm_mday=0 must roll under to the last day of the previous month. For the same reason rtc_localtime was adapted to set t->tm_mday = 1; instead of using 0 implicitly.

Testing procedure

I added relevant test cases to tests/unittests/tests-rtc/tests-rtc.c. I checked the values for tm_target manually by using a calendar. Please check this part for yourself. I could have made a mistake.

Issues/PRs references

None

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • GitHub Copilot pointed me to this issue while I was debugging a higher level module.

@github-actions github-actions Bot added Area: tests Area: tests and testing framework Area: sys Area: System labels Jun 8, 2026
@HendrikVE HendrikVE requested review from benpicco, Copilot and maribu and removed request for Teufelchen1, Copilot and miri64 June 8, 2026 14:54
@crasbe crasbe added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 8, 2026
Comment thread tests/unittests/tests-rtc/tests-rtc.c Outdated
.tm_hour = 12,
.tm_mday = 20,
.tm_mon = TM_MON_DEC,
.tm_year = 120 -1,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.tm_year = 120 -1,
.tm_year = 120 - 1,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure though why you don't use 119 as in the tm_target above.

The tm_target below also has 120 - 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make the year roll under more explicit this way, but I can set all three to 119 if that's less confusing.

Comment thread tests/unittests/tests-rtc/tests-rtc.c Outdated
@riot-ci

riot-ci commented Jun 8, 2026

Copy link
Copy Markdown

Murdock results

✔️ PASSED

aa9f45c sys/rtc_utils: correctly handle units rolling under

Success Failures Total Runtime
11124 0 11124 11m:37s

Artifacts

@HendrikVE HendrikVE force-pushed the hendrik/sys/rtc_utils/handle-rolling-under-units branch from 9d82482 to 2b4f91f Compare June 8, 2026 15:45
@crasbe

crasbe commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Perhaps you can adapt the title and commit messages to fit our Commit Conventions (no "feat()" and "fix()", just "sys/rtc_utils: ...".

@HendrikVE

Copy link
Copy Markdown
Contributor Author

Perhaps you can adapt the title and commit messages to fit our Commit Conventions (no "feat()" and "fix()", just "sys/rtc_utils: ...".

Whoops :D Yes, of course. Seems like I was still in office mode using another convention.

@HendrikVE HendrikVE force-pushed the hendrik/sys/rtc_utils/handle-rolling-under-units branch from 2b4f91f to aa9f45c Compare June 9, 2026 09:34
@HendrikVE HendrikVE changed the title fix(sys/rtc_utils): correctly handle units rolling under sys/rtc_utils: correctly handle units rolling under Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants