Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(daysUntil): use larger integer type for proper underflow
Use a larger integer type for proper underflow in Weekday.daysUntil. This is because the algorithm assumes a larger integer than a u3. It's relying on underflow to work: https://howardhinnant.github.io/date_algorithms.html#weekday_difference For Wednesday -> Monday, the math is: Monday (1) - Wednesday (3) = -2 -2 as a u3 = 6, but we are checking if the difference is <= 6 so we return 6 instead of adding 7. If we do this as a u8, -2 is 254. Add 7 with overflow, and we get 5. Note that this exposed a bug in the DST calculation for fixed posix timezones as well. The `days` var suffered from an off-by-one bug. It is supposed to be the day of the month (1-31), NOT a zero-indexed day. Fixes: #8
- Loading branch information