Class JewishDate

  • All Implemented Interfaces:
    Cloneable, Comparable<JewishDate>
    Direct Known Subclasses:
    JewishCalendar

    public class JewishDate
    extends Object
    implements Comparable<JewishDate>, Cloneable
    The JewishDate is the base calendar class, that supports maintenance of a GregorianCalendar instance along with the corresponding Jewish date. This class can use the standard Java Date and Calendar classes for setting and maintaining the dates, but it does not subclass these classes or use them internally in any calculations. This class also does not have a concept of a time (which the Date class does). Please note that the calendar does not currently support dates prior to 1/1/1 Gregorian. Also keep in mind that the Gregorian calendar started on October 15, 1582, so any calculations prior to that are suspect (at least from a Gregorian perspective). While 1/1/1 Gregorian and forward are technically supported, any calculations prior to Hillel II's (Hakatan's) calendar (4119 in the Jewish Calendar / 359 CE Julian as recorded by Rav Hai Gaon) would be just an approximation. This open source Java code was written by Avrom Finkelstien from his C++ code. It was refactored to fit the KosherJava Zmanim API with simplification of the code, enhancements and some bug fixing. Some of Avrom's original C++ code was translated from C/C++ code in Calendrical Calculations by Nachum Dershowitz and Edward M. Reingold, Software-- Practice & Experience, vol. 20, no. 9 (September, 1990), pp. 899- 928. Any method with the mark "ND+ER" indicates that the method was taken from this source with minor modifications. If you are looking for a class that implements a Jewish calendar version of the Calendar class, one is available from the ICU (International Components for Unicode) project, formerly part of IBM's DeveloperWorks.
    Author:
    © Avrom Finkelstien 2002, © Eliyahu Hershfeld 2011 - 2018
    See Also:
    JewishCalendar, HebrewDateFormatter, Date, Calendar
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ADAR
      Value of the month field indicating Adar (or Adar I in a leap year), the twelfth numeric month of the year in the Jewish calendar.
      static int ADAR_II
      Value of the month field indicating Adar II, the leap (intercalary or embolismic) thirteenth (Undecimber) numeric month of the year added in Jewish leap year).
      static int AV
      Value of the month field indicating Av, the fifth numeric month of the year in the Jewish calendar.
      private static int CHALAKIM_MOLAD_TOHU
      Days from the beginning of Sunday till molad BaHaRaD.
      private static int CHALAKIM_PER_DAY  
      private static int CHALAKIM_PER_HOUR  
      private static int CHALAKIM_PER_MINUTE  
      private static long CHALAKIM_PER_MONTH  
      static int CHASERIM
      A short year where both CHESHVAN and KISLEV are 29 days.
      static int CHESHVAN
      Value of the month field indicating Cheshvan/marcheshvan, the eighth numeric month of the year in the Jewish calendar.
      private int dayOfWeek
      1 == Sunday, 2 == Monday, etc...
      static int ELUL
      Value of the month field indicating Elul, the sixth numeric month of the year in the Jewish calendar.
      private int gregorianAbsDate  
      private int gregorianDayOfMonth
      The day of the Gregorian month
      private int gregorianMonth
      The month, where 1 == January, 2 == February, etc...
      private int gregorianYear
      The Gregorian year
      static int IYAR
      Value of the month field indicating Iyar, the second numeric month of the year in the Jewish calendar.
      private static int JEWISH_EPOCH
      the Jewish epoch using the RD (Rata Die/Fixed Date or Reingold Dershowitz) day used in Calendrical Calculations.
      private int jewishDay  
      private int jewishMonth  
      private int jewishYear  
      static int KESIDRAN
      An ordered year where CHESHVAN is 29 days and KISLEV is 30 days.
      static int KISLEV
      Value of the month field indicating Kislev, the ninth numeric month of the year in the Jewish calendar.
      private int moladChalakim  
      private int moladHours  
      private int moladMinutes  
      static int NISSAN
      Value of the month field indicating Nissan, the first numeric month of the year in the Jewish calendar.
      static int SHELAIMIM
      A long year where both CHESHVAN and KISLEV are 30 days.
      static int SHEVAT
      Value of the month field indicating Shevat, the eleventh numeric month of the year in the Jewish calendar.
      static int SIVAN
      Value of the month field indicating Sivan, the third numeric month of the year in the Jewish calendar.
      static int TAMMUZ
      Value of the month field indicating Tammuz, the fourth numeric month of the year in the Jewish calendar.
      static int TEVES
      Value of the month field indicating Teves, the tenth numeric month of the year in the Jewish calendar.
      static int TISHREI
      Value of the month field indicating Tishrei, the seventh numeric month of the year in the Jewish calendar.
    • Constructor Summary

      Constructors 
      Constructor Description
      JewishDate()
      Default constructor will set a default date to the current system date.
      JewishDate​(int jewishYear, int jewishMonth, int jewishDayOfMonth)
      Creates a Jewish date based on a Jewish year, month and day of month.
      JewishDate​(long molad)
      Constructor that creates a JewishDate based on a molad passed in.
      JewishDate​(Calendar calendar)
      A constructor that initializes the date to the Calendar paremeter.
      JewishDate​(Date date)
      A constructor that initializes the date to the Date paremeter.
    • Method Summary

      Modifier and Type Method Description
      private void absDateToDate​(int absDate)
      Computes the Gregorian date from the absolute date.
      private void absDateToJewishDate()
      Computes the Jewish date from the absolute date.
      private static int addDechiyos​(int year, int moladDay, int moladParts)
      Adds the 4 dechiyos for molad Tishrei.
      void back()
      Rolls the date back by 1 day.
      Object clone()
      A method that creates a deep copy of the object.
      int compareTo​(JewishDate jewishDate)
      Compares two dates as per the compareTo() method in the Comparable interface.
      boolean equals​(Object object)  
      void forward​(int field, int amount)
      Rolls the date, month or year forward by the amount passed in.
      private void forwardJewishMonth​(int amount)
      Forward the Jewish date by the number of months passed in.
      int getAbsDate()
      Returns the absolute date (days since January 1, 0001 on the Gregorian calendar).
      long getChalakimSinceMoladTohu()
      Returns the number of chalakim (parts - 1080 to the hour) from the original hypothetical Molad Tohu to the Jewish year and month that this Object is set to.
      private static long getChalakimSinceMoladTohu​(int year, int month)
      Returns the number of chalakim (parts - 1080 to the hour) from the original hypothetical Molad Tohu to the year and month passed in.
      int getCheshvanKislevKviah()
      Returns the Cheshvan and Kislev kviah (whether a Jewish year is short, regular or long).
      int getDayOfWeek()
      Returns the day of the week as a number between 1-7.
      int getDaysInJewishMonth()
      Returns the number of days of the Jewish month that the calendar is currently set to.
      private static int getDaysInJewishMonth​(int month, int year)
      Returns the number of days of a Jewish month for a given month and year.
      int getDaysInJewishYear()
      Returns the number of days for the current year that the calendar is set to.
      static int getDaysInJewishYear​(int year)
      Returns the number of days for a given Jewish year.
      int getDaysSinceStartOfJewishYear()
      returns the number of days from Rosh Hashana of the date passed in, to the full date passed in.
      private static int getDaysSinceStartOfJewishYear​(int year, int month, int dayOfMonth)
      returns the number of days from Rosh Hashana of the date passed in, to the full date passed in.
      Calendar getGregorianCalendar()
      Returns this object's date as a Calendar object.
      int getGregorianDayOfMonth()
      Returns the Gregorian day of the month.
      int getGregorianMonth()
      Returns the Gregorian month (between 0-11).
      int getGregorianYear()
      Returns the Gregotian year.
      static int getJewishCalendarElapsedDays​(int year)
      Returns the number of days elapsed from the Sunday prior to the start of the Jewish calendar to the mean conjunction of Tishri of the Jewish year.
      int getJewishDayOfMonth()
      Returns the Jewish day of month.
      int getJewishMonth()
      Returns the Jewish month 1-12 (or 13 years in a leap year).
      private static int getJewishMonthOfYear​(int year, int month)
      Converts the NISSAN based constants used by this class to numeric month starting from TISHREI.
      int getJewishYear()
      Returns the Jewish year.
      (package private) int getLastDayOfGregorianMonth​(int month)
      Returns the last day in a gregorian month
      private static int getLastDayOfGregorianMonth​(int month, int year)
      Returns the number of days in a given month in a given month and year.
      private static int getLastMonthOfJewishYear​(int year)
      Returns the last month of a given Jewish year.
      JewishDate getMolad()
      Returns the molad for a given year and month.
      int getMoladChalakim()
      Returns the molad chalakim/parts.
      int getMoladHours()
      Returns the molad hours.
      int getMoladMinutes()
      Returns the molad minutes.
      private static int gregorianDateToAbsDate​(int year, int month, int dayOfMonth)
      Computes the absolute date from a Gregorian date.
      int hashCode()  
      boolean isCheshvanLong()
      Returns if Cheshvan is long (30 days VS 29 days) for the current year that the calendar is set to.
      private static boolean isCheshvanLong​(int year)
      Returns if Cheshvan is long in a given Jewish year.
      boolean isJewishLeapYear()
      Returns if the year the calendar is set to is a Jewish leap year.
      private static boolean isJewishLeapYear​(int year)
      Returns if the year is a Jewish leap year.
      boolean isKislevShort()
      Returns if the Kislev is short for the year that this class is set to.
      private static boolean isKislevShort​(int year)
      Returns if Kislev is short (29 days VS 30 days) in a given Jewish year.
      private static int jewishDateToAbsDate​(int year, int month, int dayOfMonth)
      Returns the absolute date of Jewish date.
      private static int moladToAbsDate​(long chalakim)
      Returns the number of days from the Jewish epoch from the number of chalakim from the epoch passed in.
      void resetDate()
      Resets this date to the current system date.
      void setDate​(Calendar calendar)
      Sets the date based on a Calendar object.
      void setDate​(Date date)
      Sets the date based on a Date object.
      void setGregorianDate​(int year, int month, int dayOfMonth)
      Sets the Gregorian Date, and updates the Jewish date accordingly.
      void setGregorianDayOfMonth​(int dayOfMonth)
      sets the Gregorian Day of month.
      void setGregorianMonth​(int month)
      Sets the Gregorian month.
      void setGregorianYear​(int year)
      sets the Gregorian year.
      private void setInternalGregorianDate​(int year, int month, int dayOfMonth)
      Sets the hidden internal representation of the Gregorian date , and updates the Jewish date accordingly.
      void setJewishDate​(int year, int month, int dayOfMonth)
      Sets the Jewish Date and updates the Gregorian date accordingly.
      void setJewishDate​(int year, int month, int dayOfMonth, int hours, int minutes, int chalakim)
      Sets the Jewish Date and updates the Gregorian date accordingly.
      void setJewishDayOfMonth​(int dayOfMonth)
      sets the Jewish day of month.
      void setJewishMonth​(int month)
      sets the Jewish month.
      void setJewishYear​(int year)
      sets the Jewish year.
      void setMoladChalakim​(int moladChalakim)
      Sets the molad chalakim/parts.
      void setMoladHours​(int moladHours)
      Sets the molad hours.
      void setMoladMinutes​(int moladMinutes)
      Sets the molad minutes.
      private void setMoladTime​(int chalakim)
      Sets the molad time (hours minutes and chalakim) based on the number of chalakim since the start of the day.
      String toString()
      Returns a string containing the Jewish date in the form, "day Month, year" e.g. "21 Shevat, 5729".
      private static void validateGregorianDate​(int year, int month, int dayOfMonth)
      Validates the components of a Gregorian date for validity.
      private static void validateGregorianDayOfMonth​(int dayOfMonth)
      Validates a Gregorian day of month for validity.
      private static void validateGregorianMonth​(int month)
      Validates a Gregorian month for validity.
      private static void validateGregorianYear​(int year)
      Validates a Gregorian year for validity.
      private static void validateJewishDate​(int year, int month, int dayOfMonth, int hours, int minutes, int chalakim)
      Validates the components of a Jewish date for validity.
    • Constructor Detail

      • JewishDate

        public JewishDate​(long molad)
        Constructor that creates a JewishDate based on a molad passed in. The molad would be the number of chalakim/parts starting at the beginning of Sunday prior to the molad Tohu BeHaRaD (Be = Monday, Ha= 5 hours and Rad =204 chalakim/parts) - prior to the start of the Jewish calendar. BeHaRaD is 23:11:20 on Sunday night(5 hours 204/1080 chalakim after sunset on Sunday evening).
        Parameters:
        molad - the number of chalakim since the beginning of Sunday prior to BaHaRaD
      • JewishDate

        public JewishDate​(int jewishYear,
                          int jewishMonth,
                          int jewishDayOfMonth)
        Creates a Jewish date based on a Jewish year, month and day of month.
        Parameters:
        jewishYear - the Jewish year
        jewishMonth - the Jewish month. The method expects a 1 for Nissan ... 12 for Adar and 13 for Adar II. Use the constants NISSAN ... ADAR (or ADAR_II for a leap year Adar II) to avoid any confusion.
        jewishDayOfMonth - the Jewish day of month. If 30 is passed in for a month with only 29 days (for example IYAR, or KISLEV in a year that isKislevShort()), the 29th (last valid date of the month) will be set
        Throws:
        IllegalArgumentException - if the day of month is < 1 or > 30, or a year of < 0 is passed in.
      • JewishDate

        public JewishDate()
        Default constructor will set a default date to the current system date.
      • JewishDate

        public JewishDate​(Date date)
        A constructor that initializes the date to the Date paremeter.
        Parameters:
        date - the Date to set the calendar to
        Throws:
        IllegalArgumentException - if the date would fall prior to the January 1, 1 AD
    • Method Detail

      • getLastDayOfGregorianMonth

        int getLastDayOfGregorianMonth​(int month)
        Returns the last day in a gregorian month
        Parameters:
        month - the Gregorian month
        Returns:
        the last day of the Gregorian month
      • getLastDayOfGregorianMonth

        private static int getLastDayOfGregorianMonth​(int month,
                                                      int year)
        Returns the number of days in a given month in a given month and year.
        Parameters:
        month - the month. As with other cases in this class, this is 1-based, not zero-based.
        year - the year (only impacts February)
        Returns:
        the number of days in the month in the given year
      • absDateToDate

        private void absDateToDate​(int absDate)
        Computes the Gregorian date from the absolute date. ND+ER
        Parameters:
        absDate - the absolute date
      • getAbsDate

        public int getAbsDate()
        Returns the absolute date (days since January 1, 0001 on the Gregorian calendar).
        Returns:
        the number of days since January 1, 1
      • gregorianDateToAbsDate

        private static int gregorianDateToAbsDate​(int year,
                                                  int month,
                                                  int dayOfMonth)
        Computes the absolute date from a Gregorian date. ND+ER
        Parameters:
        year - the Gregorian year
        month - the Gregorian month. Unlike the Java Calendar where January has the value of 0,This expects a 1 for January
        dayOfMonth - the day of the month (1st, 2nd, etc...)
        Returns:
        the absolute Gregorian day
      • isJewishLeapYear

        private static boolean isJewishLeapYear​(int year)
        Returns if the year is a Jewish leap year. Years 3, 6, 8, 11, 14, 17 and 19 in the 19 year cycle are leap years.
        Parameters:
        year - the Jewish year.
        Returns:
        true if it is a leap year
        See Also:
        isJewishLeapYear()
      • isJewishLeapYear

        public boolean isJewishLeapYear()
        Returns if the year the calendar is set to is a Jewish leap year. Years 3, 6, 8, 11, 14, 17 and 19 in the 19 year cycle are leap years.
        Returns:
        true if it is a leap year
        See Also:
        isJewishLeapYear(int)
      • getLastMonthOfJewishYear

        private static int getLastMonthOfJewishYear​(int year)
        Returns the last month of a given Jewish year. This will be 12 on a non leap year or 13 on a leap year.
        Parameters:
        year - the Jewish year.
        Returns:
        12 on a non leap year or 13 on a leap year
        See Also:
        isJewishLeapYear(int)
      • getJewishCalendarElapsedDays

        public static int getJewishCalendarElapsedDays​(int year)
        Returns the number of days elapsed from the Sunday prior to the start of the Jewish calendar to the mean conjunction of Tishri of the Jewish year.
        Parameters:
        year - the Jewish year
        Returns:
        the number of days elapsed from prior to the molad Tohu BaHaRaD (Be = Monday, Ha= 5 hours and Rad =204 chalakim/parts) prior to the start of the Jewish calendar, to the mean conjunction of Tishri of the Jewish year. BeHaRaD is 23:11:20 on Sunday night(5 hours 204/1080 chalakim after sunset on Sunday evening).
      • addDechiyos

        private static int addDechiyos​(int year,
                                       int moladDay,
                                       int moladParts)
        Adds the 4 dechiyos for molad Tishrei. These are:
        1. Lo ADU Rosh - Rosh Hashana can't fall on a Sunday, Wednesday or Friday. If the molad fell on one of these days, Rosh Hashana is delayed to the following day.
        2. Molad Zaken - If the molad of Tishrei falls after 12 noon, Rosh Hashana is delayed to the following day. If the following day is ADU, it will be delayed an additional day.
        3. GaTRaD - If on a non leap year the molad of Tishrei falls on a Tuesday (Ga) on or after 9 hours (T) and 204 chalakim (TRaD) it is delayed till Thursday (one day delay, plus one day for Lo ADU Rosh)
        4. BeTuTaKFoT - if the year following a leap year falls on a Monday (Be) on or after 15 hours (Tu) and 589 chalakim (TaKFoT) it is delayed till Tuesday
        Parameters:
        year - the year
        moladDay - the molad day
        moladParts - the molad parts
        Returns:
        the number of elapsed days in the JewishCalendar adjusted for the 4 dechiyos.
      • getChalakimSinceMoladTohu

        private static long getChalakimSinceMoladTohu​(int year,
                                                      int month)
        Returns the number of chalakim (parts - 1080 to the hour) from the original hypothetical Molad Tohu to the year and month passed in.
        Parameters:
        year - the Jewish year
        month - the Jewish month the Jewish month, with the month numbers starting from Nisan. Use the JewishDate constants such as TISHREI.
        Returns:
        the number of chalakim (parts - 1080 to the hour) from the original hypothetical Molad Tohu
      • getChalakimSinceMoladTohu

        public long getChalakimSinceMoladTohu()
        Returns the number of chalakim (parts - 1080 to the hour) from the original hypothetical Molad Tohu to the Jewish year and month that this Object is set to.
        Returns:
        the number of chalakim (parts - 1080 to the hour) from the original hypothetical Molad Tohu
      • getJewishMonthOfYear

        private static int getJewishMonthOfYear​(int year,
                                                int month)
        Converts the NISSAN based constants used by this class to numeric month starting from TISHREI. This is required for Molad claculations.
        Parameters:
        year - The Jewish year
        month - The Jewish Month
        Returns:
        the Jewish month of the year starting with Tishrei
      • validateJewishDate

        private static void validateJewishDate​(int year,
                                               int month,
                                               int dayOfMonth,
                                               int hours,
                                               int minutes,
                                               int chalakim)
        Validates the components of a Jewish date for validity. It will throw an IllegalArgumentException if the Jewish date is earlier than 18 Teves, 3761 (1/1/1 Gregorian), a month < 1 or > 12 (or 13 on a leap year), the day of month is < 1 or > 30, an hour < 0 or > 23, a minute < 0 or > 59 or chalakim < 0 or > 17. For larger a larger number of chalakim such as 793 (TaShTzaG) break the chalakim into minutes (18 chalakim per minutes, so it would be 44 minutes and 1 chelek in the case of 793/TaShTzaG).
        Parameters:
        year - the Jewish year to validate. It will reject any year <= 3761 (lower than the year 1 Gregorian).
        month - the Jewish month to validate. It will reject a month < 1 or > 12 (or 13 on a leap year) .
        dayOfMonth - the day of the Jewish month to validate. It will reject any value < 1 or > 30 TODO: check calling methods to see if there is any reason that the class can validate that 30 is invalid for some months.
        hours - the hours (for molad calculations). It will reject an hour < 0 or > 23
        minutes - the minutes (for molad calculations). It will reject a minute < 0 or > 59
        chalakim - the chalakim/parts (for molad calculations). It will reject a chalakim < 0 or > 17. For larger numbers such as 793 (TaShTzaG) break the chalakim into minutes (18 chalakim per minutes, so it would be 44 minutes and 1 chelek in the case of 793/TaShTzaG)
        Throws:
        IllegalArgumentException - if a A Jewish date earlier than 18 Teves, 3761 (1/1/1 Gregorian), a month < 1 or > 12 (or 13 on a leap year), the day of month is < 1 or > 30, an hour < 0 or > 23, a minute < 0 or > 59 or chalakim < 0 or > 17. For larger a larger number of chalakim such as 793 (TaShTzaG) break the chalakim into minutes (18 chalakim per minutes, so it would be 44 minutes and 1 chelek in the case of 793 (TaShTzaG).
      • validateGregorianDate

        private static void validateGregorianDate​(int year,
                                                  int month,
                                                  int dayOfMonth)
        Validates the components of a Gregorian date for validity. It will throw an IllegalArgumentException if a year of < 1, a month < 0 or > 11 or a day of month < 1 is passed in.
        Parameters:
        year - the Gregorian year to validate. It will reject any year < 1.
        month - the Gregorian month number to validate. It will enforce that the month is between 0 - 11 like a GregorianCalendar, where Calendar.JANUARY has a value of 0.
        dayOfMonth - the day of the Gregorian month to validate. It will reject any value < 1, but will allow values > 31 since calling methods will simply set it to the maximum for that month. TODO: check calling methods to see if there is any reason that the class needs days > the maximum.
        Throws:
        IllegalArgumentException - if a year of < 1, a month < 0 or > 11 or a day of month < 1 is passed in
        See Also:
        validateGregorianYear(int), validateGregorianMonth(int), validateGregorianDayOfMonth(int)
      • validateGregorianMonth

        private static void validateGregorianMonth​(int month)
        Validates a Gregorian month for validity.
        Parameters:
        month - the Gregorian month number to validate. It will enforce that the month is between 0 - 11 like a GregorianCalendar, where Calendar.JANUARY has a value of 0.
      • validateGregorianDayOfMonth

        private static void validateGregorianDayOfMonth​(int dayOfMonth)
        Validates a Gregorian day of month for validity.
        Parameters:
        dayOfMonth - the day of the Gregorian month to validate. It will reject any value < 1, but will allow values > 31 since calling methods will simply set it to the maximum for that month. TODO: check calling methods to see if there is any reason that the class needs days > the maximum.
      • validateGregorianYear

        private static void validateGregorianYear​(int year)
        Validates a Gregorian year for validity.
        Parameters:
        year - the Gregorian year to validate. It will reject any year < 1.
      • getDaysInJewishYear

        public static int getDaysInJewishYear​(int year)
        Returns the number of days for a given Jewish year. ND+ER
        Parameters:
        year - the Jewish year
        Returns:
        the number of days for a given Jewish year.
        See Also:
        isCheshvanLong(), isKislevShort()
      • isCheshvanLong

        private static boolean isCheshvanLong​(int year)
        Returns if Cheshvan is long in a given Jewish year. The method name isLong is done since in a Kesidran (ordered) year Cheshvan is short. ND+ER
        Parameters:
        year - the year
        Returns:
        true if Cheshvan is long in Jewish year.
        See Also:
        isCheshvanLong(), getCheshvanKislevKviah()
      • isCheshvanLong

        public boolean isCheshvanLong()
        Returns if Cheshvan is long (30 days VS 29 days) for the current year that the calendar is set to. The method name isLong is done since in a Kesidran (ordered) year Cheshvan is short.
        Returns:
        true if Cheshvan is long for the current year that the calendar is set to
        See Also:
        isCheshvanLong()
      • isKislevShort

        private static boolean isKislevShort​(int year)
        Returns if Kislev is short (29 days VS 30 days) in a given Jewish year. The method name isShort is done since in a Kesidran (ordered) year Kislev is long. ND+ER
        Parameters:
        year - the Jewish year
        Returns:
        true if Kislev is short for the given Jewish year.
        See Also:
        isKislevShort(), getCheshvanKislevKviah()
      • isKislevShort

        public boolean isKislevShort()
        Returns if the Kislev is short for the year that this class is set to. The method name isShort is done since in a Kesidran (ordered) year Kislev is long.
        Returns:
        true if Kislev is short for the year that this class is set to
      • getDaysInJewishMonth

        private static int getDaysInJewishMonth​(int month,
                                                int year)
        Returns the number of days of a Jewish month for a given month and year.
        Parameters:
        month - the Jewish month
        year - the Jewish Year
        Returns:
        the number of days for a given Jewish month
      • getDaysInJewishMonth

        public int getDaysInJewishMonth()
        Returns the number of days of the Jewish month that the calendar is currently set to.
        Returns:
        the number of days for the Jewish month that the calendar is currently set to.
      • absDateToJewishDate

        private void absDateToJewishDate()
        Computes the Jewish date from the absolute date. ND+ER
      • jewishDateToAbsDate

        private static int jewishDateToAbsDate​(int year,
                                               int month,
                                               int dayOfMonth)
        Returns the absolute date of Jewish date. ND+ER
        Parameters:
        year - the Jewish year. The year can't be negative
        month - the Jewish month starting with Nisan. Nisan expects a value of 1 etc till Adar with a value of 12. For a leap year, 13 will be the expected value for Adar II. Use the constants NISSAN etc.
        dayOfMonth - the Jewish day of month. valid values are 1-30. If the day of month is set to 30 for a month that only has 29 days, the day will be set as 29.
        Returns:
        the absolute date of the Jewish date.
      • getMolad

        public JewishDate getMolad()
        Returns the molad for a given year and month. Returns a JewishDate Object set to the date of the molad with the hours, minutes and chalakim set. In the current implementation, it sets the molad time based on a midnight date rollover. This means that Rosh Chodesh Adar II, 5771 with a molad of 7 chalakim past midnight on Shabbos 29 Adar I / March 5, 2011 12:00 AM and 7 chalakim, will have the following values: hours: 0, minutes: 0, Chalakim: 7.
        Returns:
        a JewishDate Object set to the date of the molad with the hours, minutes and chalakim set.
      • moladToAbsDate

        private static int moladToAbsDate​(long chalakim)
        Returns the number of days from the Jewish epoch from the number of chalakim from the epoch passed in.
        Parameters:
        chalakim - the number of chalakim since the beginning of Sunday prior to BaHaRaD
        Returns:
        the number of days from the Jewish epoch
      • setMoladTime

        private void setMoladTime​(int chalakim)
        Sets the molad time (hours minutes and chalakim) based on the number of chalakim since the start of the day.
        Parameters:
        chalakim - the number of chalakim since the start of the day.
      • getDaysSinceStartOfJewishYear

        private static int getDaysSinceStartOfJewishYear​(int year,
                                                         int month,
                                                         int dayOfMonth)
        returns the number of days from Rosh Hashana of the date passed in, to the full date passed in.
        Parameters:
        year - the Jewish year
        month - the Jewish month
        dayOfMonth - the day in the Jewish month
        Returns:
        the number of days
      • getDaysSinceStartOfJewishYear

        public int getDaysSinceStartOfJewishYear()
        returns the number of days from Rosh Hashana of the date passed in, to the full date passed in.
        Returns:
        the number of days
      • setDate

        public void setDate​(Date date)
        Sets the date based on a Date object. Modifies the Jewish date as well.
        Parameters:
        date - the Date to set the calendar to
        Throws:
        IllegalArgumentException - if the date would fall prior to the year 1 AD
      • setGregorianDate

        public void setGregorianDate​(int year,
                                     int month,
                                     int dayOfMonth)
        Sets the Gregorian Date, and updates the Jewish date accordingly. Like the Java Calendar A value of 0 is expected for January.
        Parameters:
        year - the Gregorian year
        month - the Gregorian month. Like the Java Calendar, this class expects 0 for January
        dayOfMonth - the Gregorian day of month. If this is > the number of days in the month/year, the last valid date of the month will be set
        Throws:
        IllegalArgumentException - if a year of < 1, a month < 0 or > 11 or a day of month < 1 is passed in
      • setInternalGregorianDate

        private void setInternalGregorianDate​(int year,
                                              int month,
                                              int dayOfMonth)
        Sets the hidden internal representation of the Gregorian date , and updates the Jewish date accordingly. While public getters and setters have 0 based months matching the Java Calendar classes, This class internally represents the Gregorian month starting at 1. When this is called it will not adjust the month to match the Java Calendar classes.
        Parameters:
        year - the year
        month - the month
        dayOfMonth - the day of month
      • setJewishDate

        public void setJewishDate​(int year,
                                  int month,
                                  int dayOfMonth)
        Sets the Jewish Date and updates the Gregorian date accordingly.
        Parameters:
        year - the Jewish year. The year can't be negative
        month - the Jewish month starting with Nisan. A value of 1 is expected for Nissan ... 12 for Adar and 13 for Adar II. Use the constants NISSAN ... ADAR (or ADAR_II for a leap year Adar II) to avoid any confusion.
        dayOfMonth - the Jewish day of month. valid values are 1-30. If the day of month is set to 30 for a month that only has 29 days, the day will be set as 29.
        Throws:
        IllegalArgumentException - if a A Jewish date earlier than 18 Teves, 3761 (1/1/1 Gregorian), a month < 1 or > 12 (or 13 on a leap year) or the day of month is < 1 or > 30 is passed in
      • setJewishDate

        public void setJewishDate​(int year,
                                  int month,
                                  int dayOfMonth,
                                  int hours,
                                  int minutes,
                                  int chalakim)
        Sets the Jewish Date and updates the Gregorian date accordingly.
        Parameters:
        year - the Jewish year. The year can't be negative
        month - the Jewish month starting with Nisan. A value of 1 is expected for Nissan ... 12 for Adar and 13 for Adar II. Use the constants NISSAN ... ADAR (or ADAR_II for a leap year Adar II) to avoid any confusion.
        dayOfMonth - the Jewish day of month. valid values are 1-30. If the day of month is set to 30 for a month that only has 29 days, the day will be set as 29.
        hours - the hour of the day. Used for Molad calculations
        minutes - the minutes. Used for Molad calculations
        chalakim - the chalakim/parts. Used for Molad calculations. The chalakim should not exceed 17. Minutes should be used for larger numbers.
        Throws:
        IllegalArgumentException - if a A Jewish date earlier than 18 Teves, 3761 (1/1/1 Gregorian), a month < 1 or > 12 (or 13 on a leap year), the day of month is < 1 or > 30, an hour < 0 or > 23, a minute < 0 > 59 or chalakim < 0 > 17. For larger a larger number of chalakim such as 793 (TaShTzaG) break the chalakim into minutes (18 chalakim per minutes, so it would be 44 minutes and 1 chelek in the case of 793 (TaShTzaG).
      • resetDate

        public void resetDate()
        Resets this date to the current system date.
      • toString

        public String toString()
        Returns a string containing the Jewish date in the form, "day Month, year" e.g. "21 Shevat, 5729". For more complex formatting, use the formatter classes.
        Overrides:
        toString in class Object
        Returns:
        the Jewish date in the form "day Month, year" e.g. "21 Shevat, 5729"
        See Also:
        HebrewDateFormatter.format(JewishDate)
      • forwardJewishMonth

        private void forwardJewishMonth​(int amount)
        Forward the Jewish date by the number of months passed in. FIXME: Deal with forwarding a date such as 30 Nisan by a month. 30 Iyar does not exist. This should be dealt with similar to the way that the Java Calendar behaves (not that simple since there is a difference between add() or roll().
        Parameters:
        amount - the number of months to roll the month forward
        Throws:
        IllegalArgumentException - if the amount is less than 1
      • back

        public void back()
        Rolls the date back by 1 day. It modifies both the Gregorian and Jewish dates accordingly. The API does not currently offer the ability to forward more than one day t a time, or to forward by month or year. If such manipulation is required use the Calendar class Calendar.add(int, int) or Calendar.roll(int, int) methods in the following manner.
         
                Calendar cal = jewishDate.getTime(); // get a java.util.Calendar representation of the JewishDate
                cal.add(Calendar.MONTH, -3); // subtract 3 Gregorian months
                jewishDate.setDate(cal); // set the updated calendar back to this class
         
         
        See Also:
        back(), Calendar.add(int, int), Calendar.roll(int, int)
      • compareTo

        public int compareTo​(JewishDate jewishDate)
        Compares two dates as per the compareTo() method in the Comparable interface. Returns a value less than 0 if this date is "less than" (before) the date, greater than 0 if this date is "greater than" (after) the date, or 0 if they are equal.
        Specified by:
        compareTo in interface Comparable<JewishDate>
      • getGregorianMonth

        public int getGregorianMonth()
        Returns the Gregorian month (between 0-11).
        Returns:
        the Gregorian month (between 0-11). Like the java.util.Calendar, months are 0 based.
      • getGregorianDayOfMonth

        public int getGregorianDayOfMonth()
        Returns the Gregorian day of the month.
        Returns:
        the Gregorian day of the mont
      • getGregorianYear

        public int getGregorianYear()
        Returns the Gregotian year.
        Returns:
        the Gregorian year
      • getJewishMonth

        public int getJewishMonth()
        Returns the Jewish month 1-12 (or 13 years in a leap year). The month count starts with 1 for Nisan and goes to 13 for Adar II
        Returns:
        the Jewish month from 1 to 12 (or 13 years in a leap year). The month count starts with 1 for Nisan and goes to 13 for Adar II
      • getJewishDayOfMonth

        public int getJewishDayOfMonth()
        Returns the Jewish day of month.
        Returns:
        the Jewish day of the month
      • getJewishYear

        public int getJewishYear()
        Returns the Jewish year.
        Returns:
        the Jewish year
      • getDayOfWeek

        public int getDayOfWeek()
        Returns the day of the week as a number between 1-7.
        Returns:
        the day of the week as a number between 1-7.
      • setGregorianDayOfMonth

        public void setGregorianDayOfMonth​(int dayOfMonth)
        sets the Gregorian Day of month.
        Parameters:
        dayOfMonth - the Gregorian Day of month.
        Throws:
        IllegalArgumentException - if the day of month of < 1 is passed in
      • setJewishMonth

        public void setJewishMonth​(int month)
        sets the Jewish month.
        Parameters:
        month - the Jewish month from 1 to 12 (or 13 years in a leap year). The month count starts with 1 for Nisan and goes to 13 for Adar II
        Throws:
        IllegalArgumentException - if a month < 1 or > 12 (or 13 on a leap year) is passed in
      • setJewishYear

        public void setJewishYear​(int year)
        sets the Jewish year.
        Parameters:
        year - the Jewish year
        Throws:
        IllegalArgumentException - if a year of < 3761 is passed in. The same will happen if the year is 3761 and the month and day previously set are < 18 Teves (preior to Jan 1, 1 AD)
      • setJewishDayOfMonth

        public void setJewishDayOfMonth​(int dayOfMonth)
        sets the Jewish day of month.
        Parameters:
        dayOfMonth - the Jewish day of month
        Throws:
        IllegalArgumentException - if the day of month is < 1 or > 30 is passed in