KosherJava Zmanim Homepage

net.sourceforge.zmanim.hebrewcalendar
Class JewishDate

java.lang.Object
  extended by net.sourceforge.zmanim.hebrewcalendar.JewishDate
All Implemented Interfaces:
Cloneable, Comparable

public class JewishDate
extends Object
implements Comparable, Cloneable

The JewishDate class allows one to maintain an instance of a Gregorian date along with the corresponding Jewish date. This class can use the standard Java Date and Calendar classes for setting it, but does not subclass these classes or use them internally to any extensive use. This class also does not have a concept of a time (which the Date class does). If you are looking for a class that implements a Jewish calendar version of the Calendar class, one is available from developerWorks by IBM. This open source Java code was written by Avrom Finkelstien from his C++ code. it was adapted to the KosherJava Zmanim API with simplification of the non-core code. The original algorithms were untouched. 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. The methods used to obtain the parsha were derived from the source code of HebCal by Danny Sadinoff and JCal for the Mac by Frank Yellin. Both based their code on routines by Nachum Dershowitz and Edward M. Reingold. The class allows setting whether the parsha and holiday scheme follows the Israel scheme or outside Israel scheme. TODO: Some do not belong in this class, but here is a partial list of what should still be implementted in some form:

  1. Add special parshiyos (shekalim, parah, zachor and hachodesh
  2. Molad / shabbos mevarchim)
  3. Haftorah (various minhagim)
  4. Daf Yomi (bavli, yerushalmi, mishna yomis etc)
  5. Support showing the upcoming parsha for the middle of the week

Version:
0.2.5
Author:
© Avrom Finkelstien 2002, © Eliyahu Hershfeld 2011
See Also:
Date, Calendar

Constructor Summary
JewishDate()
          Default constructor will set a default date to the current system date.
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.
JewishDate(int gregorianYear, int gregorianMonth, int gregorianDayOfMonth)
          Creates a Jewish date based on a Gregorian date
JewishDate(int gregorianYear, int gregorianMonth, int gregorianDayOfMonth, boolean inIsrael)
          Creates a Jewish date based on Gregorian date and whether in Israel
 
Method Summary
 void back()
          Rolls the date back by 1.
 Object clone()
          Create a copy of this date.
 int compareTo(Object o)
          Compares two dates as per the compareTo() method in the Comparable interface.
 boolean equals(Object object)
          Compares two dates to see if they are equal
 void forward()
          Rolls the date forward by 1.
 int getDayOfOmer()
          Returns the int value of the Omer day or Integer.MIN_VALUE if the day is not in the omer
 int getDayOfWeek()
          Returns the day of the week as a number between 1-7.
static int getDaysInJewishMonth(int month, int year)
          Returns the number of days of a Jewish month for a given month and year.
 int getGregorianDayOfMonth()
          Returns the Gregorian day of the month.
 int getGregorianMonth()
          Returns the Gregorian month (between 1-12).
 int getGregorianYear()
          Returns the Gregotian year.
 String getHoliday()
          Returns a String of the Jewish holiday or fast day for the current day, or a null if there is no holiday for this day.
 boolean getInIsrael()
          Gets whether Israel parsha and holiday scheme is used or not.
 int getJewishDayOfMonth()
          Returns the Jewish day of month.
 int getJewishMonth()
          Returns the Jewish month (1-12 or 13).
 int getJewishYear()
          Returns the Jewish year.
(package private)  int getLastDayOfGregorianMonth(int month)
          Returns the number of days in a given month for the current year.
 String getParsha()
          returns a string of today's parsha(ios) or an empty string if there are none.
 Date getTime()
          Returns this object's date as a java.util.Date object.
 int hashCode()
           
static boolean isCheshvanLong(int year)
          Returns if Cheshvan is long in a given Jewish year.
static boolean isJewishLeapYear(int year)
          Returns if the year is a Jewish leap year.
static boolean isKislevShort(int year)
          Returns if Kislev is short in a given Jewish year.
 boolean isRoshChodesh()
          Returns if the day is Rosh Chodesh.
 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.
 void setInIsrael(boolean inIsrael)
          Sets whether to use Israel parsha and holiday scheme or not.
 void setJewishDate(int year, int month, int dayOfMonth)
          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.
 String toString()
          Returns a string containing the Jewish date in the form, "day Month, year" e.g. "21 Shevat, 5729".
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JewishDate

public JewishDate(int gregorianYear,
                  int gregorianMonth,
                  int gregorianDayOfMonth)
Creates a Jewish date based on a Gregorian date

Parameters:
gregorianYear - the Gregorian year
gregorianMonth - the Gregorian month. Unlike the Java Calendar where January has the value of 0,This expects a 1 for January
gregorianDayOfMonth - 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

JewishDate

public JewishDate(int gregorianYear,
                  int gregorianMonth,
                  int gregorianDayOfMonth,
                  boolean inIsrael)
Creates a Jewish date based on Gregorian date and whether in Israel

Parameters:
gregorianYear - the Gregorian year
gregorianMonth - the Gregorian month. Unlike the Java Calendar where January has the value of 0,This expects a 1 for January
gregorianDayOfMonth - 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
inIsrael - whether in Israel. This affects Yom Tov and Parsha calculations

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

JewishDate

public JewishDate(Calendar calendar)
A constructor that initializes the date to the Calendar paremeter.

Parameters:
calendar - the Calendar to set the calendar to
Method Detail

getLastDayOfGregorianMonth

int getLastDayOfGregorianMonth(int month)
Returns the number of days in a given month for the current year. Will likely turn into a private method in the future.

Parameters:
month - the month
Returns:
the number of days in the month

isJewishLeapYear

public static boolean isJewishLeapYear(int year)
Returns if the year is a Jewish leap year.

Parameters:
year - the Jewish year.
Returns:
true if it is a leap year

isCheshvanLong

public static boolean isCheshvanLong(int year)
Returns if Cheshvan is long in a given Jewish year. ND+ER

Parameters:
year - the year
Returns:
true if Cheshvan is long in Jewish year.

isRoshChodesh

public boolean isRoshChodesh()
Returns if the day is Rosh Chodesh.

Returns:
true if it is Rosh Chodesh. Rosh Hashana will return false

isKislevShort

public static boolean isKislevShort(int year)
Returns if Kislev is short in a given Jewish year. ND+ER

Parameters:
year - the Jewish year
Returns:
true if Kislev is short for the given Jewish year.

getDaysInJewishMonth

public 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

setDate

public void setDate(Calendar calendar)
Sets the date based on a Calendar object. Modifies the Jewish date as well.

Parameters:
calendar - the Calendar to set the calendar to

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

setGregorianDate

public void setGregorianDate(int year,
                             int month,
                             int dayOfMonth)
Sets the Gregorian Date, and updates the Jewish date accordingly. Confusingly unlike the Java Calendar where January has the value of 0,This expects a 1 for January this uses a

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

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. 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.
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.

getTime

public Date getTime()
Returns this object's date as a java.util.Date object. Note: This class does not have a concept of time.

Returns:
The Date

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"

forward

public void forward()
Rolls the date forward by 1. It modifies both the Gregorian and Jewish dates accordingly.


back

public void back()
Rolls the date back by 1. It modifies both the Gregorian and Jewish dates accordingly


equals

public boolean equals(Object object)
Compares two dates to see if they are equal

Overrides:
equals in class Object

compareTo

public int compareTo(Object o)
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

getGregorianMonth

public int getGregorianMonth()
Returns the Gregorian month (between 1-12).

Returns:
the Gregorian month (between 1-12). Unlike the java.util.Calendar, this will be 1 based and not 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).

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.

setGregorianMonth

public void setGregorianMonth(int month)
Sets the Gregorian month.

Parameters:
month - the Gregorian month

setGregorianYear

public void setGregorianYear(int year)
sets the Gregorian year.

Parameters:
year - the Gregorian year.

setGregorianDayOfMonth

public void setGregorianDayOfMonth(int dayOfMonth)
sets the Gregorian Day of month.

Parameters:
dayOfMonth - the Gregorian Day of month.

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

setJewishYear

public void setJewishYear(int year)
sets the Jewish year.

Parameters:
year - the Jewish year

setJewishDayOfMonth

public void setJewishDayOfMonth(int dayOfMonth)
sets the Jewish day of month.

Parameters:
dayOfMonth - the Jewish day of month

getDayOfOmer

public int getDayOfOmer()
Returns the int value of the Omer day or Integer.MIN_VALUE if the day is not in the omer

Returns:
The Omer count as an int or Integer.MIN_VALUE if it is not a day of the Omer.

getHoliday

public String getHoliday()
Returns a String of the Jewish holiday or fast day for the current day, or a null if there is no holiday for this day. Has no "modern" holidays.

Returns:
A String containing the holiday name or an empty string if it is not a holiday.

setInIsrael

public void setInIsrael(boolean inIsrael)
Sets whether to use Israel parsha and holiday scheme or not. Default is false.

Parameters:
inIsrael - set to true for calculations for Israel

getInIsrael

public boolean getInIsrael()
Gets whether Israel parsha and holiday scheme is used or not. The default (if not set) is false.

Returns:
if the if the calendar is set to Israel

getParsha

public String getParsha()
returns a string of today's parsha(ios) or an empty string if there are none. FIXME: consider possibly return the parsha of the week for any day during the week instead of empty. To do this the simple way, create a new instance of the class in the mothod, roll it to the next shabbos. If the shabbos has no parsha, keep rolling by a week till a parsha is encountered. Possibly turn into static method that takes in a year, month, day, roll to next shabbos (not that simple with the API for date passed in) and if it is not a shabbos roll forwarde one week at a time to get the parsha. I do not think it is possible to have more than 2 shabbosim in a row without a parsha, but I may be wrong.

Returns:
the string of the parsha. Will currently return blank for weekdays and a shabbos on a yom tov.

clone

public Object clone()
Create a copy of this date.

Overrides:
clone in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

KosherJava Zmanim Homepage

Copyright © 2004 - 2011 Eliyahu Hershfeld. All Rights Reserved. Released under the GPL 2 license