Skip to content

Implement cal_from_jd function#34

Merged
roukmoute merged 5 commits intomasterfrom
add-cal-from-jd
Jan 17, 2026
Merged

Implement cal_from_jd function#34
roukmoute merged 5 commits intomasterfrom
add-cal-from-jd

Conversation

@roukmoute
Copy link
Copy Markdown
Owner

Summary

  • Implements cal_from_jd function that converts Julian Day Count to a supported calendar
  • Returns an array with 9 keys: date, month, day, year, dow, abbrevdayname, dayname, abbrevmonth, monthname
  • Supports all 4 calendar types: Gregorian, Julian, Jewish, and French Republican
  • Handles edge cases like Jewish calendar year 0 (returns null dow per bug71894)
  • Handles integer overflow for large Julian Day values

Closes #13

Test plan

  • Verify all tests pass in CI
  • Tests based on PHP source:
    • cal_from_jd.phpt
    • cal_from_jd_error1.phpt
    • bug71894.phpt
    • bug53574_2.phpt (64-bit Julian overflow)
    • bug55797_2.phpt (64-bit Gregorian overflow)

Converts a Julian Day Count to a supported calendar (Gregorian, Julian,
Jewish, or French Republican). Returns an array with date, month, day,
year, dow, abbrevdayname, dayname, abbrevmonth, and monthname.

Based on PHP source tests:
- cal_from_jd.phpt
- cal_from_jd_error1.phpt
- bug71894.phpt (Jewish calendar year 0 returns null dow)
- bug53574_1/2.phpt (Julian overflow handling)
- bug55797_1/2.phpt (Gregorian overflow handling)

Closes #13
Prevents integer overflow for very large Julian Day values by checking
bounds before performing arithmetic operations, matching PHP source behavior.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the cal_from_jd function that converts Julian Day Count to a supported calendar system (Gregorian, Julian, Jewish, or French Republican). The implementation handles all calendar types correctly, including edge cases such as Jewish calendar year 0 (which returns null for day of week) and integer overflow scenarios on 64-bit systems.

Changes:

  • Implements cal_from_jd method in the Calendar class with support for all four calendar types
  • Adds comprehensive test coverage based on PHP source test cases
  • Updates README to document the new function

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

File Description
src/Calendar.php Implements cal_from_jd method with calendar conversion logic and special handling for Jewish year 0
runtime/bootstrap.php Adds wrapper function for cal_from_jd
test/Spec/CalendarSpec.php Adds comprehensive tests covering all calendar types, edge cases, and overflow scenarios
README.md Documents the new cal_from_jd function in the available functions list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Calendar.php Outdated
Comment thread src/Calendar.php Outdated
Comment thread src/Calendar.php Outdated
- Add sdnToFrench method to French class for consistency with other calendars
- Remove default case in cal_from_jd switch (calendar is already validated)
- Reuse jddayofweek method instead of duplicating dow calculation logic
- Update jdmonthname to use sdnToFrench for consistency
@roukmoute roukmoute merged commit 15e521a into master Jan 17, 2026
14 checks passed
@roukmoute roukmoute deleted the add-cal-from-jd branch January 17, 2026 01:54
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.

Implement cal_from_jd

2 participants