Skip to content

Truncating day(byAdding:) for month and year rolling#10

Merged
drekka merged 2 commits into
mainfrom
develop
Mar 4, 2026
Merged

Truncating day(byAdding:) for month and year rolling#10
drekka merged 2 commits into
mainfrom
develop

Conversation

@drekka
Copy link
Copy Markdown
Owner

@drekka drekka commented Mar 4, 2026

Summary

  • Rewrote day(byAdding:) to use modular arithmetic for month rolling and direct year adjustment, with day clamping to handle shorter months (e.g. Jan 31 + 1 month = Feb 28)
  • Replaced day-count walking algorithm with truncating approach for correct and predictable results
  • Added comprehensive tests for day clamping edge cases (leap years, shorter months, zero addition)

Test plan

  • All 98 tests pass via swift test
  • Month clamping forward (Jan 31 + 1 month = Feb 28/29)
  • Month clamping backward (Mar 31 - 1 month = Feb 28/29)
  • Year clamping for leap day (Feb 29 + 1 year = Feb 28)
  • Adding zero returns same day

🤖 Generated with Claude Code

drekka and others added 2 commits March 4, 2026 15:07
…y, fix macro deprecations

- Day init(year:month:day:) now throws DayError for invalid inputs
- Day stores year, month, dayOfMonth directly alongside daysSince1970
- Removed DayComponents and CalendarDay — CalendarDays is now
  OrderedDictionary<Day, [Day]>
- Fixed deprecated MemberMacro expansion signatures (added conformingTo)
- Updated README and CLAUDE.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Month and year rolling now uses modular arithmetic to calculate the
target month/year, then clamps the day to the last day of that month.
This means Jan 31 + 1 month = Feb 28 (or 29) instead of overshooting
into March, and Feb 29 + 1 year = Feb 28 in non-leap years.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@drekka drekka merged commit 1cad15d into main Mar 4, 2026
2 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.

1 participant