Skip to content

Refactor daysInMonth to use lookup table for static values#16

Merged
mjradwin merged 1 commit into
mainfrom
claude/optimize-daysInMonth-Hkj0J
Apr 30, 2026
Merged

Refactor daysInMonth to use lookup table for static values#16
mjradwin merged 1 commit into
mainfrom
claude/optimize-daysInMonth-Hkj0J

Conversation

@mjradwin

Copy link
Copy Markdown
Member

Summary

Refactored the daysInMonth function to improve readability and performance by using a lookup table for months with static day counts, while maintaining the same logic for variable-length months.

Key Changes

  • Introduced STATIC_DAYS_IN_MONTH constant array that maps each Hebrew month to its day count (0 indicates variable length)
  • Simplified daysInMonth logic by first checking the lookup table for static values
  • Replaced the switch statement and complex conditional logic with a more concise implementation
  • Preserved all existing behavior for variable-length months (CHESHVAN, KISLEV, ADAR_I)

Implementation Details

  • The lookup table uses 0 as a sentinel value to indicate months whose length depends on the year properties
  • For static months, the function returns immediately from the lookup table
  • For variable months, the function applies the appropriate year-dependent logic (leap year check, long Cheshvan check, short Kislev check)
  • This approach reduces code duplication and makes the month length rules more explicit and maintainable

https://claude.ai/code/session_01VTWaREoLypCvHzEkkTWzWm

Replace the switch + chained || with an array lookup for the 10 months
whose length is fixed, falling through to a direct dispatch for the 3
year-dependent months (CHESHVAN, KISLEV, ADAR_I).
@mjradwin mjradwin merged commit 68d71c4 into main Apr 30, 2026
4 checks passed
@mjradwin mjradwin deleted the claude/optimize-daysInMonth-Hkj0J branch April 30, 2026 19:37
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