Fix Date Handling and Time Zone Issues #247
Draft
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.
This PR addresses several critical bugs and inconsistencies in KosherJava related to date validation, time zone handling, and calendar calculations.
WIP
This PR is a Draft. If more issues are bugs are found, this PR will be updated with fixes for them.
Changes
1. Enhanced Date Validation in
JewishDateJewishDatenow properly validates that the day of the month does not exceed the maximum for that specific month and year. Previously, validation only checked that the day was less than 30, which was inadequate since many Jewish months have fewer than 30 days. The constructor now throws anIllegalArgumentExceptionfor invalid day values.2. Standardized UTC Time Zone in
getGregorianCalendar()The
getGregorianCalendar()method inJewishDatenow returns aCalendarinstance with the following standardized values:This ensures consistent, predictable behavior regardless of the system's time zone and time of day.
3. Fixed Yerushalmi Yomi Start Date Time Zone
The
DAF_YOMI_START_DAYconstant inYerushalmiYomiCalculatornow explicitly sets its time zone to UTC instead of using the system default time zone, ensuring consistent calculations across all time zones.4. UTC-Based Yerushalmi Yomi Calculations
All
Calendarinstances used in Yerushalmi Yomi calculations now use UTC time zone, eliminating time zone-related calculation errors.5. Replaced Legacy
Calendar.add()with Modern Date-Time APIReplaced all instances of
Calendar.add(Calendar.DAY_OF_MONTH, n)with a helper method that converts toZonedDateTimefor date arithmetic. This change addresses numerous inaccuracies in Java's legacyjava.util.CalendarAPI, particularly around daylight saving time transitions and month boundaries.6. Corrected
getLocalMeanTimeOffset()ImplementationUpdated the
getLocalMeanTimeOffset()method to:java.time) instead of the legacy API7. Modernized
getJulianDay()ImplementationUpdated
getJulianDay()to useZonedDateTimefor extracting day, month, and year values, fixing multiple issues caused by the legacy Java standard library's date handling.8. Null Safety in
getMoladBasedTime()Added null-argument handling to
getMoladBasedTime()to preventNullPointerExceptionwhen null arguments are passed.8. Null return from in
getDafYomiYerushalmi()on transition datesThis method would return
nullon the dates of a brand new cycle. This PR fixes that.9. Forwarding a
JewishDateby a month return invalid dateIf adding a month to a date would result in an invalid date (Nissan 30 -> Iyar 30), we return the last day of that month (Iyar 29).
Checklist