Skip to content

Fix invalid month overflow in totalDaysInMonth - #4

Merged
techguy0711 merged 2 commits into
mainfrom
copilot/fix-github-actions-job
Jul 5, 2026
Merged

Fix invalid month overflow in totalDaysInMonth#4
techguy0711 merged 2 commits into
mainfrom
copilot/fix-github-actions-job

Conversation

Copilot AI commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

DateComponents with month: 13 silently overflows to January of the following year instead of returning nil, causing totalDaysInMonth to return 31 for invalid months rather than the expected 0.

Changes

  • Date.startOfMonth(for:of:using:) — added an early guard (1...12).contains(month) check that returns nil for out-of-range months before constructing DateComponents, preventing the calendar overflow
static func startOfMonth(for month: Int, of year: Int, using calendar: Calendar = .current) -> Date? {
    guard (1...12).contains(month) else { return nil }
    return DateComponents(calendar: calendar, year: year, month: month).date
}

This nil propagates through the existing guard in totalDaysInMonth, making it return 0 as intended.

Copilot AI changed the title [WIP] Fix failing GitHub Actions job Build & test MattiUI package Fix invalid month overflow in totalDaysInMonth Jul 5, 2026
Copilot AI requested a review from techguy0711 July 5, 2026 20:31
@techguy0711
techguy0711 marked this pull request as ready for review July 5, 2026 20:35
@techguy0711
techguy0711 merged commit 0f9b793 into main Jul 5, 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.

2 participants