Skip to content

HebrewDateFormatter.formatHebrewNumber: support numbers up to 999,999 (Jewish years past 9999) - #304

Merged
KosherJava merged 1 commit into
KosherJava:masterfrom
Elyahu41:fix/hebrew-numbers-above-9999
Nov 6, 2026
Merged

KosherJava merged 1 commit into
KosherJava:masterfrom
Elyahu41:fix/hebrew-numbers-above-9999

Conversation

@Elyahu41

@Elyahu41 Elyahu41 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

The issue

HebrewDateFormatter.formatHebrewNumber(int) only accepts 0 to 9999. As a result, format() (Hebrew format) throws for every date whose Jewish year is 10,000 or more, which is any Gregorian date from the year 6240 on.

The edge case

Hebrew formatting of a Jewish year of 10,000 or more. JewishCalendar itself handles these dates fine (new JewishCalendar(LocalDate.of(6500, 1, 1)).getJewishYear() is 10,260); only the formatting fails. This is far in the future, but the date classes accept these dates and code that iterates or computes dates generically can reach them. The same limit also applies to any other caller formatting a number of 10,000 or more.

What happens

HebrewDateFormatter formatter = new HebrewDateFormatter();
formatter.setHebrewFormat(true);
formatter.format(new JewishCalendar(LocalDate.of(6500, 1, 1)));
// IllegalArgumentException: numbers > 9999 can't be formatted

The thousands are written with jOnes[number / 1000], a 10-letter array, which is why the method rejects anything over 9999.

The fix

Write the thousands with the same letters as any other number: hundreds, tens and ones, with ט״ו / ט״ז for 15 and 16, followed by the geresh. A new private formatThousands helper does this, and the limit moves to 999,999.

Number Default With long years
10,000 י׳ אלפים י׳ אלפים
12,345 שמ״ה (thousands dropped, as for 5786) יב׳ שמ״ה

Output for every number up to 9999 is unchanged; the thousands 1 to 9 are still a single letter. The Javadoc describes the new range.

Tests

HebrewNumberAbove9999Test checks:

  • Unchanged output for 5000, 5786 and 9999 (short and long years).
  • Results from 10,000 up to 999,999, with and without gershayim.
  • 1,000,000 is still rejected.
  • format() of a date in Jewish year 10,260.

The new cases fail without the change.


🤖 Generated with Claude Code

https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU

The thousands digit indexed a 10 letter array, so numbers over 9999 were
rejected and format() threw IllegalArgumentException for every date whose
Jewish year is over 9999 (Gregorian years from 6240). The thousands are now
written with the same letters as other numbers (10,000 = "י׳ אלפים",
12,345 = "יב׳ שמ״ה" with long years). Output up to 9999 is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU
@KosherJava
KosherJava merged commit 9fd771c into KosherJava:master Nov 6, 2026
2 of 3 checks passed
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.

2 participants