Skip to content

Conversation

@dickermoshe
Copy link
Contributor

@dickermoshe dickermoshe commented Nov 11, 2025

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 JewishDate

JewishDate now 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 an IllegalArgumentException for invalid day values.

2. Standardized UTC Time Zone in getGregorianCalendar()

The getGregorianCalendar() method in JewishDate now returns a Calendar instance with the following standardized values:

  • Time zone: Set to UTC (instead of the system default time zone)
  • Time fields: Hours, minutes, seconds, and milliseconds are set to 0 (instead of the current system time)

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_DAY constant in YerushalmiYomiCalculator now 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 Calendar instances 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 API

Replaced all instances of Calendar.add(Calendar.DAY_OF_MONTH, n) with a helper method that converts to ZonedDateTime for date arithmetic. This change addresses numerous inaccuracies in Java's legacy java.util.Calendar API, particularly around daylight saving time transitions and month boundaries.

6. Corrected getLocalMeanTimeOffset() Implementation

Updated the getLocalMeanTimeOffset() method to:

  • Account for the time zone offset at the specific location
  • Use the modern Java date-time API (java.time) instead of the legacy API
  • Fix incorrect offset calculations that existed in the old implementation

7. Modernized getJulianDay() Implementation

Updated getJulianDay() to use ZonedDateTime for 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 prevent NullPointerException when null arguments are passed.

8. Null return from in getDafYomiYerushalmi() on transition dates

This method would return null on the dates of a brand new cycle. This PR fixes that.

9. Forwarding a JewishDate by a month return invalid date

If 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

  • Add tests for each of these changes
  • Investigate whether these changes are considered breaking

@dickermoshe dickermoshe marked this pull request as draft November 11, 2025 03:55
@dickermoshe dickermoshe changed the title improve naive time zone conversion Various Bug Fixes Dec 7, 2025
@dickermoshe dickermoshe changed the title Various Bug Fixes Fix Date Handling and Time Zone Issues Dec 7, 2025
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.

1 participant