Conversation
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.
There was a problem hiding this comment.
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_jdmethod 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.
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cal_from_jdfunction that converts Julian Day Count to a supported calendarCloses #13
Test plan