Class HebrewDateFormatter


  • public class HebrewDateFormatter
    extends Object
    The HebrewDateFormatter class formats a JewishDate. The class formats Jewish dates in Hebrew or Latin chars, and has various settings. Sample full date output includes (using various options):
    • 21 Shevat, 5729
    • כא שבט תשכט
    • ה׳ כ״א שבט תשכ״ט
    • כ״א שבט תשך׳
    Author:
    © Eliyahu Hershfeld 2011 - 2018
    See Also:
    JewishDate, JewishCalendar
    • Method Detail

      • 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
      • getTransliteratedHolidayList

        public String[] getTransliteratedHolidayList()
        Returns the list of holidays transliterated into Latin chars. This is used by the formatYomTov(JewishCalendar) when formatting the Yom Tov String. The default list of months uses Ashkenazi pronunciation in typical American English spelling.
        Returns:
        the list of holidays "Adar", "Adar II", "Adar I". 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", "Purim Katan", "Rosh Chodesh", "Yom HaShoah", "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim"
        See Also:
        setTransliteratedMonthList(String[]), formatYomTov(JewishCalendar), isHebrewFormat()
      • setTransliteratedHolidayList

        public void setTransliteratedHolidayList​(String[] transliteratedHolidays)
        Sets the list of holidays transliterated into Latin chars. This is used by the formatYomTov(JewishCalendar) when formatting the Yom Tov String.
        Parameters:
        transliteratedHolidays - the transliteratedHolidays to set. Ensure that the sequence exactly matches the list returned by the defaulyt
      • formatYomTov

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

        public void setHebrewOmerPrefix​(String hebrewOmerPrefix)
        Method to set the Hebrew Omer prefix. By default it is the letter ב, but this allows setting it to a ל (or any other prefix).
        Parameters:
        hebrewOmerPrefix - the hebrewOmerPrefix to set. You can use the Unicode \u05DC to set it to ל.
        See Also:
        getHebrewOmerPrefix(), formatOmer(JewishCalendar)
      • getTransliteratedMonthList

        public String[] getTransliteratedMonthList()
        Returns the list 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"
        Returns:
        the list of months beginning in Nissan and ending in in "Adar", "Adar II", "Adar I". The default list is currently "Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Cheshvan", "Kislev", "Teves", "Shevat", "Adar", "Adar II", "Adar I"
        See Also:
        setTransliteratedMonthList(String[])
      • setTransliteratedMonthList

        public void setTransliteratedMonthList​(String[] transliteratedMonths)
        Setter method to allow overriding of the default list of months transliterated into into Latin chars. The default uses Ashkenazi American English transliteration.
        Parameters:
        transliteratedMonths - an array of 14 month names such as { "Nissan", "Iyar", "Sivan", "Tamuz", "Av", "Elul", "Tishrei", "Heshvan", "Kislev", "Tevet", "Shevat", "Adar", "Adar II", "Adar I" }
        See Also:
        getTransliteratedMonthList()
      • 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:
        isHebrewFormat(), isLongWeekFormat()
      • 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 כ״א שבט תשך׳. 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 כ״א שבט תשך׳. When set to false, this output would display as כא שבט תשך.
        Parameters:
        useGershGershayim - set to false to omit the Geresh ׳ and Gershayim ״ in formatting
      • 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 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.
      • 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 BaOmer" 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:
        isHebrewFormat(), getHebrewOmerPrefix(), setHebrewOmerPrefix(String)
      • formatMolad

        private String formatMolad​(long moladChalakim)
        Formats a molad. TODO: Experimental and incomplete
        Parameters:
        moladChalakim - the chalakim of the molad
        Returns:
        the formatted molad. FIXME: define proper format in English and Hebrew.
      • 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).
      • formatHebrewNumber

        public String formatHebrewNumber​(int number)
        Returns a Hebrew formatted string of a number. The method can calculate from 0 - 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 תשכ״ט