Skip to content

Comments

Fix bugs in algorithms ported from Howard Hinnant's date_algorithms#50

Merged
rockorager merged 1 commit intorockorager:mainfrom
dvorakluk:main
Nov 26, 2025
Merged

Fix bugs in algorithms ported from Howard Hinnant's date_algorithms#50
rockorager merged 1 commit intorockorager:mainfrom
dvorakluk:main

Conversation

@dvorakluk
Copy link
Contributor

This PR fixes several issues in the Zig port of the algorithms from https://howardhinnant.github.io/date_algorithms.html.

The original C++ algorithms use workarounds for truncated division with negative numerators. These workarounds are unnecessary (actually incorrect) when porting to Zig using floored division. The added range assertions will trigger for negative Days or negative years, catching these cases.

Similar issue affect weekdayFromDays when called with negative Days values. The previous implementation also caused panics for all Days < -4 (except Saturdays).

The errors in civilFromDays were previously masked because subsequent calculations compensated for them. I've added expectations in tests that trigger the new range assertions because of the lack of better tests possibilities in this case.

@rockorager
Copy link
Owner

This is great, thank you!

@rockorager rockorager merged commit b01d405 into rockorager:main Nov 26, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants