001/*
002 * Zmanim Java API
003 * Copyright (C) 2011 - 2022 Eliyahu Hershfeld
004 * Copyright (C) September 2002 Avrom Finkelstien
005 * Copyright (C) 2019 - 2022 Y Paritcher
006 *
007 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
008 * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
009 * any later version.
010 *
011 * This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied
012 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
013 * details.
014 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
015 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA,
016 * or connect to: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
017 */
018package com.kosherjava.zmanim.hebrewcalendar;
019
020import com.kosherjava.zmanim.util.GeoLocation;
021
022import java.time.LocalDate;
023import java.util.Calendar;
024import java.util.Date;
025import java.util.TimeZone;
026
027/**
028 * The JewishCalendar extends the JewishDate class and adds calendar methods.
029 * 
030 * This open source Java code was originally ported by <a href="http://www.facebook.com/avromf">Avrom Finkelstien</a>
031 * from his C++ code. It was refactored to fit the KosherJava Zmanim API with simplification of the code, enhancements
032 * and some bug fixing. The class allows setting whether the holiday and <em>parsha</em> scheme follows the Israel scheme
033 * or outside Israel scheme. The default is the outside Israel scheme.
034 * The parsha code was ported by Y. Paritcher from his <a href="https://github.com/yparitcher/libzmanim">libzmanim</a> code.
035 * 
036 * @todo Some do not belong in this class, but here is a partial list of what should still be implemented in some form:
037 * <ol>
038 * <li>Mishna yomis etc</li>
039 * </ol>
040 * 
041 * @see java.util.Date
042 * @see java.util.Calendar
043 * @author &copy; Y. Paritcher 2019 - 2022
044 * @author &copy; Avrom Finkelstien 2002
045 * @author &copy; Eliyahu Hershfeld 2011 - 2022
046 */
047public class JewishCalendar extends JewishDate {
048        /** The 14th day of Nissan, the day before of Pesach (Passover).*/
049        public static final int EREV_PESACH = 0;
050        /** The holiday of Pesach (Passover) on the 15th (and 16th out of Israel) day of Nissan.*/
051        public static final int PESACH = 1;
052        /** Chol Hamoed (interim days) of Pesach (Passover)*/
053        public static final int CHOL_HAMOED_PESACH = 2;
054        /**Pesach Sheni, the 14th day of Iyar, a minor holiday.*/
055        public static final int PESACH_SHENI = 3;
056        /**Erev Shavuos (the day before Shavuos), the 5th of Sivan*/
057        public static final int EREV_SHAVUOS = 4;
058        /**Shavuos (Pentecost), the 6th of Sivan*/
059        public static final int SHAVUOS = 5;
060        /** The fast of the 17th day of Tamuz*/
061        public static final int SEVENTEEN_OF_TAMMUZ = 6;
062        /** The fast of the 9th of Av*/
063        public static final int TISHA_BEAV = 7;
064        /** The 15th day of Av, a minor holiday*/
065        public static final int TU_BEAV = 8;
066        /**Erev Rosh Hashana (the day before Rosh Hashana), the 29th of Elul*/
067        public static final int EREV_ROSH_HASHANA = 9;
068        /** Rosh Hashana, the first of Tishrei.*/
069        public static final int ROSH_HASHANA = 10;
070        /** The fast of Gedalyah, the 3rd of Tishrei.*/
071        public static final int FAST_OF_GEDALYAH = 11;
072        /** The 9th day of Tishrei, the day before of Yom Kippur.*/
073        public static final int EREV_YOM_KIPPUR = 12;
074        /** The holiday of Yom Kippur, the 10th day of Tishrei*/
075        public static final int YOM_KIPPUR = 13;
076        /** The 14th day of Tishrei, the day before of Succos/Sukkos (Tabernacles).*/
077        public static final int EREV_SUCCOS = 14;
078        /** The holiday of Succos/Sukkos (Tabernacles), the 15th (and 16th out of Israel) day of Tishrei */
079        public static final int SUCCOS = 15;
080        /** Chol Hamoed (interim days) of Succos/Sukkos (Tabernacles)*/
081        public static final int CHOL_HAMOED_SUCCOS = 16;
082        /** Hoshana Rabba, the 7th day of Succos/Sukkos that occurs on the 21st of Tishrei. */
083        public static final int HOSHANA_RABBA = 17;
084        /** Shmini Atzeres, the 8th day of Succos/Sukkos is an independent holiday that occurs on the 22nd of Tishrei. */
085        public static final int SHEMINI_ATZERES = 18;
086        /** Simchas Torah, the 9th day of Succos/Sukkos, or the second day of Shmini Atzeres that is celebrated
087         * {@link #getInIsrael() out of Israel} on the 23rd of Tishrei.
088         */
089        public static final int SIMCHAS_TORAH = 19;
090        // public static final int EREV_CHANUKAH = 20;// probably remove this
091        /** The holiday of Chanukah. 8 days starting on the 25th day Kislev.*/
092        public static final int CHANUKAH = 21;
093        /** The fast of the 10th day of Teves.*/
094        public static final int TENTH_OF_TEVES = 22;
095        /** Tu Bishvat on the 15th day of Shevat, a minor holiday.*/
096        public static final int TU_BESHVAT = 23;
097        /** The fast of Esther, usually on the 13th day of Adar (or Adar II on leap years). It is earlier on some years.*/
098        public static final int FAST_OF_ESTHER = 24;
099        /** The holiday of Purim on the 14th day of Adar (or Adar II on leap years).*/
100        public static final int PURIM = 25;
101        /** The holiday of Shushan Purim on the 15th day of Adar (or Adar II on leap years).*/
102        public static final int SHUSHAN_PURIM = 26;
103        /** The holiday of Purim Katan on the 14th day of Adar I on a leap year when Purim is on Adar II, a minor holiday.*/
104        public static final int PURIM_KATAN = 27;
105        /**
106         * Rosh Chodesh, the new moon on the first day of the Jewish month, and the 30th day of the previous month in the
107         * case of a month with 30 days.
108         */
109        public static final int ROSH_CHODESH = 28;
110        /** Yom HaShoah, Holocaust Remembrance Day, usually held on the 27th of Nissan. If it falls on a Friday, it is moved
111         * to the 26th, and if it falls on a Sunday it is moved to the 28th. A {@link #isUseModernHolidays() modern holiday}.
112         */
113        public static final int YOM_HASHOAH = 29;
114        /**
115         * Yom HaZikaron, Israeli Memorial Day, held a day before Yom Ha'atzmaut.  A {@link #isUseModernHolidays() modern holiday}.
116         */
117        public static final int YOM_HAZIKARON = 30;
118        
119        /** Yom Ha'atzmaut, Israel Independence Day, the 5th of Iyar, but if it occurs on a Friday or Saturday, the holiday is
120         * moved back to Thursday, the 3rd of 4th of Iyar, and if it falls on a Monday, it is moved forward to Tuesday the
121         * 6th of Iyar.  A {@link #isUseModernHolidays() modern holiday}.*/
122        public static final int YOM_HAATZMAUT = 31;
123        /**
124         * Yom Yerushalayim or Jerusalem Day, on 28 Iyar. A {@link #isUseModernHolidays() modern holiday}.
125         */
126        public static final int YOM_YERUSHALAYIM = 32;
127        
128        /** The 33rd day of the Omer, the 18th of Iyar, a minor holiday.*/
129        public static final int LAG_BAOMER = 33;
130        
131        /** The holiday of Purim Katan on the 15th day of Adar I on a leap year when Purim is on Adar II, a minor holiday.*/
132        public static final int SHUSHAN_PURIM_KATAN = 34;
133        
134        /** The day following the last day of Pesach, Shavuos and Sukkos.*/
135        public static final int ISRU_CHAG = 35;
136        
137        /**
138         * The day before <em>Rosh Chodesh</em> (moved to Thursday if <em>Rosh Chodesh</em> is on a Friday or <em>Shabbos</em>) in most months.
139         * This constant is not actively in use.
140         * @see #isYomKippurKatan()
141         */
142        public static final int YOM_KIPPUR_KATAN = 36;
143        
144        /**
145         * The Monday, Thursday and Monday after the first <em>Shabbos</em> after <em>Rosh Chodesh Cheshvan</em> and <em>Iyar</em>) are BeHab
146         * days. This constant is not actively in use.
147         * @see #isBeHaB()
148         */
149        public static final int BEHAB = 37;
150
151        /**
152         * Is the calendar set to Israel, where some holidays have different rules.
153         * @see #getInIsrael()
154         * @see #setInIsrael(boolean)
155         */
156        private boolean inIsrael = false;
157        
158        /**
159         * Is the calendar set to have Purim <em>demukafim</em>, where Purim is celebrated on Shushan Purim.
160         * @see #getIsMukafChoma()
161         * @see #setIsMukafChoma(boolean)
162         */
163        private boolean isMukafChoma = false;
164
165        /**
166         * Is the calendar set to use modern Israeli holidays such as Yom Haatzmaut.
167         * @see #isUseModernHolidays()
168         * @see #setUseModernHolidays(boolean)
169         */
170        private boolean useModernHolidays = false;
171
172        /**
173         * List of <em>parshiyos</em>. {@link #NONE} indicates a week without a <em>parsha</em>, while the enum for the <em>parsha</em> of
174         * {@link #VZOS_HABERACHA} exists for consistency, but is not currently used.
175         */
176        public static enum Parsha {
177                /**NONE A week without any <em>parsha</em> such as <em>Shabbos Chol Hamoed</em> */NONE,
178                /**BERESHIS*/BERESHIS, /**NOACH*/NOACH, /**LECH_LECHA*/LECH_LECHA, /**VAYERA*/VAYERA, /**CHAYEI_SARA*/CHAYEI_SARA, /**TOLDOS*/TOLDOS, 
179                /**VAYETZEI*/VAYETZEI, /**VAYISHLACH*/VAYISHLACH, /**VAYESHEV*/VAYESHEV, /**MIKETZ*/MIKETZ, /**VAYIGASH*/VAYIGASH, /**VAYECHI*/VAYECHI,
180                /**SHEMOS*/SHEMOS, /**VAERA*/VAERA, /**BO*/BO, /**BESHALACH*/BESHALACH, /**YISRO*/YISRO, /**MISHPATIM*/MISHPATIM, /**TERUMAH*/TERUMAH,
181                /**TETZAVEH*/TETZAVEH, /***KI_SISA*/KI_SISA, /**VAYAKHEL*/VAYAKHEL, /**PEKUDEI*/PEKUDEI, /**VAYIKRA*/VAYIKRA, /**TZAV*/TZAV, /**SHMINI*/SHMINI, 
182                /**TAZRIA*/TAZRIA, /**METZORA*/METZORA, /**ACHREI_MOS*/ACHREI_MOS, /**KEDOSHIM*/KEDOSHIM, /**EMOR*/EMOR, /**BEHAR*/BEHAR, /**BECHUKOSAI*/BECHUKOSAI,
183                /**BAMIDBAR*/BAMIDBAR, /**NASSO*/NASSO, /**BEHAALOSCHA*/BEHAALOSCHA, /**SHLACH*/SHLACH, /**KORACH*/KORACH, /**CHUKAS*/CHUKAS, /**BALAK*/BALAK,
184                /**PINCHAS*/PINCHAS, /**MATOS*/MATOS, /**MASEI*/MASEI, /**DEVARIM*/DEVARIM, /**VAESCHANAN*/VAESCHANAN, /**EIKEV*/EIKEV, /**REEH*/REEH,
185                /**SHOFTIM*/SHOFTIM, /**KI_SEITZEI*/KI_SEITZEI, /**KI_SAVO*/KI_SAVO, /**NITZAVIM*/NITZAVIM, /**VAYEILECH*/VAYEILECH, /**HAAZINU*/HAAZINU,
186                /**VZOS_HABERACHA*/VZOS_HABERACHA, /**The double parsha of Vayakhel &amp; Peudei*/VAYAKHEL_PEKUDEI, /**The double <em>parsha</em> of Tazria
187                 * &amp; Metzora*/TAZRIA_METZORA,/**The double <em>parsha</em> of Achrei Mos &amp; Kedoshim*/ACHREI_MOS_KEDOSHIM,/**The double <em>parsha</em>
188                 * of Behar &amp; Bechukosai*/BEHAR_BECHUKOSAI,/**The double <em>parsha</em> of Chukas &amp; Balak*/CHUKAS_BALAK, /**The double
189                 * <em>parsha</em> of Matos &amp; Masei*/MATOS_MASEI,/**The double <em>parsha</em> of Nitzavim &amp; Vayelech*/NITZAVIM_VAYEILECH,
190                 /**The special <em>parsha</em> of Shekalim*/SHKALIM, /** The special <em>parsha</em> of Zachor*/ZACHOR, /**The special <em>parsha</em> of
191                  * Para*/PARA, /** The special <em>parsha</em> of Hachodesh*/HACHODESH
192        };
193        
194        /**
195         * An array of <em>parshiyos</em> in the 17 possible combinations.
196         */
197        public static final Parsha[][] parshalist = {
198                {Parsha.NONE, Parsha.VAYEILECH, Parsha.HAAZINU, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL_PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR_BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
199                {Parsha.NONE, Parsha.VAYEILECH, Parsha.HAAZINU, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL_PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR_BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NONE, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS_BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
200                {Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL_PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR_BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM},
201                {Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR_BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM},
202                {Parsha.NONE, Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL_PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR_BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM},
203                {Parsha.NONE, Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL_PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR_BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
204                {Parsha.NONE, Parsha.VAYEILECH, Parsha.HAAZINU, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.NONE, Parsha.ACHREI_MOS, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NONE, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS_BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
205                {Parsha.NONE, Parsha.VAYEILECH, Parsha.HAAZINU, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.NONE, Parsha.NONE, Parsha.ACHREI_MOS, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM},
206                {Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.ACHREI_MOS, Parsha.NONE, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS, Parsha.MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM},
207                {Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.ACHREI_MOS, Parsha.NONE, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS, Parsha.MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
208                {Parsha.NONE, Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.NONE, Parsha.ACHREI_MOS, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
209                {Parsha.NONE, Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.NONE, Parsha.ACHREI_MOS, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NONE, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS_BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
210                {Parsha.NONE, Parsha.VAYEILECH, Parsha.HAAZINU, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL_PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR_BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
211                {Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL_PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.NONE, Parsha.SHMINI, Parsha.TAZRIA_METZORA, Parsha.ACHREI_MOS_KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM},
212                {Parsha.NONE, Parsha.VAYEILECH, Parsha.HAAZINU, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.NONE, Parsha.ACHREI_MOS, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH},
213                {Parsha.NONE, Parsha.VAYEILECH, Parsha.HAAZINU, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.NONE, Parsha.ACHREI_MOS, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS, Parsha.MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM},
214                {Parsha.NONE, Parsha.NONE, Parsha.HAAZINU, Parsha.NONE, Parsha.NONE, Parsha.BERESHIS, Parsha.NOACH, Parsha.LECH_LECHA, Parsha.VAYERA, Parsha.CHAYEI_SARA, Parsha.TOLDOS, Parsha.VAYETZEI, Parsha.VAYISHLACH, Parsha.VAYESHEV, Parsha.MIKETZ, Parsha.VAYIGASH, Parsha.VAYECHI, Parsha.SHEMOS, Parsha.VAERA, Parsha.BO, Parsha.BESHALACH, Parsha.YISRO, Parsha.MISHPATIM, Parsha.TERUMAH, Parsha.TETZAVEH, Parsha.KI_SISA, Parsha.VAYAKHEL, Parsha.PEKUDEI, Parsha.VAYIKRA, Parsha.TZAV, Parsha.SHMINI, Parsha.TAZRIA, Parsha.METZORA, Parsha.NONE, Parsha.ACHREI_MOS, Parsha.KEDOSHIM, Parsha.EMOR, Parsha.BEHAR, Parsha.BECHUKOSAI, Parsha.BAMIDBAR, Parsha.NASSO, Parsha.BEHAALOSCHA, Parsha.SHLACH, Parsha.KORACH, Parsha.CHUKAS, Parsha.BALAK, Parsha.PINCHAS, Parsha.MATOS_MASEI, Parsha.DEVARIM, Parsha.VAESCHANAN, Parsha.EIKEV, Parsha.REEH, Parsha.SHOFTIM, Parsha.KI_SEITZEI, Parsha.KI_SAVO, Parsha.NITZAVIM_VAYEILECH}
215        };
216
217        /**
218         * Is this calendar set to return modern Israeli national holidays. By default this value is false. The holidays
219         * are {@link #YOM_HASHOAH <em>Yom HaShoah</em>}, {@link #YOM_HAZIKARON <em>Yom Hazikaron</em>}, {@link
220         * #YOM_HAATZMAUT <em>Yom Ha'atzmaut</em>} and {@link #YOM_YERUSHALAYIM <em>Yom Yerushalayim</em>}.
221         * 
222         * @return the useModernHolidays true if set to return modern Israeli national holidays
223         * 
224         * @see #setUseModernHolidays(boolean)
225         */
226        public boolean isUseModernHolidays() {
227                return useModernHolidays;
228        }
229
230        /**
231         * Sets the calendar to return modern Israeli national holidays. By default this value is false. The holidays are:
232         * {@link #YOM_HASHOAH <em>Yom HaShoah</em>}, {@link #YOM_HAZIKARON <em>Yom Hazikaron</em>}, {@link
233         * #YOM_HAATZMAUT <em>Yom Ha'atzmaut</em>} and {@link #YOM_YERUSHALAYIM <em>Yom Yerushalayim</em>}.
234         * 
235         * @param useModernHolidays
236         *            the useModernHolidays to set
237         * 
238         * @see #isUseModernHolidays()
239         */
240        public void setUseModernHolidays(boolean useModernHolidays) {
241                this.useModernHolidays = useModernHolidays;
242        }
243
244        /**
245         * Default constructor will set a default date to the current system date.
246         */
247        public JewishCalendar() {
248                super();
249        }
250
251        /**
252         * A constructor that initializes the date to the {@link java.util.Date Date} parameter.
253         * 
254         * @param date
255         *            the <code>Date</code> to set the calendar to
256         */
257        public JewishCalendar(Date date) {
258                super(date);
259        }
260
261        /**
262         * A constructor that initializes the date to the {@link java.util.Calendar Calendar} parameter.
263         * 
264         * @param calendar
265         *            the <code>Calendar</code> to set the calendar to
266         */
267        public JewishCalendar(Calendar calendar) {
268                super(calendar);
269        }
270
271        /**
272         * A constructor that initializes the date to the {@link java.time.LocalDate LocalDate} parameter.
273         * 
274         * @param localDate
275         *            the <code>LocalDate</code> to set the calendar to
276         */
277        public JewishCalendar(LocalDate localDate) {
278                super(localDate);
279        }
280
281        /**
282         * Creates a Jewish date based on a Jewish year, month and day of month.
283         * 
284         * @param jewishYear
285         *            the Jewish year
286         * @param jewishMonth
287         *            the Jewish month. The method expects a 1 for Nissan ... 12 for Adar and 13 for Adar II. Use the
288         *            constants {@link #NISSAN} ... {@link #ADAR} (or {@link #ADAR_II} for a leap year Adar II) to avoid any
289         *            confusion.
290         * @param jewishDayOfMonth
291         *            the Jewish day of month. If 30 is passed in for a month with only 29 days (for example {@link #IYAR},
292         *            or {@link #KISLEV} in a year that {@link #isKislevShort()}), the 29th (last valid date of the month)
293         *            will be set
294         * @throws IllegalArgumentException
295         *             if the day of month is &lt; 1 or &gt; 30, or a year of &lt; 0 is passed in.
296         */
297        public JewishCalendar(int jewishYear, int jewishMonth, int jewishDayOfMonth) {
298                super(jewishYear, jewishMonth, jewishDayOfMonth);
299        }
300
301        /**
302         * Creates a Jewish date based on a Jewish date and whether in Israel
303         * 
304         * @param jewishYear
305         *            the Jewish year
306         * @param jewishMonth
307         *            the Jewish month. The method expects a 1 for <em>Nissan</em> ... 12 for <em>Adar</em> and 13 for
308         *            <em>Adar II</em>. Use the constants {@link #NISSAN} ... {@link #ADAR} (or {@link #ADAR_II} for a
309         *            leap year Adar II) to avoid any confusion.
310         * @param jewishDayOfMonth
311         *            the Jewish day of month. If 30 is passed in for a month with only 29 days (for example {@link #IYAR},
312         *            or {@link #KISLEV} in a year that {@link #isKislevShort()}), the 29th (last valid date of the month)
313         *            will be set.
314         * @param inIsrael
315         *            whether in Israel. This affects <em>Yom Tov</em> calculations
316         */
317        public JewishCalendar(int jewishYear, int jewishMonth, int jewishDayOfMonth, boolean inIsrael) {
318                super(jewishYear, jewishMonth, jewishDayOfMonth);
319                setInIsrael(inIsrael);
320        }
321
322        /**
323         * Sets whether to use Israel holiday scheme or not. Default is false.
324         * 
325         * @param inIsrael
326         *            set to true for calculations for Israel
327         * 
328         * @see #getInIsrael()
329         */
330        public void setInIsrael(boolean inIsrael) {
331                this.inIsrael = inIsrael;
332        }
333
334        /**
335         * Gets whether Israel holiday scheme is used or not. The default (if not set) is false.
336         * 
337         * @return if the calendar is set to Israel
338         * 
339         * @see #setInIsrael(boolean)
340         */
341        public boolean getInIsrael() {
342                return inIsrael;
343        }
344        
345        /**
346         * Returns if the city is set as a city surrounded by a wall from the time of Yehoshua, and Shushan Purim
347         * should be celebrated as opposed to regular Purim.
348         * @return if the city is set as a city surrounded by a wall from the time of Yehoshua, and Shushan Purim
349         *         should be celebrated as opposed to regular Purim.
350         * @see #setIsMukafChoma(boolean)
351         */
352        public boolean getIsMukafChoma() {
353                return isMukafChoma;
354        }
355
356        /**
357         * Sets if the location is surrounded by a wall from the time of Yehoshua, and Shushan Purim should be
358         * celebrated as opposed to regular Purim. This should be set for Yerushalayim, Shushan and other cities.
359         * @param isMukafChoma is the city surrounded by a wall from the time of Yehoshua.
360         * 
361         * @see #getIsMukafChoma()
362         */
363        public void setIsMukafChoma(boolean isMukafChoma) {
364                this.isMukafChoma = isMukafChoma;
365        }
366        
367        /**
368         * <a href="https://en.wikipedia.org/wiki/Birkat_Hachama">Birkas Hachamah</a> is recited every 28 years based on
369         * <em>Tekufas Shmuel</em> (Julian years) that a year is 365.25 days. The <a href="https://en.wikipedia.org/wiki/Maimonides"
370         * >Rambam</a> in <a href="http://hebrewbooks.org/pdfpager.aspx?req=14278&amp;st=&amp;pgnum=323">Hilchos Kiddush Hachodesh 9:3</a>
371         * states that <em>tekufas Nissan</em> of year 1 was 7 days + 9 hours before <em>molad Nissan</em>. This is calculated as every
372         * 10,227 days (28 * 365.25).  
373         * @return true for a day that <em>Birkas Hachamah</em> is recited.
374         */
375        public boolean isBirkasHachamah() {
376                int elapsedDays = getJewishCalendarElapsedDays(getJewishYear()); //elapsed days since molad ToHu
377                elapsedDays = elapsedDays + getDaysSinceStartOfJewishYear(); //elapsed days to the current calendar date
378                
379                /* Molad Nissan year 1 was 177 days after molad tohu of Tishrei. We multiply 29.5 days * 6 months from Tishrei
380                 * to Nissan = 177. Subtract 7 days since tekufas Nissan was 7 days and 9 hours before the molad as stated in the Rambam
381                 * and we are now at 170 days. Because getJewishCalendarElapsedDays and getDaysSinceStartOfJewishYear use the value for
382                 * Rosh Hashana as 1, we have to add 1 day for a total of 171. To this add a day since the tekufah is on a Tuesday
383                 * night and we push off the bracha to Wednesday AM resulting in the 172 used in the calculation.
384                 */
385                if (elapsedDays % (28 * 365.25) == 172) { // 28 years of 365.25 days + the offset from molad tohu mentioned above
386                        return true;
387                }
388                return false;
389        }
390
391        /**
392         * Return the type of year for <em>parsha</em> calculations. The algorithm follows the
393         * <a href="http://hebrewbooks.org/pdfpager.aspx?req=14268&amp;st=&amp;pgnum=222">Luach Arba'ah Shearim</a> in the Tur Ohr Hachaim.
394         * @return the type of year for <em>parsha</em> calculations.
395         */
396        private int getParshaYearType() {
397                int roshHashanaDayOfWeek = (getJewishCalendarElapsedDays(getJewishYear()) + 1) % 7; // plus one to the original Rosh Hashana of year 1 to get a week starting on Sunday
398                if (roshHashanaDayOfWeek == 0) {
399                        roshHashanaDayOfWeek = 7; // convert 0 to 7 for Shabbos for readability
400                }
401                if (isJewishLeapYear()) {
402                        switch (roshHashanaDayOfWeek) {
403                        case Calendar.MONDAY:
404                                if (isKislevShort()) { //BaCh
405                                        if (getInIsrael()) {
406                                                return 14;
407                                        }
408                                        return 6;
409                                }
410                                if (isCheshvanLong()) { //BaSh
411                                        if (getInIsrael()) {
412                                                return 15;
413                                        }
414                                        return 7;
415                                }
416                                break;
417                        case Calendar.TUESDAY: //Gak
418                                if (getInIsrael()) {
419                                        return 15;
420                                }
421                                return 7;
422                        case Calendar.THURSDAY:
423                                if (isKislevShort()) { //HaCh
424                                        return 8;
425                                }
426                                if (isCheshvanLong()) { //HaSh
427                                        return 9;
428                                }
429                                break;
430                        case Calendar.SATURDAY:
431                                if (isKislevShort()) { //ZaCh
432                                        return 10;
433                                }
434                                if (isCheshvanLong()) { //ZaSh
435                                        if (getInIsrael()) {
436                                                return 16;
437                                        }
438                                        return 11;
439                                }
440                                break;
441                        }
442                } else { //not a leap year
443                        switch (roshHashanaDayOfWeek) {
444                        case Calendar.MONDAY:
445                                if (isKislevShort()) { //BaCh
446                                        return 0;
447                                }
448                                if (isCheshvanLong()) { //BaSh
449                                        if (getInIsrael()) {
450                                                return 12;
451                                        }
452                                        return 1;
453                                }
454                                break;
455                        case Calendar.TUESDAY: //GaK
456                                if (getInIsrael()) {
457                                        return 12;
458                                }
459                                return 1;
460                        case Calendar.THURSDAY:
461                                if (isCheshvanLong()) { //HaSh
462                                        return 3;
463                                }
464                                if (!isKislevShort()) { //Hak
465                                        if (getInIsrael()) {
466                                                return 13;
467                                        }
468                                        return 2;
469                                }
470                                break;
471                        case Calendar.SATURDAY:
472                                if (isKislevShort()) { //ZaCh
473                                        return 4;
474                                }
475                                if (isCheshvanLong()) { //ZaSh
476                                        return 5;
477                                }
478                                break;
479                        }
480                }
481                return -1; //keep the compiler happy
482        }
483
484        /**
485         * Returns this week's {@link Parsha <em>Parsha</em>} if it is <em>Shabbos</em>. It returns {@link Parsha#NONE} if the date
486         * is a weekday or if there is no <em>parsha</em> that week (for example <em>Yom Tov</em> that falls on a <em>Shabbos</em>).
487         * 
488         * @return the current <em>parsha</em>.
489         */
490        public Parsha getParshah() {
491                if (getDayOfWeek() != Calendar.SATURDAY) {
492                        return Parsha.NONE;
493                }
494                
495                int yearType = getParshaYearType();
496                int roshHashanaDayOfWeek = getJewishCalendarElapsedDays(getJewishYear()) % 7;
497                int day = roshHashanaDayOfWeek + getDaysSinceStartOfJewishYear();
498                
499                if (yearType >= 0) { // negative year should be impossible, but let's cover all bases
500                        return parshalist[yearType][day/7];
501                }
502                return Parsha.NONE; //keep the compiler happy
503        }
504        
505        /**
506         * Returns the upcoming {@link Parsha <em>Parsha</em>} regardless of if it is the weekday or <em>Shabbos</em> (where next
507         * Shabbos's <em>Parsha</em> will be returned. This is unlike {@link #getParshah()} that returns {@link Parsha#NONE} if
508         * the date is not <em>Shabbos</em>. If the upcoming Shabbos is a <em>Yom Tov</em> and has no <em>Parsha</em>, the
509         * following week's <em>Parsha</em> will be returned.
510         * 
511         * @return the upcoming <em>parsha</em>.
512         */
513        public Parsha getUpcomingParshah() {
514                JewishCalendar clone = (JewishCalendar) clone();
515                int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek()  + 7) % 7;
516                if (getDayOfWeek() != Calendar.SATURDAY) {
517                        clone.forward(Calendar.DATE, daysToShabbos);
518                } else {
519                        clone.forward(Calendar.DATE, 7);
520                }
521                while(clone.getParshah() == Parsha.NONE) { //Yom Kippur / Sukkos or Pesach with 2 potential non-parsha Shabbosim in a row
522                        clone.forward(Calendar.DATE, 7);
523                }
524                return clone.getParshah();
525        }
526        
527        /**
528         * Returns a {@link Parsha <em>Parsha</em>} enum if the <em>Shabbos</em> is one of the four <em>parshiyos</em> of {@link
529         * Parsha#SHKALIM <em>Shkalim</em>}, {@link Parsha#ZACHOR <em>Zachor</em>}, {@link Parsha#PARA <em>Para</em>}, {@link
530         * Parsha#HACHODESH <em>Hachdesh</em>} or {@link Parsha#NONE Parsha.NONE} for a regular <em>Shabbos</em> (or any weekday).
531         * 
532         * @return one of the four <em>parshiyos</em> of {@link Parsha#SHKALIM <em>Shkalim</em>} {@link Parsha#ZACHOR 
533         *         <em>Zachor</em>}, {@link Parsha#PARA <em>Para</em>}, {@link Parsha#HACHODESH <em>Hachdesh</em>} or {@link
534         *         Parsha#NONE Parsha.NONE}.
535         */
536        public Parsha getSpecialShabbos() {
537                if (getDayOfWeek() == Calendar.SATURDAY)        {
538                        if ((getJewishMonth() == SHEVAT && !isJewishLeapYear()) || (getJewishMonth() == ADAR && isJewishLeapYear())) {
539                                if (getJewishDayOfMonth() == 25 || getJewishDayOfMonth() == 27 || getJewishDayOfMonth() == 29) {
540                                        return Parsha.SHKALIM;
541                                }
542                        }
543                        if ((getJewishMonth() == ADAR && !isJewishLeapYear()) || getJewishMonth() == ADAR_II) {
544                                if (getJewishDayOfMonth() == 1) {
545                                        return Parsha.SHKALIM;
546                                }
547                                if (getJewishDayOfMonth() == 8 || getJewishDayOfMonth() == 9 || getJewishDayOfMonth() == 11 || getJewishDayOfMonth() == 13) {
548                                        return Parsha.ZACHOR;
549                                }
550                                if (getJewishDayOfMonth() == 18 || getJewishDayOfMonth() == 20 || getJewishDayOfMonth() == 22 || getJewishDayOfMonth() == 23) {
551                                        return Parsha.PARA;
552                                }
553                                if (getJewishDayOfMonth() == 25 || getJewishDayOfMonth() == 27 || getJewishDayOfMonth() == 29) {
554                                        return Parsha.HACHODESH;
555                                }
556                        }
557                        if (getJewishMonth() == NISSAN && getJewishDayOfMonth() == 1) {
558                                return Parsha.HACHODESH;
559                        }
560                }
561                return Parsha.NONE;
562        }
563
564        /**
565         * Returns an index of the Jewish holiday or fast day for the current day, or a -1 if there is no holiday for this day.
566         * There are constants in this class representing each <em>Yom Tov</em>. Formatting of the <em>Yomim tovim</em> is done
567         * in the {@link HebrewDateFormatter#formatYomTov(JewishCalendar)}.
568         * 
569         * @todo Consider using enums instead of the constant ints.
570         * 
571         * @return the index of the holiday such as the constant {@link #LAG_BAOMER} or {@link #YOM_KIPPUR} or a -1 if it is not a holiday.
572         * 
573         * @see HebrewDateFormatter#formatYomTov(JewishCalendar)
574         */
575        public int getYomTovIndex() {
576                final int day = getJewishDayOfMonth();
577                final int dayOfWeek = getDayOfWeek();
578
579                // check by month (starting from Nissan)
580                switch (getJewishMonth()) {
581                case NISSAN:
582                        if (day == 14) {
583                                return EREV_PESACH;
584                        }
585                        if (day == 15 || day == 21
586                                        || (!inIsrael && (day == 16 || day == 22))) {
587                                return PESACH;
588                        }
589                        if (day >= 17 && day <= 20
590                                        || (day == 16 && inIsrael)) {
591                                return CHOL_HAMOED_PESACH;
592                        }
593                        if ((day == 22 && inIsrael) || (day == 23 && !inIsrael)) {
594                                return ISRU_CHAG;
595                        }
596                        if (isUseModernHolidays()
597                                        && ((day == 26 && dayOfWeek == Calendar.THURSDAY)
598                                                        || (day == 28 && dayOfWeek == Calendar.MONDAY)
599                                                        || (day == 27 && dayOfWeek != Calendar.SUNDAY && dayOfWeek != Calendar.FRIDAY))) {
600                                return YOM_HASHOAH;
601                        }
602                        break;
603                case IYAR:
604                        if (isUseModernHolidays()
605                                        && ((day == 4 && dayOfWeek == Calendar.TUESDAY)
606                                                        || ((day == 3 || day == 2) && dayOfWeek == Calendar.WEDNESDAY) || (day == 5 && dayOfWeek == Calendar.MONDAY))) {
607                                return YOM_HAZIKARON;
608                        }
609                        // if 5 Iyar falls on Wed, Yom Haatzmaut is that day. If it fal1s on Friday or Shabbos, it is moved back to
610                        // Thursday. If it falls on Monday it is moved to Tuesday
611                        if (isUseModernHolidays()
612                                        && ((day == 5 && dayOfWeek == Calendar.WEDNESDAY)
613                                                        || ((day == 4 || day == 3) && dayOfWeek == Calendar.THURSDAY) || (day == 6 && dayOfWeek == Calendar.TUESDAY))) {
614                                return YOM_HAATZMAUT;
615                        }
616                        if (day == 14) {
617                                return PESACH_SHENI;
618                        }
619                        if (day == 18) {
620                                return LAG_BAOMER;
621                        }
622                        if (isUseModernHolidays() && day == 28) {
623                                return YOM_YERUSHALAYIM;
624                        }
625                        break;
626                case SIVAN:
627                        if (day == 5) {
628                                return EREV_SHAVUOS;
629                        }
630                        if (day == 6 || (day == 7 && !inIsrael)) {
631                                return SHAVUOS;
632                        }
633                        if ((day == 7 && inIsrael) || (day == 8 && !inIsrael)) {
634                                return ISRU_CHAG;
635                        }
636                        break;
637                case TAMMUZ:
638                        // push off the fast day if it falls on Shabbos
639                        if ((day == 17 && dayOfWeek != Calendar.SATURDAY)
640                                        || (day == 18 && dayOfWeek == Calendar.SUNDAY)) {
641                                return SEVENTEEN_OF_TAMMUZ;
642                        }
643                        break;
644                case AV:
645                        // if Tisha B'av falls on Shabbos, push off until Sunday
646                        if ((dayOfWeek == Calendar.SUNDAY && day == 10)
647                                        || (dayOfWeek != Calendar.SATURDAY && day == 9)) {
648                                return TISHA_BEAV;
649                        }
650                        if (day == 15) {
651                                return TU_BEAV;
652                        }
653                        break;
654                case ELUL:
655                        if (day == 29) {
656                                return EREV_ROSH_HASHANA;
657                        }
658                        break;
659                case TISHREI:
660                        if (day == 1 || day == 2) {
661                                return ROSH_HASHANA;
662                        }
663                        if ((day == 3 && dayOfWeek != Calendar.SATURDAY) || (day == 4 && dayOfWeek == Calendar.SUNDAY)) {
664                                // push off Tzom Gedalia if it falls on Shabbos
665                                return FAST_OF_GEDALYAH;
666                        }
667                        if (day == 9) {
668                                return EREV_YOM_KIPPUR;
669                        }
670                        if (day == 10) {
671                                return YOM_KIPPUR;
672                        }
673                        if (day == 14) {
674                                return EREV_SUCCOS;
675                        }
676                        if (day == 15 || (day == 16 && !inIsrael)) {
677                                return SUCCOS;
678                        }
679                        if (day >= 17 && day <= 20 || (day == 16 && inIsrael)) {
680                                return CHOL_HAMOED_SUCCOS;
681                        }
682                        if (day == 21) {
683                                return HOSHANA_RABBA;
684                        }
685                        if (day == 22) {
686                                return SHEMINI_ATZERES;
687                        }
688                        if (day == 23 && !inIsrael) {
689                                return SIMCHAS_TORAH;
690                        }
691                        if ((day == 23 && inIsrael) || (day == 24 && !inIsrael)) {
692                                return ISRU_CHAG;
693                        }
694                        break;
695                case KISLEV: // no yomtov in CHESHVAN
696                        // if (day == 24) {
697                        // return EREV_CHANUKAH;
698                        // } else
699                        if (day >= 25) {
700                                return CHANUKAH;
701                        }
702                        break;
703                case TEVES:
704                        if (day == 1 || day == 2
705                                        || (day == 3 && isKislevShort())) {
706                                return CHANUKAH;
707                        }
708                        if (day == 10) {
709                                return TENTH_OF_TEVES;
710                        }
711                        break;
712                case SHEVAT:
713                        if (day == 15) {
714                                return TU_BESHVAT;
715                        }
716                        break;
717                case ADAR:
718                        if (!isJewishLeapYear()) {
719                                // if 13th Adar falls on Friday or Shabbos, push back to Thursday
720                                if (((day == 11 || day == 12) && dayOfWeek == Calendar.THURSDAY)
721                                                || (day == 13 && !(dayOfWeek == Calendar.FRIDAY || dayOfWeek == Calendar.SATURDAY))) {
722                                        return FAST_OF_ESTHER;
723                                }
724                                if (day == 14) {
725                                        return PURIM;
726                                }
727                                if (day == 15) {
728                                        return SHUSHAN_PURIM;
729                                }
730                        } else { // else if a leap year
731                                if (day == 14) {
732                                        return PURIM_KATAN;
733                                }
734                                if (day == 15) {
735                                        return SHUSHAN_PURIM_KATAN;
736                                }
737                        }
738                        break;
739                case ADAR_II:
740                        // if 13th Adar falls on Friday or Shabbos, push back to Thursday
741                        if (((day == 11 || day == 12) && dayOfWeek == Calendar.THURSDAY)
742                                        || (day == 13 && !(dayOfWeek == Calendar.FRIDAY || dayOfWeek == Calendar.SATURDAY))) {
743                                return FAST_OF_ESTHER;
744                        }
745                        if (day == 14) {
746                                return PURIM;
747                        }
748                        if (day == 15) {
749                                return SHUSHAN_PURIM;
750                        }
751                        break;
752                }
753                // if we get to this stage, then there are no holidays for the given date return -1
754                return -1;
755        }
756
757        /**
758         * Returns true if the current day is <em>Yom Tov</em>. The method returns true even for holidays such as {@link #CHANUKAH}
759         * and minor ones such as {@link #TU_BEAV} and {@link #PESACH_SHENI}. <em>Erev Yom Tov</em> (with the exception of
760         * {@link #HOSHANA_RABBA}, <em>erev</em> the second days of {@link #PESACH}) returns false, as do {@link #isTaanis() fast
761         * days} besides {@link #YOM_KIPPUR}. Use {@link #isAssurBemelacha()} to find the days that have a prohibition of work. 
762         * 
763         * @return true if the current day is a Yom Tov
764         * 
765         * @see #getYomTovIndex()
766         * @see #isErevYomTov()
767         * @see #isErevYomTovSheni()
768         * @see #isTaanis()
769         * @see #isAssurBemelacha()
770         * @see #isCholHamoed()
771         */
772        public boolean isYomTov() {
773                int holidayIndex = getYomTovIndex();
774                if ((isErevYomTov() && (holidayIndex != HOSHANA_RABBA && (holidayIndex == CHOL_HAMOED_PESACH && getJewishDayOfMonth() != 20)))
775                                || (isTaanis() && holidayIndex != YOM_KIPPUR) || holidayIndex == ISRU_CHAG) {
776                        return false;
777                }
778                return getYomTovIndex() != -1;
779        }
780
781        /**
782         * Returns true if the <em>Yom Tov</em> day has a <em>melacha</em> (work)  prohibition. This method will return false for a
783         * non-<em>Yom Tov</em> day, even if it is <em>Shabbos</em>.
784         *
785         * @return if the <em>Yom Tov</em> day has a <em>melacha</em> (work)  prohibition.
786         */
787        public boolean isYomTovAssurBemelacha() {
788                int holidayIndex = getYomTovIndex();
789                return holidayIndex == PESACH || holidayIndex == SHAVUOS || holidayIndex == SUCCOS || holidayIndex == SHEMINI_ATZERES ||
790                                holidayIndex == SIMCHAS_TORAH || holidayIndex == ROSH_HASHANA  || holidayIndex == YOM_KIPPUR;
791        }
792        
793        /**
794         * Returns true if it is <em>Shabbos</em> or if it is a <em>Yom Tov</em> day that has a <em>melacha</em> (work)  prohibition.
795         * 
796         * @return if the day is a <em>Yom Tov</em> that is <em>assur bemlacha</em> or <em>Shabbos</em>
797         */
798        public boolean isAssurBemelacha() {
799                return getDayOfWeek() == Calendar.SATURDAY || isYomTovAssurBemelacha();
800        }
801        
802        /**
803         * Returns true if the day has candle lighting. This will return true on <em>Erev Shabbos</em>, <em>Erev Yom Tov</em>, the
804         * first day of <em>Rosh Hashana</em> and the first days of <em>Yom Tov</em> out of Israel. It is identical
805         * to calling {@link #isTomorrowShabbosOrYomTov()}.
806         * 
807         * @return if the day has candle lighting.
808         * 
809         * @see #isTomorrowShabbosOrYomTov()
810         */
811        public boolean hasCandleLighting() {
812                return isTomorrowShabbosOrYomTov();
813        }
814        
815        /**
816         * Returns true if tomorrow is <em>Shabbos</em> or <em>Yom Tov</em>. This will return true on <em>Erev Shabbos</em>,
817         * <em>Erev Yom Tov</em>, the first day of <em>Rosh Hashana</em> and <em>erev</em> the first days of <em>Yom Tov</em>
818         * out of Israel. It is identical to calling {@link #hasCandleLighting()}.
819         * 
820         * @return will return if the next day is <em>Shabbos</em> or <em>Yom Tov</em>.
821         * 
822         * @see #hasCandleLighting()
823         */
824        public boolean isTomorrowShabbosOrYomTov() {
825                return getDayOfWeek() == Calendar.FRIDAY || isErevYomTov() || isErevYomTovSheni();
826        }
827        
828        /**
829         * Returns true if the day is the second day of <em>Yom Tov</em>. This impacts the second day of <em>Rosh Hashana</em> everywhere and
830         * the second days of Yom Tov in <em>chutz laaretz</em> (out of Israel).
831         * 
832         * @return  if the day is the second day of <em>Yom Tov</em>.
833         */
834        public boolean isErevYomTovSheni() {
835                return (getJewishMonth() == TISHREI && (getJewishDayOfMonth() == 1))
836                || (! getInIsrael()
837                                && ((getJewishMonth() == NISSAN && (getJewishDayOfMonth() == 15 || getJewishDayOfMonth() == 21))
838                                || (getJewishMonth() == TISHREI && (getJewishDayOfMonth() == 15 || getJewishDayOfMonth() == 22))
839                                || (getJewishMonth() == SIVAN && getJewishDayOfMonth() == 6 )));
840        }
841
842        /**
843         * Returns true if the current day is <em>Aseres Yemei Teshuva</em>.
844         * 
845         * @return if the current day is <em>Aseres Yemei Teshuvah</em>
846         */
847        public boolean isAseresYemeiTeshuva() {
848                return getJewishMonth() == TISHREI && getJewishDayOfMonth() <= 10;
849        }
850        
851        /**
852         * Returns true if the current day is <em>Pesach</em> (either  the <em>Yom Tov</em> of <em>Pesach</em> or<em>Chol Hamoed Pesach</em>).
853         * 
854         * @return true if the current day is <em>Pesach</em> (either  the <em>Yom Tov</em> of <em>Pesach</em> or<em>Chol Hamoed Pesach</em>).
855         * @see #isYomTov()
856         * @see #isCholHamoedPesach()
857         * @see #PESACH
858         * @see #CHOL_HAMOED_PESACH
859         */
860        public boolean isPesach() {
861                int holidayIndex = getYomTovIndex();
862                return holidayIndex == PESACH || holidayIndex == CHOL_HAMOED_PESACH;
863        }
864        
865        /**
866         * Returns true if the current day is <em>Chol Hamoed</em> of <em>Pesach</em>.
867         *
868         * @return true if the current day is <em>Chol Hamoed</em> of <em>Pesach</em>
869         * @see #isYomTov()
870         * @see #isPesach()
871         * @see #CHOL_HAMOED_PESACH
872         */
873        public boolean isCholHamoedPesach() {
874                int holidayIndex = getYomTovIndex();
875                return holidayIndex == CHOL_HAMOED_PESACH;
876        }
877        
878        /**
879         * Returns true if the current day is <em>Shavuos</em>.
880         *
881         * @return true if the current day is <em>Shavuos</em>.
882         * @see #isYomTov()
883         * @see #SHAVUOS
884         */
885        public boolean isShavuos() {
886                int holidayIndex = getYomTovIndex();
887                return holidayIndex == SHAVUOS;
888        }
889        
890        /**
891         * Returns true if the current day is <em>Rosh Hashana</em>.
892         *
893         * @return true if the current day is <em>Rosh Hashana</em>.
894         * @see #isYomTov()
895         * @see #ROSH_HASHANA
896         */
897        public boolean isRoshHashana() {
898                int holidayIndex = getYomTovIndex();
899                return holidayIndex == ROSH_HASHANA;
900        }
901        
902        /**
903         * Returns true if the current day is <em>Yom Kippur</em>.
904         *
905         * @return true if the current day is <em>Yom Kippur</em>.
906         * @see #isYomTov()
907         * @see #YOM_KIPPUR
908         */
909        public boolean isYomKippur() {
910                int holidayIndex = getYomTovIndex();
911                return holidayIndex == YOM_KIPPUR;
912        }
913        
914        /**
915         * Returns true if the current day is <em>Succos</em> (either  the <em>Yom Tov</em> of <em>Succos</em> or<em>Chol Hamoed Succos</em>).
916         * It will return false for {@link #isShminiAtzeres() Shmini Atzeres} and {@link #isSimchasTorah() Simchas Torah}.
917         * 
918         * @return true if the current day is <em>Succos</em> (either  the <em>Yom Tov</em> of <em>Succos</em> or<em>Chol Hamoed Succos</em>.
919         * @see #isYomTov()
920         * @see #isCholHamoedSuccos()
921         * @see #isHoshanaRabba()
922         * @see #SUCCOS
923         * @see #CHOL_HAMOED_SUCCOS
924         * @see #HOSHANA_RABBA
925         */
926        public boolean isSuccos() {
927                int holidayIndex = getYomTovIndex();
928                return holidayIndex == SUCCOS || holidayIndex == CHOL_HAMOED_SUCCOS || holidayIndex == HOSHANA_RABBA;
929        }
930        
931        /**
932         * Returns true if the current day is <em>Hoshana Rabba</em>.
933         *
934         * @return true true if the current day is <em>Hoshana Rabba</em>.
935         * @see #isYomTov()
936         * @see #HOSHANA_RABBA
937         */
938        public boolean isHoshanaRabba() {
939                int holidayIndex = getYomTovIndex();
940                return holidayIndex == HOSHANA_RABBA;
941        }
942        
943        /**
944         * Returns true if the current day is <em>Shmini Atzeres</em>.
945         *
946         * @return true if the current day is <em>Shmini Atzeres</em>.
947         * @see #isYomTov()
948         * @see #SHEMINI_ATZERES
949         */
950        public boolean isShminiAtzeres() {
951                int holidayIndex = getYomTovIndex();
952                return holidayIndex == SHEMINI_ATZERES;
953        }
954        
955        /**
956         * Returns true if the current day is <em>Simchas Torah</em>. This will always return false if {@link #getInIsrael() in Israel}
957         *
958         * @return true if the current day is <em>Shmini Atzeres</em>.
959         * @see #isYomTov()
960         * @see #SIMCHAS_TORAH
961         */
962        public boolean isSimchasTorah() {
963                int holidayIndex = getYomTovIndex();
964                //if in Israel, Holiday index of SIMCHAS_TORAH will not be returned by getYomTovIndex()
965                return holidayIndex == SIMCHAS_TORAH;
966        }
967        
968        /**
969         * Returns true if the current day is <em>Chol Hamoed</em> of <em>Succos</em>.
970         *
971         * @return true if the current day is <em>Chol Hamoed</em> of <em>Succos</em>
972         * @see #isYomTov()
973         * @see #CHOL_HAMOED_SUCCOS
974         */
975        public boolean isCholHamoedSuccos() {
976                int holidayIndex = getYomTovIndex();
977                return holidayIndex == CHOL_HAMOED_SUCCOS || holidayIndex == HOSHANA_RABBA;
978        }
979        
980        /**
981         * Returns true if the current day is <em>Chol Hamoed</em> of <em>Pesach</em> or <em>Succos</em>.
982         * 
983         * @return true if the current day is <em>Chol Hamoed</em> of <em>Pesach</em> or <em>Succos</em>
984         * @see #isYomTov()
985         * @see #CHOL_HAMOED_PESACH
986         * @see #CHOL_HAMOED_SUCCOS
987         */
988        public boolean isCholHamoed() {
989                return isCholHamoedPesach() || isCholHamoedSuccos();
990        }
991
992        /**
993         * Returns true if the current day is <em>Erev Yom Tov</em>. The method returns true for <em>Erev</em> - <em>Pesach</em>
994         * (first and last days), <em>Shavuos</em>, <em>Rosh Hashana</em>, <em>Yom Kippur</em>, <em>Succos</em> and <em>Hoshana
995         * Rabba</em>.
996         * 
997         * @return true if the current day is <em>Erev</em> - <em>Pesach</em>, <em>Shavuos</em>, <em>Rosh Hashana</em>, <em>Yom
998         * Kippur</em>, <em>Succos</em> and <em>Hoshana Rabba</em>.
999         * @see #isYomTov()
1000         * @see #isErevYomTovSheni()
1001         */
1002        public boolean isErevYomTov() {
1003                int holidayIndex = getYomTovIndex();
1004                return holidayIndex == EREV_PESACH || holidayIndex == EREV_SHAVUOS || holidayIndex == EREV_ROSH_HASHANA
1005                                || holidayIndex == EREV_YOM_KIPPUR || holidayIndex == EREV_SUCCOS || holidayIndex == HOSHANA_RABBA
1006                                || (holidayIndex == CHOL_HAMOED_PESACH && getJewishDayOfMonth() == 20);
1007        }
1008
1009        /**
1010         * Returns true if the current day is <em>Erev Rosh Chodesh</em>. Returns false for <em>Erev Rosh Hashana</em>.
1011         * 
1012         * @return true if the current day is <em>Erev Rosh Chodesh</em>. Returns false for <em>Erev Rosh Hashana</em>.
1013         * @see #isRoshChodesh()
1014         */
1015        public boolean isErevRoshChodesh() {
1016                // Erev Rosh Hashana is not Erev Rosh Chodesh.
1017                return (getJewishDayOfMonth() == 29 && getJewishMonth() != ELUL);
1018        }
1019        
1020        
1021        /**
1022         * Returns true if the current day is <em>Yom Kippur Katan</em>. Returns false for <em>Erev Rosh Hashana</em>,
1023         * <em>Erev Rosh Chodesh Cheshvan</em>, <em>Teves</em> and <em>Iyyar</em>. If <em>Erev Rosh Chodesh</em> occurs
1024         * on a Friday or <em>Shabbos</em>, <em>Yom Kippur Katan</em> is moved back to Thursday.
1025         * 
1026         * @return true if the current day is <em>Erev Rosh Chodesh</em>. Returns false for <em>Erev Rosh Hashana</em>.
1027         * @see #isRoshChodesh()
1028         */
1029        public boolean isYomKippurKatan() {
1030                int dayOfWeek = getDayOfWeek();
1031                int month = getJewishMonth();
1032                int day = getJewishDayOfMonth();
1033                if(month == JewishDate.ELUL || month == JewishDate.TISHREI || month == JewishDate.KISLEV || month == JewishDate.NISSAN) {
1034                        return false;
1035                }
1036
1037                if(day == 29 && dayOfWeek != Calendar.FRIDAY && dayOfWeek != Calendar.SATURDAY) {
1038                        return true;
1039                }
1040                
1041                if((day == 27 || day == 28) && dayOfWeek == Calendar.THURSDAY ) {
1042                        return true;
1043                }
1044                return false;
1045        }
1046        
1047        /**
1048         * The Monday, Thursday and Monday after the first <em>Shabbos</em> after {@link #isRoshChodesh() <em>Rosh Chodesh</em>}
1049         * {@link JewishDate#CHESHVAN <em>Cheshvan</em>} and {@link JewishDate#IYAR <em>Iyar</em>} are <a href=
1050         * "https://outorah.org/p/41334/"> <em>BeHaB</em></a> days. If the last Monday of Iyar's BeHaB coincides with {@link
1051         * #PESACH_SHENI <em>Pesach Sheni</em>}, the method currently considers it both <em>Pesach Sheni</em> and <em>BeHaB</em>.
1052         * As seen in an Ohr Sameach  article on the subject <a href="https://ohr.edu/this_week/insights_into_halacha/9340">The
1053         * unknown Days: BeHaB Vs. Pesach Sheini?</a> there are some customs that delay the day to various points in the future.
1054         * @return true if the day is <em>BeHaB</em>.
1055         */
1056        public boolean isBeHaB() {
1057                int dayOfWeek = getDayOfWeek();
1058                int month = getJewishMonth();
1059                int day = getJewishDayOfMonth();
1060                
1061                if (month == JewishDate.CHESHVAN || month == JewishDate.IYAR) {
1062                        if((dayOfWeek == Calendar.MONDAY && day > 4 && day < 18)
1063                                        || (dayOfWeek == Calendar.THURSDAY && day > 7 && day < 14)) {
1064                                return true;
1065                        }
1066                }
1067                return false;
1068        }
1069
1070        /**
1071         * Return true if the day is a Taanis (fast day). Return true for <em>17 of Tammuz</em>, <em>Tisha B'Av</em>,
1072         * <em>Yom Kippur</em>, <em>Fast of Gedalyah</em>, <em>10 of Teves</em> and the <em>Fast of Esther</em>.
1073         * 
1074         * @return true if today is a fast day
1075         */
1076        public boolean isTaanis() {
1077                int holidayIndex = getYomTovIndex();
1078                return holidayIndex == SEVENTEEN_OF_TAMMUZ || holidayIndex == TISHA_BEAV || holidayIndex == YOM_KIPPUR
1079                                || holidayIndex == FAST_OF_GEDALYAH || holidayIndex == TENTH_OF_TEVES || holidayIndex == FAST_OF_ESTHER;
1080        }
1081        
1082        /**
1083         * Return true if the day is <em>Taanis Bechoros</em> (on <em>Erev Pesach</em>). It will return true for the 14th
1084         * of <em>Nissan</em> if it is not on <em>Shabbos</em>, or if the 12th of <em>Nissan</em> occurs on a Thursday.
1085         * 
1086         * @return true if today is <em>Taanis Bechoros</em>.
1087         */
1088        public boolean isTaanisBechoros() {
1089            final int day = getJewishDayOfMonth();
1090            final int dayOfWeek = getDayOfWeek();
1091            // on 14 Nissan unless that is Shabbos where the fast is moved back to Thursday
1092            return getJewishMonth() == NISSAN && ((day == 14 && dayOfWeek != Calendar.SATURDAY) ||
1093                        (day == 12 && dayOfWeek == Calendar.THURSDAY ));
1094        }
1095
1096        /**
1097         * Returns the day of <em>Chanukah</em> or -1 if it is not <em>Chanukah</em>.
1098         * 
1099         * @return the day of <em>Chanukah</em> or -1 if it is not <em>Chanukah</em>.
1100         * @see #isChanukah()
1101         */
1102        public int getDayOfChanukah() {
1103                final int day = getJewishDayOfMonth();
1104                if (isChanukah()) {
1105                        if (getJewishMonth() == KISLEV) {
1106                                return day - 24;
1107                        } else { // teves
1108                                return isKislevShort() ? day + 5 : day + 6;
1109                        }
1110                } else {
1111                        return -1;
1112                }
1113        }
1114
1115        /**
1116         * Returns true if the current day is one of the 8 days of <em>Chanukah</em>.
1117         * 
1118         * @return if the current day is one of the 8 days of <em>Chanukah</em>.
1119         * 
1120         * @see #getDayOfChanukah()
1121         */
1122        public boolean isChanukah() {
1123                return getYomTovIndex() == CHANUKAH;
1124        }
1125        
1126        /**
1127         * Returns if the day is Purim (<a href="https://en.wikipedia.org/wiki/Purim#Shushan_Purim">Shushan Purim</a>
1128         * in a mukaf choma and regular Purim in a non-mukaf choma). 
1129         * @return if the day is Purim (Shushan Purim in a mukaf choma and regular Purin in a non-mukaf choma)
1130         * 
1131         * @see #getIsMukafChoma()
1132         * @see #setIsMukafChoma(boolean)
1133         */
1134        public boolean isPurim() {
1135                if(isMukafChoma) {
1136                        return getYomTovIndex() == SHUSHAN_PURIM;
1137                } else {
1138                        return getYomTovIndex() == PURIM;
1139                }
1140        }
1141
1142        /**
1143         * Returns if the day is Rosh Chodesh. Rosh Hashana will return false
1144         * 
1145         * @return true if it is Rosh Chodesh. Rosh Hashana will return false
1146         */
1147        public boolean isRoshChodesh() {
1148                // Rosh Hashana is not rosh chodesh. Elul never has 30 days
1149                return (getJewishDayOfMonth() == 1 && getJewishMonth() != TISHREI) || getJewishDayOfMonth() == 30;
1150        }
1151
1152        /**
1153         * Returns if the day is <em>Shabbos</em> and Sunday is <em>Rosh Chodesh</em>.
1154         *
1155         * @return true if it is <em>Shabbos</em> and Sunday is <em>Rosh Chodesh</em>.
1156         * @todo There is more to tweak in this method (it does not cover all cases and opinions), and it may be removed.
1157         */
1158        public boolean isMacharChodesh() {
1159                return (getDayOfWeek() == Calendar.SATURDAY && (getJewishDayOfMonth() == 30 || getJewishDayOfMonth() == 29));
1160        }
1161
1162        /**
1163         * Returns if the day is <em>Shabbos Mevorchim</em>.
1164         *
1165         * @return true if it is <em>Shabbos Mevorchim</em>.
1166         */
1167        public boolean isShabbosMevorchim() {
1168                return (getDayOfWeek() == Calendar.SATURDAY && getJewishDayOfMonth() >= 23 && getJewishDayOfMonth() <= 29 && getJewishMonth() != ELUL);
1169        }
1170
1171        /**
1172         * Returns the int value of the <em>Omer</em> day or -1 if the day is not in the <em>Omer</em>.
1173         * 
1174         * @return The <em>Omer</em> count as an int or -1 if it is not a day of the <em>Omer</em>.
1175         */
1176        public int getDayOfOmer() {
1177                int omer = -1; // not a day of the Omer
1178                int month = getJewishMonth();
1179                int day = getJewishDayOfMonth();
1180
1181                // if Nissan and second day of Pesach and on
1182                if (month == NISSAN && day >= 16) {
1183                        omer = day - 15;
1184                        // if Iyar
1185                } else if (month == IYAR) {
1186                        omer = day + 15;
1187                        // if Sivan and before Shavuos
1188                } else if (month == SIVAN && day < 6) {
1189                        omer = day + 44;
1190                }
1191                return omer;
1192        }
1193        
1194        /**
1195         * Returns if the day is Tisha Be'Av (the 9th of Av).
1196         * @return if the day is Tisha Be'Av (the 9th of Av).
1197         */
1198        public boolean isTishaBav() {
1199            int holidayIndex = getYomTovIndex();
1200            return holidayIndex == TISHA_BEAV;
1201        }
1202
1203        /**
1204         * Returns the <em>molad</em> in Standard Time in Yerushalayim as a Date. The traditional calculation uses local time.
1205         * This method subtracts 20.94 minutes (20 minutes and 56.496 seconds) from the local time (of <em>Har Habayis</em>
1206         * with a longitude of 35.2354&deg; is 5.2354&deg; away from the %15 timezone longitude) to get to standard time. This
1207         * method intentionally uses standard time and not daylight savings time. Java will implicitly format the time to the
1208         * default (or set) Timezone.
1209         * 
1210         * @return the Date representing the moment of the <em>molad</em> in Yerushalayim standard time (GMT + 2)
1211         */
1212        public Date getMoladAsDate() {
1213                JewishDate molad = getMolad();
1214                String locationName = "Jerusalem, Israel";
1215
1216                double latitude = 31.778; // Har Habayis latitude
1217                double longitude = 35.2354; // Har Habayis longitude
1218
1219                // The raw molad Date (point in time) must be generated using standard time. Using "Asia/Jerusalem" timezone will result in the time
1220                // being incorrectly off by an hour in the summer due to DST. Proper adjustment for the actual time in DST will be done by the date
1221                // formatter class used to display the Date.
1222                TimeZone yerushalayimStandardTZ = TimeZone.getTimeZone("GMT+2");
1223                GeoLocation geo = new GeoLocation(locationName, latitude, longitude, yerushalayimStandardTZ);
1224                Calendar cal = Calendar.getInstance(geo.getTimeZone());
1225                cal.clear();
1226                double moladSeconds = molad.getMoladChalakim() * 10 / (double) 3;
1227                cal.set(molad.getGregorianYear(), molad.getGregorianMonth(), molad.getGregorianDayOfMonth(),
1228                                molad.getMoladHours(), molad.getMoladMinutes(), (int) moladSeconds);
1229                cal.set(Calendar.MILLISECOND, (int) (1000 * (moladSeconds - (int) moladSeconds)));
1230                // subtract local time difference of 20.94 minutes (20 minutes and 56.496 seconds) to get to Standard time
1231                cal.add(Calendar.MILLISECOND, -1 * (int) geo.getLocalMeanTimeOffset());
1232                return cal.getTime();
1233        }
1234
1235        /**
1236         * Returns the earliest time of <em>Kiddush Levana</em> calculated as 3 days after the molad. This method returns the time
1237         * even if it is during the day when <em>Kiddush Levana</em> can't be said. Callers of this method should consider
1238         * displaying the next <em>tzais</em> if the <em>zman</em> is between <em>alos</em> and <em>tzais</em>.
1239         * 
1240         * @return the Date representing the moment 3 days after the molad.
1241         * 
1242         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getTchilasZmanKidushLevana3Days()
1243         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getTchilasZmanKidushLevana3Days(Date, Date)
1244         */
1245        public Date getTchilasZmanKidushLevana3Days() {
1246                Date molad = getMoladAsDate();
1247                Calendar cal = Calendar.getInstance();
1248                cal.setTime(molad);
1249                cal.add(Calendar.HOUR, 72); // 3 days after the molad
1250                return cal.getTime();
1251        }
1252
1253        /**
1254         * Returns the earliest time of <em>Kiddush Levana</em> calculated as 7 days after the <em>molad</em> as mentioned
1255         * by the <a href="http://en.wikipedia.org/wiki/Yosef_Karo">Mechaber</a>. See the <a
1256         * href="http://en.wikipedia.org/wiki/Yoel_Sirkis">Bach's</a> opinion on this time. This method returns the time
1257         * even if it is during the day when <em>Kiddush Levana</em> can't be said. Callers of this method should consider
1258         * displaying the next <em>tzais</em> if the <em>zman</em> is between <em>alos</em> and <em>tzais</em>.
1259         * 
1260         * @return the Date representing the moment 7 days after the molad.
1261         * 
1262         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getTchilasZmanKidushLevana7Days()
1263         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getTchilasZmanKidushLevana7Days(Date, Date)
1264         */
1265        public Date getTchilasZmanKidushLevana7Days() {
1266                Date molad = getMoladAsDate();
1267                Calendar cal = Calendar.getInstance();
1268                cal.setTime(molad);
1269                cal.add(Calendar.HOUR, 168); // 7 days after the molad
1270                return cal.getTime();
1271        }
1272
1273        /**
1274         * Returns the latest time of Kiddush Levana according to the <a
1275         * href="http://en.wikipedia.org/wiki/Yaakov_ben_Moshe_Levi_Moelin">Maharil's</a> opinion that it is calculated as
1276         * halfway between <em>molad</em> and <em>molad</em>. This adds half the 29 days, 12 hours and 793 <em>chalakim</em>
1277         * time between <em>molad</em> and <em>molad</em> (14 days, 18 hours, 22 minutes and 666 milliseconds) to the month's
1278         * <em>molad</em>. This method returns the time even if it is during the day when <em>Kiddush Levana</em> can't be
1279         * recited. Callers of this method should consider displaying <em>alos</em> before this time if the <em>zman</em> is
1280         * between <em>alos</em> and <em>tzais</em>.
1281         * 
1282         * @return the Date representing the moment halfway between <em>molad</em> and <em>molad</em>.
1283         * 
1284         * @see #getSofZmanKidushLevana15Days()
1285         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getSofZmanKidushLevanaBetweenMoldos()
1286         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getSofZmanKidushLevanaBetweenMoldos(Date, Date)
1287         */
1288        public Date getSofZmanKidushLevanaBetweenMoldos() {
1289                Date molad = getMoladAsDate();
1290                Calendar cal = Calendar.getInstance();
1291                cal.setTime(molad);
1292                // add half the time between molad and molad (half of 29 days, 12 hours and 793 chalakim (44 minutes, 3.3
1293                // seconds), or 14 days, 18 hours, 22 minutes and 666 milliseconds). Add it as hours, not days, to avoid
1294                // DST/ST crossover issues.
1295                cal.add(Calendar.HOUR, (24 * 14) + 18);
1296                cal.add(Calendar.MINUTE, 22);
1297                cal.add(Calendar.SECOND, 1);
1298                cal.add(Calendar.MILLISECOND, 666);
1299                return cal.getTime();
1300        }
1301
1302        /**
1303         * Returns the latest time of <em>Kiddush Levana</em> calculated as 15 days after the <em>molad.</em> This is the
1304         * opinion brought down in the Shulchan Aruch (Orach Chaim 426). It should be noted that some opinions hold that
1305         * the <a href="http://en.wikipedia.org/wiki/Moses_Isserles">Rema</a> who brings down the the <a
1306         * href="http://en.wikipedia.org/wiki/Yaakov_ben_Moshe_Levi_Moelin">Maharil's</a> opinion of calculating it as
1307         * {@link #getSofZmanKidushLevanaBetweenMoldos() half way between <em>molad</em> and <em>molad</em>} is of the
1308         * opinion of the Mechaber as well. Also see the Aruch Hashulchan. For additional details on the subject, See Rabbi
1309         * Dovid Heber's very detailed writeup in Siman Daled (chapter 4) of <a
1310         * href="http://www.worldcat.org/oclc/461326125">Shaarei Zmanim</a>. This method returns the time even if it is during
1311         * the day when <em>Kiddush Levana</em> can't be said. Callers of this method should consider displaying <em>alos</em>
1312         * before this time if the <em>zman</em> is between <em>alos</em> and <em>tzais</em>.
1313         * 
1314         * @return the Date representing the moment 15 days after the <em>molad</em>.
1315         * @see #getSofZmanKidushLevanaBetweenMoldos()
1316         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getSofZmanKidushLevana15Days()
1317         * @see com.kosherjava.zmanim.ComplexZmanimCalendar#getSofZmanKidushLevana15Days(Date, Date)
1318         */
1319        public Date getSofZmanKidushLevana15Days() {
1320                Date molad = getMoladAsDate();
1321                Calendar cal = Calendar.getInstance();
1322                cal.setTime(molad);
1323                cal.add(Calendar.HOUR, 24 * 15); //15 days after the molad. Add it as hours, not days, to avoid DST/ST crossover issues.
1324                return cal.getTime();
1325        }
1326
1327        /**
1328         * Returns the <em>Daf Yomi (Bavli)</em> for the date that the calendar is set to. See the
1329         * {@link HebrewDateFormatter#formatDafYomiBavli(Daf)} for the ability to format the <em>daf</em> in
1330         * Hebrew or transliterated <em>masechta</em> names.
1331         * 
1332         * @return the daf as a {@link Daf}
1333         */
1334        public Daf getDafYomiBavli() {
1335                return YomiCalculator.getDafYomiBavli(this);
1336        }
1337        /**
1338         * Returns the <em>Daf Yomi (Yerushalmi)</em> for the date that the calendar is set to. See the
1339         * {@link HebrewDateFormatter#formatDafYomiYerushalmi(Daf)} for the ability to format the <em>daf</em>
1340         * in Hebrew or transliterated <em>masechta</em> names.
1341         *
1342         * @return the daf as a {@link Daf}
1343         */
1344        public Daf getDafYomiYerushalmi() {
1345                return YerushalmiYomiCalculator.getDafYomiYerushalmi(this);
1346        }
1347        
1348        /**
1349         * Returns the elapsed days since <em>Tekufas Tishrei</em>. This uses <em>Tekufas Shmuel</em> (identical to the <a href=
1350         * "https://en.wikipedia.org/wiki/Julian_year_(astronomy)">Julian Year</a> with a solar year length of 365.25 days).
1351         * The notation used below is D = days, H = hours and C = chalakim. <em><a href="https://en.wikipedia.org/wiki/Molad"
1352         * >Molad</a> BaHaRad</em> was 2D,5H,204C or 5H,204C from the start of <em>Rosh Hashana</em> year 1. For <em>molad
1353         * Nissan</em> add 177D, 4H and 438C (6 * 29D, 12H and 793C), or 177D,9H,642C after <em>Rosh Hashana</em> year 1.
1354         * <em>Tekufas Nissan</em> was 7D, 9H and 642C before <em>molad Nissan</em> according to the Rambam, or 170D, 0H and
1355         * 0C after <em>Rosh Hashana</em> year 1. <em>Tekufas Tishrei</em> was 182D and 3H (365.25 / 2) before <em>tekufas
1356         * Nissan</em>, or 12D and 15H before <em>Rosh Hashana</em> of year 1. Outside of Israel we start reciting <em>Tal
1357         * Umatar</em> in <em>Birkas Hashanim</em> from 60 days after <em>tekufas Tishrei</em>. The 60 days include the day of
1358         * the <em>tekufah</em> and the day we start reciting <em>Tal Umatar</em>. 60 days from the tekufah == 47D and 9H
1359         * from <em>Rosh Hashana</em> year 1.
1360         * 
1361         * @return the number of elapsed days since <em>tekufas Tishrei</em>.
1362         * 
1363         * @see #isVeseinTalUmatarStartDate()
1364         * @see #isVeseinTalUmatarStartingTonight()
1365         * @see #isVeseinTalUmatarRecited()
1366         */
1367        public int getTekufasTishreiElapsedDays() {
1368                // Days since Rosh Hashana year 1. Add 1/2 day as the first tekufas tishrei was 9 hours into the day. This allows all
1369                // 4 years of the secular leap year cycle to share 47 days. Truncate 47D and 9H to 47D for simplicity.
1370                double days = getJewishCalendarElapsedDays(getJewishYear()) + (getDaysSinceStartOfJewishYear()-1) + 0.5;
1371                // days of completed solar years
1372                double solar = (getJewishYear() - 1) * 365.25;
1373                return (int) Math.floor(days - solar);
1374        }
1375
1376        /**
1377         * Returns if it is the Jewish day (starting the evening before) to start reciting <em>Vesein Tal Umatar
1378         * Livracha</em> (<em>Sheailas Geshamim</em>). In Israel this is the 7th day of <em>Marcheshvan</em>. Outside
1379         * Israel recitation starts on the evening of December 4th (or 5th if it is the year before a civil leap year)
1380         * in the 21st century and shifts a day forward every century not evenly divisible by 400. This method will
1381         * return true if <em>vesein tal umatar</em> on the current Jewish date that starts on the previous night, so
1382         * Dec 5/6 will be returned by this method in the 21st century. <em>vesein tal umatar</em> is not recited on
1383         * <em>Shabbos</em> and the start date will be delayed a day when the start day is on a <em>Shabbos</em> (this
1384         * can only occur out of Israel).
1385         * 
1386         * @deprecated Use {@link TefilaRules#isVeseinTalUmatarStartDate(JewishCalendar)} instead. This method will be
1387         *         removed in the v3.0 release.
1388         * 
1389         * @return true if it is the first Jewish day (starting the prior evening of reciting <em>Vesein Tal Umatar
1390         * Livracha</em> (<em>Sheailas Geshamim</em>)).
1391         * 
1392         * @see #isVeseinTalUmatarStartingTonight()
1393         * @see #isVeseinTalUmatarRecited()
1394         */
1395        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1396        public boolean isVeseinTalUmatarStartDate() {
1397                if (inIsrael) {
1398                         // The 7th Cheshvan can't occur on Shabbos, so always return true for 7 Cheshvan
1399                        if (getJewishMonth() == CHESHVAN && getJewishDayOfMonth() == 7) {
1400                                return true;
1401                        }
1402                } else {
1403                        if (getDayOfWeek() == Calendar.SATURDAY) { //Not recited on Friday night
1404                                return false;
1405                        }
1406                        if (getDayOfWeek() == Calendar.SUNDAY) { // When starting on Sunday, it can be the start date or delayed from Shabbos
1407                                return getTekufasTishreiElapsedDays() == 48 || getTekufasTishreiElapsedDays() == 47;
1408                        } else {
1409                                return getTekufasTishreiElapsedDays() == 47;
1410                        }
1411                }
1412                return false; // keep the compiler happy
1413        }
1414        
1415        /**
1416         * Returns true if tonight is the first night to start reciting <em>Vesein Tal Umatar Livracha</em> (
1417         * <em>Sheailas Geshamim</em>). In Israel this is the 7th day of <em>Marcheshvan</em> (so the 6th will return
1418         * true). Outside Israel recitation starts on the evening of December 4th (or 5th if it is the year before a
1419         * civil leap year) in the 21st century and shifts a day forward every century not evenly divisible by 400.
1420         * <em>Vesein tal umatar</em> is not recited on <em>Shabbos</em> and the start date will be delayed a day when
1421         * the start day is on a <em>Shabbos</em> (this can only occur out of Israel).
1422         * 
1423         * @deprecated Use {@link TefilaRules#isVeseinTalUmatarStartingTonight(JewishCalendar)} instead. This method
1424         *         will be removed in the v3.0 release.
1425         * 
1426         * @return true if it is the first Jewish day (starting the prior evening of reciting <em>Vesein Tal Umatar
1427         * Livracha</em> (<em>Sheailas Geshamim</em>)).
1428         * 
1429         * @see #isVeseinTalUmatarStartDate()
1430         * @see #isVeseinTalUmatarRecited()
1431         */
1432        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1433        public boolean isVeseinTalUmatarStartingTonight() {
1434                if (inIsrael) {
1435                        // The 7th Cheshvan can't occur on Shabbos, so always return true for 6 Cheshvan
1436                        if (getJewishMonth() == CHESHVAN && getJewishDayOfMonth() == 6) {
1437                                        return true;
1438                        }
1439                } else {
1440                        if (getDayOfWeek() == Calendar.FRIDAY) { //Not recited on Friday night
1441                                return false;
1442                        }
1443                        if (getDayOfWeek() == Calendar.SATURDAY) { // When starting on motzai Shabbos, it can be the start date or delayed from Friday night
1444                                return getTekufasTishreiElapsedDays() == 47 || getTekufasTishreiElapsedDays() == 46;
1445                        } else {
1446                                return getTekufasTishreiElapsedDays() == 46;
1447                        }
1448                }
1449                return false;
1450        }
1451
1452        /**
1453         * Returns if <em>Vesein Tal Umatar Livracha</em> (<em>Sheailas Geshamim</em>) is recited. This will return
1454         * true for the entire season, even on <em>Shabbos</em> when it is not recited.
1455         * 
1456         * @deprecated Use {@link TefilaRules#isVeseinTalUmatarRecited(JewishCalendar)} instead. This method will
1457         *         be removed in the v3.0 release.
1458         * 
1459         * @return true if <em>Vesein Tal Umatar Livracha</em> (<em>Sheailas Geshamim</em>) is recited.
1460         * 
1461         * @see #isVeseinTalUmatarStartDate()
1462         * @see #isVeseinTalUmatarStartingTonight()
1463         */
1464        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1465        public boolean isVeseinTalUmatarRecited() {
1466                if (getJewishMonth() == NISSAN && getJewishDayOfMonth() < 15) {
1467                        return true;
1468                }
1469                if (getJewishMonth() < CHESHVAN) {
1470                        return false;
1471                }
1472                if (inIsrael) {
1473                        return getJewishMonth() != CHESHVAN || getJewishDayOfMonth() >= 7;
1474                } else {
1475                        return getTekufasTishreiElapsedDays() >= 47;
1476                }
1477        }
1478        
1479        /**
1480         * Returns if <em>Vesein Beracha</em> is recited. It is recited from 15 <em>Nissan</em> to the point that {@link
1481         * #isVeseinTalUmatarRecited() <em>vesein tal umatar</em> is recited}.
1482         * 
1483         * @deprecated Use {@link TefilaRules#isVeseinBerachaRecited(JewishCalendar)} instead. This method will be
1484         *         removed in the v3.0 release.
1485         * 
1486         * @return true if <em>Vesein Beracha</em> is recited.
1487         * 
1488         * @see #isVeseinTalUmatarRecited()
1489         */
1490        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1491        public boolean isVeseinBerachaRecited() {
1492                return !isVeseinTalUmatarRecited();
1493        }
1494
1495        /**
1496         * Returns if the date is the start date for reciting <em>Mashiv Haruach Umorid Hageshem</em>. The date is 22 <em>Tishrei</em>.
1497         * 
1498         * @deprecated Use {@link TefilaRules#isMashivHaruachStartDate(JewishCalendar)} instead. This method will be
1499         *         removed in the v3.0 release.
1500         * 
1501         * @return true if the date is the start date for reciting <em>Mashiv Haruach Umorid Hageshem</em>.
1502         * 
1503         * @see #isMashivHaruachEndDate()
1504         * @see #isMashivHaruachRecited()
1505         */
1506        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1507        public boolean isMashivHaruachStartDate() {
1508                return getJewishMonth() == TISHREI && getJewishDayOfMonth() == 22;
1509        }
1510
1511        /**
1512         * Returns if the date is the end date for reciting <em>Mashiv Haruach Umorid Hageshem</em>. The date is 15 <em>Nissan</em>.
1513         * 
1514         * @deprecated Use {@link TefilaRules#isMashivHaruachEndDate(JewishCalendar)} instead. This method will be
1515         *         removed in the v3.0 release.
1516         * 
1517         * @return true if the date is the end date for reciting <em>Mashiv Haruach Umorid Hageshem</em>.
1518         * 
1519         * @see #isMashivHaruachStartDate()
1520         * @see #isMashivHaruachRecited()
1521         */
1522        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1523        public boolean isMashivHaruachEndDate() {
1524                return getJewishMonth() == NISSAN && getJewishDayOfMonth() == 15;
1525        }
1526
1527        /**
1528         * Returns if <em>Mashiv Haruach Umorid Hageshem</em> is recited. This period starts on 22 <em>Tishrei</em> and ends
1529         * on the 15th day of <em>Nissan</em>.
1530         * 
1531         * @deprecated Use {@link TefilaRules#isMashivHaruachRecited(JewishCalendar)} instead. This method will be
1532         *         removed in the v3.0 release.
1533         * 
1534         * @return true if <em>Mashiv Haruach Umorid Hageshem</em> is recited.
1535         * 
1536         * @see #isMashivHaruachStartDate()
1537         * @see #isMashivHaruachEndDate()
1538         */
1539        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1540        public boolean isMashivHaruachRecited() {
1541                JewishDate startDate = new JewishDate(getJewishYear(), TISHREI, 22);
1542                JewishDate endDate = new JewishDate(getJewishYear(), NISSAN, 15);
1543                return compareTo(startDate) > 0 && compareTo(endDate) < 0;
1544        }
1545
1546        /**
1547         * Returns if <em>Morid Hatal</em> (or the lack of reciting <em>Mashiv Haruach</em> following <em>nussach Ashkenaz</em>) is recited.
1548         * This period starts on 22 <em>Tishrei</em> and ends on the 15th day of
1549         * <em>Nissan</em>.
1550         * 
1551         * @deprecated Use {@link TefilaRules#isMoridHatalRecited(JewishCalendar)} instead. This method will be
1552         *         removed in the v3.0 release.
1553         * 
1554         * @return true if <em>Morid Hatal</em> (or the lack of reciting <em>Mashiv Haruach</em> following <em>nussach Ashkenaz</em>) is recited.
1555         */
1556        @Deprecated // (forRemoval=true) // add back once Java 9 is the minimum supported version
1557        public boolean isMoridHatalRecited() {
1558                return !isMashivHaruachRecited() || isMashivHaruachStartDate() || isMashivHaruachEndDate();
1559        }
1560        
1561        /**
1562         * Returns true if the current day is <em>Isru Chag</em>. The method returns true for the day following <em>Pesach</em>
1563         * <em>Shavuos</em> and <em>Succos</em>. It utilizes {@see #getInIsrael()} to return the proper date.
1564         * 
1565         * @return true if the current day is <em>Isru Chag</em>. The method returns true for the day following <em>Pesach</em>
1566         * <em>Shavuos</em> and <em>Succos</em>. It utilizes {@see #getInIsrael()} to return the proper date.
1567         */
1568        public boolean isIsruChag() {
1569                int holidayIndex = getYomTovIndex();
1570                return holidayIndex == ISRU_CHAG;
1571        }
1572
1573        /**
1574         * Indicates whether some other object is "equal to" this one.
1575         * @see Object#equals(Object)
1576         */
1577        public boolean equals(Object object) {
1578                if (this == object) {
1579                        return true;
1580                }
1581                if (!(object instanceof JewishCalendar)) {
1582                        return false;
1583                }
1584                JewishCalendar jewishCalendar = (JewishCalendar) object;
1585                return getAbsDate() == jewishCalendar.getAbsDate() && getInIsrael() == jewishCalendar.getInIsrael();
1586        }
1587
1588        /**
1589         * Overrides {@link Object#hashCode()}.
1590         * @see Object#hashCode()
1591         */
1592        public int hashCode() {
1593                int result = 17;
1594                result = 37 * result + getClass().hashCode(); // needed or this and subclasses will return identical hash
1595                result += 37 * result + getAbsDate() + (getInIsrael() ? 1 : 3);
1596                return result;
1597        }
1598}