Class HebrewDateFormatter

java.lang.Object
com.kosherjava.zmanim.hebrewcalendar.HebrewDateFormatter

public class HebrewDateFormatter extends Object
The HebrewDateFormatter class formats a JewishDate. The class formats Jewish dates, numbers, Daf Yomi (Bavli and Yerushalmi), the Omer, Parshas Hashavua (including the special parshiyos of Shekalim, Zachor, Parah and Hachodesh), Yomim Tovim in Hebrew or Latin chars, and has various settings. Sample full date output includes (using various options):
  • 21 Shevat, 5729
  • כא שבט תשכט
  • כ״א שבט ה׳תשכ״ט
  • כ״א שבט תש״פ or כ״א שבט תש״ף
  • כ׳ שבט ו׳ אלפים
Author:
© Eliyahu Hershfeld 2011 - 2026
See Also:
  • Field Details

  • Constructor Details

    • HebrewDateFormatter

      Default constructor sets the EnumMaps of Hebrew and default transliterated parshiyos.
  • Method Details

    • isLongWeekFormat

      public boolean isLongWeekFormat()
      Returns if the formatDayOfWeek(JewishDate) will use the long format such as ראשון or short such as א when formatting the day of week in Hebrew.
      Returns:
      the longWeekFormat
      See Also:
    • setLongWeekFormat

      public void setLongWeekFormat(boolean longWeekFormat)
      Setting to control if the formatDayOfWeek(JewishDate) will use the long format such as ראשון or short such as א when formatting the day of week in Hebrew.
      Parameters:
      longWeekFormat - the longWeekFormat to set
    • getTransliteratedShabbosDayOfWeek

      Returns the day of Shabbos transliterated into Latin chars. The default uses Ashkenazi pronunciation "Shabbos". This can be overwritten using the setTransliteratedShabbosDayOfWeek(String). It is uesd by formatDayOfWeek(JewishDate).
      Returns:
      the transliteratedShabbos. The default list of months uses Ashkenazi pronunciation "Shabbos".
      See Also:
    • setTransliteratedShabbosDayOfWeek

      public void setTransliteratedShabbosDayOfWeek(String transliteratedShabbos)
      Setter to override the default transliterated name of "Shabbos" to alternate spelling such as "Shabbat" used by the formatDayOfWeek(JewishDate).
      Parameters:
      transliteratedShabbos - the transliteratedShabbos to set
      See Also:
    • getTransliteratedHolidayList

      Returns the array of Yomim Tovim (holidays) transliterated into Latin chars. This is used by the formatYomTov(JewishCalendar) when formatting the Yom Tov String. The default list of months usesnAshkenazi pronunciation in typical American English spelling. The default list is currently ["Erev Pesach", "Pesach", "Chol Hamoed Pesach", "Pesach Sheni", "Erev Shavuos", "Shavuos", "Seventeenth of Tammuz", "Tishah B'Av", "Tu B'Av", "Erev Rosh Hashana", "Rosh Hashana", "Fast of Gedalyah", "Erev Yom Kippur", "Yom Kippur", "Erev Succos", "Succos", "Chol Hamoed Succos", "Hoshana Rabbah", "Shemini Atzeres", "Simchas Torah", "Erev Chanukah", "Chanukah", "Tenth of Teves", "Tu B'Shvat", "Fast of Esther", "Purim", "Shushan Purim",m"Purim Katan", "Rosh Chodesh", "Yom HaShoah", "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim", "Lag B'Omer", "Shushan Purim Katan", "Isru Chag"].
      Returns:
      the array of transliterated Yomim Tovim (holidays).
      See Also:
    • setTransliteratedHolidayList

      public void setTransliteratedHolidayList(String[] transliteratedHolidays)
      Sets the array of Yomim Tovim (holidays) transliterated into Latin chars. This is used by the formatYomTov(JewishCalendar) when formatting the Yom Tov String. The list uses the following order and uses the spelling as follows. ["Erev Pesach", "Pesach", "Chol Hamoed Pesach", "Pesach Sheni", "Erev Shavuos", "Shavuos", "Seventeenth of Tammuz", "Tishah B'Av", "Tu B'Av", "Erev Rosh Hashana", "Rosh Hashana", "Fast of Gedalyah", "Erev Yom Kippur", "Yom Kippur", "Erev Succos", "Succos", "Chol Hamoed Succos", "Hoshana Rabbah", "Shemini Atzeres", "Simchas Torah", "Erev Chanukah", "Chanukah", "Tenth of Teves", "Tu B'Shvat", "Fast of Esther", "Purim", "Shushan Purim", "Purim Katan", "Rosh Chodesh", "Yom HaShoah", "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim", "Lag B'Omer", "Shushan Purim Katan", "Isru Chag"].
      Parameters:
      transliteratedHolidays - the transliteratedHolidays to set. Ensure that the sequence exactly matches the list returned by the default
    • formatYomTov

      public String formatYomTov(JewishCalendar jewishCalendar)
      Formats the Yom Tov (holiday) in Hebrew or transliterated Latin characters.
      Parameters:
      jewishCalendar - the JewishCalendar
      Returns:
      the formatted Yom Tov (holiday) or an empty String if the day is not a Yom Tov (holiday).
      See Also:
    • formatRoshChodesh

      public String formatRoshChodesh(JewishCalendar jewishCalendar)
      Formats a day as Rosh Chodesh in the format of in the format of ראש חודש שבט or Rosh Chodesh Shevat. If it is not Rosh Chodesh, an empty String will be returned.
      Parameters:
      jewishCalendar - the JewishCalendar
      Returns:
      The formatted String in the format of ראש חודש שבט or Rosh Chodesh Shevat. If it is not Rosh Chodesh, an empty String will be returned.
    • isHebrewFormat

      public boolean isHebrewFormat()
      Returns if the formatter is set to use Hebrew formatting in the various formatting methods.
      Returns:
      the hebrewFormat
      See Also:
    • setHebrewFormat

      public void setHebrewFormat(boolean hebrewFormat)
      Sets the formatter to format in Hebrew in the various formatting methods.
      Parameters:
      hebrewFormat - the hebrewFormat to set
      See Also:
    • getHebrewOmerPrefix

      Returns the Hebrew Omer prefix. By default it is the letter ב producing בעומר, but it can be set to ל to produce לעומר (or any other prefix) using the setHebrewOmerPrefix(String).
      Returns:
      the hebrewOmerPrefix
      See Also:
    • setHebrewOmerPrefix

      public void setHebrewOmerPrefix(String hebrewOmerPrefix)
      Method to set the Hebrew Omer prefix. By default it is the letter ב producing בעומר, but it can be set to ל to produce לעומר (or any other prefix).
      Parameters:
      hebrewOmerPrefix - the hebrewOmerPrefix to set. You can use the Unicode \u05DC to set it to ל.
      See Also:
    • getHebrewMonthList

      Returns the Hebrew array of months in the order of ‏["ניסן", "אייר", "סיון", "תמוז", "אב", "אלול", "תשרי", "חשון", "כסלו", "טבת", "שבט", "אדר", "אדר ב", "אדר א"]. This list has a length of 14 starting with "ניסן" and ending with 3 variations of Adar - "אדר", "אדר ב", "אדר א".
      Returns:
      the array of Hebrew months.
      See Also:
    • setHebrewMonthList

      public void setHebrewMonthList(String[] hebrewMonths)
      Setter method to allow overriding of the default list of Hebrew month names. This allows changing things such as the default month name of חשון to מרחשון, etc. This list expects a length of 14 starting with "ניסן" and ending with 3 variations of Adar - "אדר", "אדר ב", "אדר".
      Parameters:
      hebrewMonths - the array of Hebrew months beginning in "ניסן" and ending in "אדר", "אדר ב", "אדר א"
      See Also:
    • getTransliteratedMonthList

      Returns the array of months transliterated into Latin chars. The default list of months uses Ashkenazi pronunciation in typical American English spelling. This list has a length of 14 with 3 variations for Adar - "Adar", "Adar II", "Adar I". The array of months beginn in Nissan and end in "Adar", "Adar II", "Adar I". The default list is ["Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Cheshvan", "Kislev", "Teves", "Shevat", "Adar", "Adar II", "Adar I"].
      Returns:
      the array of 14 month names beginning in Nissan and ending in "Adar", "Adar II", "Adar I".
      See Also:
    • setTransliteratedMonthList

      public void setTransliteratedMonthList(String[] transliteratedMonths)
      Setter method to allow overriding of the default list of months transliterated into Latin chars. The default list uses Ashkenazi American English transliteration. The array of 14 transliterated month names begin in "Nissan" and end in the 3 Adar variations - "Adar", "Adar II", "Adar I". The default list is ["Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Cheshvan", "Kislev", "Teves", "Shevat", "Adar", "Adar II", "Adar I"].
      Parameters:
      transliteratedMonths - the array of 14 month names beginning in Nissan and ending in "Adar", "Adar II", "Adar I".
      See Also:
    • formatDayOfWeek

      public String formatDayOfWeek(JewishDate jewishDate)
      Formats the day of week. If Hebrew formatting is set, it will display in the format ראשון etc. If Hebrew formatting is not in use it will return it in the format of Sunday etc. There are various formatting options that will affect the output.
      Parameters:
      jewishDate - the JewishDate Object
      Returns:
      the formatted day of week
      See Also:
    • isUseGershGershayim

      public boolean isUseGershGershayim()
      Returns whether the class is set to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers. When true and output would look like כ״א שבט תש״כ (or כ״א שבט תש״ך). When set to false, this output would display as כא שבט תשכ.
      Returns:
      true if set to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers.
    • setUseGershGershayim

      public void setUseGershGershayim(boolean useGershGershayim)
      Sets whether to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers. The default value is true and output would look like כ״א שבט תש״כ (or כ״א שבט תש״ך). When set to false, this output would display as כא שבט תשכ (or כא שבט תשך). Single digit days or month or years such as כ׳ שבט ו׳ אלפים show the use of the Geresh.
      Parameters:
      useGershGershayim - set this to false to omit the Geresh ׳ and Gershayim ״ in formatting
    • isUseFinalFormLetters

      public boolean isUseFinalFormLetters()
      Returns whether the class is set to use the מנצפ״ך letters when formatting years ending in 20, 40, 50, 80 and 90 to produce תש״פ if false or תש״ף if true. Traditionally non-final form letters are used, so the year 5780 would be formatted as תש״פ if the default false is used here. If this returns true, the format תש״ף would be used.
      Returns:
      true if set to use final form letters when formatting Hebrew years. The default value is false.
    • setUseFinalFormLetters

      public void setUseFinalFormLetters(boolean useFinalFormLetters)
      When formatting a Hebrew Year, traditionally years ending in 20, 40, 50, 80 and 90 are formatted using non-final form letters for example תש״פ for the year 5780. Setting this to true (the default is false) will use the final form letters for מנצפ״ך and will format the year 5780 as תש״ף.
      Parameters:
      useFinalFormLetters - Set this to true to use final form letters when formatting Hebrew years.
    • isUseLongHebrewYears

      public boolean isUseLongHebrewYears()
      Returns whether the class is set to use the thousands digit when formatting. When formatting a Hebrew Year, traditionally the thousands digit is omitted and output for a year such as 5729 (1969 Gregorian) would be calculated for 729 and format as תשכ״ט. When set to true the long format year such as ה׳ תשכ״ט for 5729/1969 is returned.
      Returns:
      true if set to use the thousands digit when formatting Hebrew dates and numbers.
    • setUseLongHebrewYears

      public void setUseLongHebrewYears(boolean useLongHebrewYears)
      When formatting a Hebrew Year, traditionally the thousands digit is omitted and output for a year such as 5729 (1969 Gregorian) would be calculated for 729 and format as תשכ״ט. This method allows setting this to true to return the long format year such as ה׳ תשכ״ט for 5729/1969.
      Parameters:
      useLongHebrewYears - Set this to true to use the long formatting
    • format

      public String format(JewishDate jewishDate)
      Formats the Jewish date. If the formatter is set to Hebrew, it will format in the form, "day Month year" for example כ״א שבט תשכ״ט, and the format "21 Shevat, 5729" if not.
      Parameters:
      jewishDate - the JewishDate to be formatted
      Returns:
      the formatted date. If the formatter is set to Hebrew, it will format in the form, "day Month year" for example כ״א שבט תשכ״ט, and the format "21 Shevat, 5729" if not.
    • formatMonth

      public String formatMonth(JewishDate jewishDate)
      Returns a string of the current Hebrew month such as "Tishrei". Returns a string of the current Hebrew month such as "אדר ב׳".
      Parameters:
      jewishDate - the JewishDate to format
      Returns:
      the formatted month name
      See Also:
    • formatOmer

      public String formatOmer(JewishCalendar jewishCalendar)
      Returns a String of the Omer day in the form ל״ג בעומר if Hebrew Format is set, or "Omer X" or "Lag B'Omer" if not. An empty string if there is no Omer this day.
      Parameters:
      jewishCalendar - the JewishCalendar to be formatted
      Returns:
      a String of the Omer day in the form or an empty string if there is no Omer this day. The default formatting has a ב׳ prefix that would output בעומר, but this can be set via the setHebrewOmerPrefix(String) method to use a ל and output ל״ג לעומר.
      See Also:
    • getFormattedKviah

      public String getFormattedKviah(int jewishYear)
      Returns the kviah in the traditional 3 letter Hebrew format where the first letter represents the day of week of Rosh Hashana, the second letter represents the lengths of Cheshvan and Kislev (Shelaimim , Kesidran or Chaserim) and the 3rd letter represents the day of week of Pesach. For example 5729 (1969) would return בשה (Rosh Hashana on Monday, Shelaimim, and Pesach on Thursday), while 5771 (2011) would return השג (Rosh Hashana on Thursday, Shelaimim, and Pesach on Tuesday).
      Parameters:
      jewishYear - the Jewish year
      Returns:
      the Hebrew String such as בשה for 5729 (1969) and השג for 5771 (2011).
    • formatDafYomiBavli

      Formats the Daf Yomi Bavli in the format of "עירובין נ״ב" in Hebrew, or the transliterated format of "Eruvin 52".
      Parameters:
      daf - the Daf to be formatted.
      Returns:
      the formatted daf.
    • formatDafYomiYerushalmi

      Formats the Daf Yomi Yerushalmi in the format of "עירובין נ״ב" in Hebrew, or the transliterated format of "Eruvin 52".
      Parameters:
      daf - the Daf to be formatted.
      Returns:
      the formatted daf.
    • formatHebrewNumber

      public String formatHebrewNumber(int number)
      Returns a Hebrew formatted string of a number. The method can calculate from 0 to 9999.
      • Single digit numbers such as 3, 30 and 100 will be returned with a ׳ (Geresh) appended as at the end. For example ג׳, ל׳ and ק׳
      • multi digit numbers such as 21 and 769 will be returned with a ״ (Gershayim) between the second to last and last letters. For example כ״א, תשכ״ט
      • 15 and 16 will be returned as ט״ו and ט״ז
      • Single digit numbers (years assumed) such as 6000 (%1000=0) will be returned as ו׳ אלפים
      • 0 will return אפס
      Parameters:
      number - the number to be formatted. It will trow an IllegalArgumentException if the number is < 0 or > 9999.
      Returns:
      the Hebrew formatted number such as תשכ״ט
      See Also:
    • getTransliteratedParshiosList

      Returns the map of transliterated parshiyos used by this formatter. This list using the default Ashkenazi pronunciation. This list can be overridden (for Sephardi English transliteration for example) by setting the setTransliteratedParshiosList(EnumMap). The list includes double and special parshiyos in the following order and spelling "Bereshis, Noach, Lech Lecha, Vayera, Chayei Sara, Toldos, Vayetzei, Vayishlach, Vayeshev, Miketz, Vayigash, Vayechi, Shemos, Vaera, Bo, Beshalach, Yisro, Mishpatim, Terumah, Tetzaveh, Ki Sisa, Vayakhel, Pekudei, Vayikra, Tzav, Shmini, Tazria, Metzora, Achrei Mos, Kedoshim, Emor, Behar, Bechukosai, Bamidbar, Nasso, Beha'aloscha, Sh'lach, Korach, Chukas, Balak, Pinchas, Matos, Masei, Devarim, Vaeschanan, Eikev, Re'eh, Shoftim, Ki Seitzei, Ki Savo, Nitzavim, Vayeilech, Ha'Azinu, Vezos Habracha, Vayakhel Pekudei, Tazria Metzora, Achrei Mos Kedoshim, Behar Bechukosai, Chukas Balak, Matos Masei, Nitzavim Vayeilech, Shekalim, Zachor, Parah, Hachodesh,Shuva, Shira, Hagadol, Chazon, Nachamu".
      Returns:
      the map of transliterated Parshios
      See Also:
    • setTransliteratedParshiosList

      public void setTransliteratedParshiosList(EnumMap<JewishCalendar.Parsha, String> transliteratedParshaMap)
      Setter method to allow overriding of the default list of parshiyos transliterated into Latin chars. The default uses Ashkenazi American English transliteration.
      Parameters:
      transliteratedParshaMap - the transliterated Parshios as an EnumMap to set
      See Also:
    • formatParsha

      public String formatParsha(JewishCalendar jewishCalendar)
      Returns a String with the name of the current parsha(ios). This method gets the current parsha by calling JewishCalendar.getParshah() that does not return a parsha for any non-Shabbos or a Shabbos that occurs on a Yom Tov, and will return an empty String in those cases. If the class is set to format in Hebrew it will return a String of the current parsha(ios) in Hebrew for example בראשית or נצבים וילך or an empty string if there are none. If not set to Hebrew, it returns a string of the parsha(ios) transliterated into Latin chars. The default uses Ashkenazi pronunciation in typical American English spelling, for example Bereshis or Nitzavim Vayeilech or an empty string if there are none.
      Parameters:
      jewishCalendar - the JewishCalendar Object
      Returns:
      today's parsha(ios) in Hebrew for example, if the formatter is set to format in Hebrew, returns a string of the current parsha(ios) in Hebrew for example בראשית or נצבים וילך or an empty string if there are none. If not set to Hebrew, it returns a string of the parsha(ios) transliterated into Latin chars. The default uses Ashkenazi pronunciation in typical American English spelling, for example Bereshis or Nitzavim Vayeilech or an empty string if there are none.
      See Also:
    • formatParsha

      Returns a String with the name of the current parsha(ios). This method overloads formatParsha(JewishCalendar) and unlike that method, it will format the parsha passed to this method regardless of the day of week. This is the way to format a parsha retrieved from calling JewishCalendar.getUpcomingParshah().
      Parameters:
      parsha - a JewishCalendar.Parsha object
      Returns:
      today's parsha(ios) in Hebrew for example, if the formatter is set to format in Hebrew, returns a string of the current parsha(ios) in Hebrew for example בראשית or נצבים וילך or an empty string if there are none. If not set to Hebrew, it returns a string of the parsha(ios) transliterated into Latin chars. The default uses Ashkenazi pronunciation in typical American English spelling, for example Bereshis or Nitzavim Vayeilech or an empty string if there are none.
      See Also:
    • formatSpecialParsha

      public String formatSpecialParsha(JewishCalendar jewishCalendar)
      Returns a String with the name of the current special parsha of Shekalim, Zachor, Parah or Hachodesh or an empty String for a non-special parsha. If the formatter is set to format in Hebrew, it returns a string of the current special parsha in Hebrew, for example שקלים, זכור, פרה or החדש. An empty string if the date is not a special parsha. If not set to Hebrew, it returns a string of the special parsha transliterated into Latin chars. The default uses Ashkenazi pronunciation in typical American English spelling Shekalim, Zachor, Parah or Hachodesh.
      Parameters:
      jewishCalendar - the JewishCalendar Object
      Returns:
      today's special parsha. If the formatter is set to format in Hebrew, returns a string of the current special parsha in Hebrew for in the format of שקלים, זכור, פרה or החדש or an empty string if there are none. If not set to Hebrew, it returns a string of the special parsha transliterated into Latin chars. The default uses Ashkenazi pronunciation in typical American English spelling of Shekalim, Zachor, Parah or Hachodesh. An empty string if there are none.