Skip to content

Fix getLocalDate() for dates before January 1, 0001 - #308

Open
dickermoshe wants to merge 1 commit into
KosherJava:masterfrom
dickermoshe:fix-abs-date-to-date-before-year-1
Open

dickermoshe wants to merge 1 commit into
KosherJava:masterfrom
dickermoshe:fix-abs-date-to-date-before-year-1

Conversation

@dickermoshe

Copy link
Copy Markdown
Contributor

Fixes #307.

absDateToDate guessed the year with Math.floorDiv(absDate, 366) and searched forward. For a negative absDate, dividing by 366 rounds toward zero, so the guess can be later than the correct year. The forward search then can't reach it, and LocalDate.of throws. A JewishDate built with new JewishDate(long molad) from an early molad reaches this through getLocalDate().

This divides by 365 when absDate is not positive. That guess is never after the correct year, so the forward search finds it. Positive dates use the same guess as before.

Tests

The new UT_GregorianDateConversion checks the following:

  • the molad of Tishrei 3000, which threw Invalid value for DayOfMonth (valid values 1 - 28/31): -129 before this change and now returns August 24, 762 BCE (-0761-08-24)
  • Rosh Hashana of the year 1, on September 7, 3761 BCE
  • the days around January 1, 0001
  • leap days before and after year 1, including century years that are and are not leap years
  • the first and last day of every year from 3761 BCE to 9999, compared against java.time

Three of the new tests fail without the fix. The full suite passes with it.

absDateToDate guessed the year with floorDiv(absDate, 366) and searched
forward. For a negative absDate that guess can be later than the correct
year, so LocalDate.of threw for a JewishDate built from an early molad.
Divide by 365 when absDate is not positive.

Fixes KosherJava#307
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.

getLocalDate() throws for a JewishDate built from an early molad

1 participant