001/*
002 * Zmanim Java API
003 * Copyright (C) 2019 - 2023 Eliyahu Hershfeld
004 * Copyright (C) 2019 - 2021 Y Paritcher
005 *
006 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
007 * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
008 * any later version.
009 *
010 * This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied
011 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
012 * details.
013 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
014 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA,
015 * or connect to: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
016 */
017package com.kosherjava.zmanim.hebrewcalendar;
018
019import java.util.Calendar;
020
021/**
022 * Tefila Rules is a utility class that covers the various <em>halachos</em> and <em>minhagim</em> regarding
023 * changes to daily <em>tefila</em> / prayers, based on the Jewish calendar. This is mostly useful for use in
024 * developing <em>siddur</em> type applications, but it is also valuable for <em>shul</em> calendars that set
025 * <em>tefila</em> times based on if <a href="https://en.wikipedia.org/wiki/Tachanun"><em>tachanun</em></a> is
026 * recited that day. There are many settings in this class to cover the vast majority of <em>minhagim</em>, but
027 * there are likely some not covered here. The source for many of the <em>chasidishe minhagim</em> can be found
028 * in the <a href="https://www.nli.org.il/he/books/NNL_ALEPH001141272/NLI">Minhag Yisrael Torah</a> on Orach
029 * Chaim 131.
030 * Dates used in specific communities such as specific <em>yahrzeits</em> or a holidays like Purim Mezhbizh
031 * (Medzhybizh) celebrated on 11 {@link JewishDate#TEVES <em>Teves</em>} or <a href=
032 * "https://en.wikipedia.org/wiki/Second_Purim#Purim_Saragossa_(18_Shevat)">Purim Saragossa</a> celebrated on
033 * the (17th or) 18th of {@link JewishDate#SHEVAT <em>Shevat</em>} are not (and likely will not be) supported by
034 * this class.
035 * <p>Sample code:
036 * <pre style="background: #FEF0C9; display: inline-block;">
037 * TefilaRules tr = new TefilaRules();
038 * JewishCalendar jewishCalendar = new JewishCalendar();
039 * HebrewDateFormatter hdf = new HebrewDateFormatter();
040 * jewishCalendar.setJewishDate(5783, JewishDate.TISHREI, 1); // Rosh Hashana
041 * System.out.println(hdf.format(jewishCalendar) + ": " + tr.isTachanunRecitedShacharis(jd));
042 * jewishCalendar.setJewishDate(5783, JewishDate.ADAR, 17);
043 * System.out.println(hdf.format(jewishCalendar) + ": " + tr.isTachanunRecitedShacharis(jewishCalendar));
044 * tr.setTachanunRecitedWeekOfPurim(false);
045 * System.out.println(hdf.format(jewishCalendar) + ": " + tr.isTachanunRecitedShacharis(jewishCalendar));</pre>
046 * 
047 * @author &copy; Y. Paritcher 2019 - 2021
048 * @author &copy; Eliyahu Hershfeld 2019 - 2023
049 * 
050 * @todo The following items may be added at a future date.
051 * <ol>
052 * <li><em>Lamnatzaiach</em></li>
053 * <li><em>Mizmor Lesoda</em></li>
054 * <li><em>Behab</em></li>
055 * <li><em>Selichos</em></li>
056 * <li>...</li>
057 * </ol>
058 */
059public class TefilaRules {
060        /**
061         * The default value is <code>true</code>.
062         * @see #isTachanunRecitedEndOfTishrei()
063         * @see #setTachanunRecitedEndOfTishrei(boolean)
064         */
065        private boolean tachanunRecitedEndOfTishrei = true;
066        
067        /**
068         * The default value is <code>false</code>.
069         * @see #isTachanunRecitedWeekAfterShavuos()
070         * @see #setTachanunRecitedWeekAfterShavuos(boolean)
071         */
072        private boolean tachanunRecitedWeekAfterShavuos = false;
073        
074        /**
075         * The default value is <code>true</code>.
076         * @see #isTachanunRecited13SivanOutOfIsrael()
077         * @see #setTachanunRecited13SivanOutOfIsrael(boolean)
078         */
079        private boolean tachanunRecited13SivanOutOfIsrael = true;
080        
081        /**
082         * The default value is <code>false</code>.
083         * @see #isTachanunRecitedPesachSheni()
084         * @see #setTachanunRecitedPesachSheni(boolean)
085         */
086        private boolean tachanunRecitedPesachSheni = false;
087        
088        /**
089         * The default value is <code>true</code>.
090         * @see #isTachanunRecited15IyarOutOfIsrael()
091         * @see #setTachanunRecited15IyarOutOfIsrael(boolean)
092         */
093        private boolean tachanunRecited15IyarOutOfIsrael = true;
094        
095        /**
096         * The default value is <code>false</code>.
097         * @see #isTachanunRecitedMinchaErevLagBaomer()
098         * @see #setTachanunRecitedMinchaErevLagBaomer(boolean)
099         */
100        private boolean tachanunRecitedMinchaErevLagBaomer = false;
101        
102        /**
103         * The default value is <code>true</code>.
104         * @see #isTachanunRecitedShivasYemeiHamiluim()
105         * @see #setTachanunRecitedShivasYemeiHamiluim(boolean)
106         */
107        private boolean tachanunRecitedShivasYemeiHamiluim = true;
108        
109        /**
110         * The default value is <code>true</code>.
111         * @see #isTachanunRecitedWeekOfHod()
112         * @see #setTachanunRecitedWeekOfHod(boolean)
113         */
114        private boolean tachanunRecitedWeekOfHod = true;
115        
116        /**
117         * The default value is <code>true</code>.
118         * @see #isTachanunRecitedWeekOfPurim()
119         * @see #setTachanunRecitedWeekOfPurim(boolean)
120         */
121        private boolean tachanunRecitedWeekOfPurim = true;
122        
123        /**
124         * The default value is <code>true</code>.
125         * @see #isTachanunRecitedFridays()
126         * @see #setTachanunRecitedFridays(boolean)
127         */
128        private boolean tachanunRecitedFridays = true;
129        
130        /**
131         * The default value is <code>true</code>.
132         * @see #isTachanunRecitedSundays()
133         * @see #setTachanunRecitedSundays(boolean)
134         */
135        private boolean tachanunRecitedSundays = true;
136        
137        /**
138         * The default value is <code>true</code>.
139         * @see #isTachanunRecitedMinchaAllYear()
140         * @see #setTachanunRecitedMinchaAllYear(boolean)
141         */
142        private boolean tachanunRecitedMinchaAllYear = true;
143        
144        /**
145         * Returns if <em>tachanun</em> is recited during <em>shacharis</em> on the day in question. See the many
146         * <em>minhag</em> based settings that are available in this class.
147         * 
148         * @param jewishCalendar the Jewish calendar day.
149         * @return if <em>tachanun</em> is recited during <em>shacharis</em>.
150         * @see #isTachanunRecitedMincha(JewishCalendar)
151         */
152        public boolean isTachanunRecitedShacharis(JewishCalendar jewishCalendar) {
153                int holidayIndex = jewishCalendar.getYomTovIndex();
154                int day = jewishCalendar.getJewishDayOfMonth();
155                int month = jewishCalendar.getJewishMonth();
156
157                if (jewishCalendar.getDayOfWeek() == Calendar.SATURDAY
158                                || (!tachanunRecitedSundays && jewishCalendar.getDayOfWeek() == Calendar.SUNDAY)
159                                || (!tachanunRecitedFridays && jewishCalendar.getDayOfWeek() == Calendar.FRIDAY)
160                                || month == JewishDate.NISSAN
161                                || (month == JewishDate.TISHREI && ((!tachanunRecitedEndOfTishrei && day > 8)
162                                || (tachanunRecitedEndOfTishrei && (day > 8 && day < 22))))
163                                || (month == JewishDate.SIVAN && (tachanunRecitedWeekAfterShavuos && day < 7
164                                                || !tachanunRecitedWeekAfterShavuos && day < (!jewishCalendar.getInIsrael()
165                                                                && !tachanunRecited13SivanOutOfIsrael ? 14: 13)))
166                                || (jewishCalendar.isYomTov() && (! jewishCalendar.isTaanis()
167                                                || (!tachanunRecitedPesachSheni && holidayIndex == JewishCalendar.PESACH_SHENI))) // Erev YT is included in isYomTov()
168                                || (!jewishCalendar.getInIsrael() && !tachanunRecitedPesachSheni && !tachanunRecited15IyarOutOfIsrael
169                                                && jewishCalendar.getJewishMonth() == JewishDate.IYAR && day == 15)
170                                || holidayIndex == JewishCalendar.TISHA_BEAV || jewishCalendar.isIsruChag()
171                                || jewishCalendar.isRoshChodesh()
172                                || (!tachanunRecitedShivasYemeiHamiluim &&
173                                                ((!jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR)
174                                                                || (jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR_II)) && day > 22)
175                                || (!tachanunRecitedWeekOfPurim &&
176                                                ((!jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR)
177                                                                || (jewishCalendar.isJewishLeapYear() && month == JewishDate.ADAR_II)) && day > 10 && day < 18)
178                                || (jewishCalendar.isUseModernHolidays()
179                                                && (holidayIndex == JewishCalendar.YOM_HAATZMAUT || holidayIndex == JewishCalendar.YOM_YERUSHALAYIM))
180                                || (!tachanunRecitedWeekOfHod && month == JewishDate.IYAR && day > 13 && day < 21)) {
181                        return false;
182                }
183                return true;
184        }
185
186        /**
187         * Returns if <em>tachanun</em> is recited during <em>mincha</em> on the day in question.
188         * 
189         * @param jewishCalendar the Jewish calendar day.
190         * @return if <em>tachanun</em> is recited during <em>mincha</em>.
191         * @see #isTachanunRecitedShacharis(JewishCalendar)
192         */
193        public boolean isTachanunRecitedMincha(JewishCalendar jewishCalendar) {
194                JewishCalendar tomorrow = new JewishCalendar();
195                tomorrow = (JewishCalendar) jewishCalendar.clone();
196                tomorrow.forward(Calendar.DATE, 1);
197                
198                if (!tachanunRecitedMinchaAllYear
199                                        || jewishCalendar.getDayOfWeek() == Calendar.FRIDAY
200                                        || ! isTachanunRecitedShacharis(jewishCalendar) 
201                                        || (! isTachanunRecitedShacharis(tomorrow) && 
202                                                        !(tomorrow.getYomTovIndex() == JewishCalendar.EREV_ROSH_HASHANA) &&
203                                                        !(tomorrow.getYomTovIndex() == JewishCalendar.EREV_YOM_KIPPUR) &&
204                                                        !(tomorrow.getYomTovIndex() == JewishCalendar.PESACH_SHENI))
205                                        || ! tachanunRecitedMinchaErevLagBaomer && tomorrow.getYomTovIndex() == JewishCalendar.LAG_BAOMER) {
206                        return false;
207                }
208                return true;
209        }
210        
211        /**
212         * Returns if it is the Jewish day (starting the evening before) to start reciting <em>Vesein Tal Umatar Livracha</em>
213         * (<em>Sheailas Geshamim</em>). In Israel this is the 7th day of {@link JewishDate#CHESHVAN <em>Marcheshvan</em>}.
214         * Outside Israel recitation starts on the evening of December 4th (or 5th if it is the year before a civil leap year)
215         * in the 21st century and shifts a day forward every century not evenly divisible by 400. This method will return true
216         * if <em>vesein tal umatar</em> on the current Jewish date that starts on the previous night, so Dec 5/6 will be
217         * returned by this method in the 21st century. <em>vesein tal umatar</em> is not recited on <em>Shabbos</em> and the
218         * start date will be delayed a day when the start day is on a <em>Shabbos</em> (this can only occur out of Israel).
219         * 
220         * @param jewishCalendar the Jewish calendar day.
221         * 
222         * @return true if it is the first Jewish day (starting the prior evening of reciting <em>Vesein Tal Umatar Livracha</em>
223         *         (<em>Sheailas Geshamim</em>).
224         * 
225         * @see #isVeseinTalUmatarStartingTonight(JewishCalendar)
226         * @see #isVeseinTalUmatarRecited(JewishCalendar)
227         */
228        public boolean isVeseinTalUmatarStartDate(JewishCalendar jewishCalendar) {
229                if (jewishCalendar.getInIsrael()) {
230                         // The 7th Cheshvan can't occur on Shabbos, so always return true for 7 Cheshvan
231                        if (jewishCalendar.getJewishMonth() == JewishDate.CHESHVAN && jewishCalendar.getJewishDayOfMonth() == 7) {
232                                return true;
233                        }
234                } else {
235                        if (jewishCalendar.getDayOfWeek() == Calendar.SATURDAY) { //Not recited on Friday night
236                                return false;
237                        }
238                        if(jewishCalendar.getDayOfWeek() == Calendar.SUNDAY) { // When starting on Sunday, it can be the start date or delayed from Shabbos
239                                return jewishCalendar.getTekufasTishreiElapsedDays() == 48 || jewishCalendar.getTekufasTishreiElapsedDays() == 47;
240                        } else {
241                                return jewishCalendar.getTekufasTishreiElapsedDays() == 47;
242                        }
243                }
244                return false; // keep the compiler happy
245        }
246        
247        /**
248         * Returns if true if tonight is the first night to start reciting <em>Vesein Tal Umatar Livracha</em> (
249         * <em>Sheailas Geshamim</em>). In Israel this is the 7th day of {@link JewishDate#CHESHVAN
250         * <em>Marcheshvan</em>} (so the 6th will return true). Outside Israel recitation starts on the evening
251         * of December 4th (or 5th if it is the year before a civil leap year) in the 21st century and shifts a
252         * day forward every century not evenly divisible by 400. <em>Vesein tal umatar</em> is not recited on
253         * <em>Shabbos</em> and the start date will be delayed a day when the start day is on a <em>Shabbos</em>
254         * (this can only occur out of Israel).
255         * 
256         * @param jewishCalendar the Jewish calendar day.
257         * 
258         * @return true if it is the first Jewish day (starting the prior evening of reciting <em>Vesein Tal Umatar
259         *         Livracha</em> (<em>Sheailas Geshamim</em>).
260         * 
261         * @see #isVeseinTalUmatarStartDate(JewishCalendar)
262         * @see #isVeseinTalUmatarRecited(JewishCalendar)
263         */
264        public boolean isVeseinTalUmatarStartingTonight(JewishCalendar jewishCalendar) {
265                if (jewishCalendar.getInIsrael()) {
266                        // The 7th Cheshvan can't occur on Shabbos, so always return true for 6 Cheshvan
267                        if (jewishCalendar.getJewishMonth() == JewishDate.CHESHVAN && jewishCalendar.getJewishDayOfMonth() == 6) {
268                                        return true;
269                        }
270                } else {
271                        if (jewishCalendar.getDayOfWeek() == Calendar.FRIDAY) { //Not recited on Friday night
272                                return false;
273                        }
274                        if(jewishCalendar.getDayOfWeek() == Calendar.SATURDAY) { // When starting on motzai Shabbos, it can be the start date or delayed from Friday night
275                                return jewishCalendar.getTekufasTishreiElapsedDays() == 47 || jewishCalendar.getTekufasTishreiElapsedDays() == 46;
276                        } else {
277                                return jewishCalendar.getTekufasTishreiElapsedDays() == 46;
278                        }
279                }
280                return false;
281        }
282
283        /**
284         * Returns if <em>Vesein Tal Umatar Livracha</em> (<em>Sheailas Geshamim</em>) is recited. This will return
285         * true for the entire season, even on <em>Shabbos</em> when it is not recited.
286         * 
287         * @param jewishCalendar the Jewish calendar day.
288         * 
289         * @return true if <em>Vesein Tal Umatar Livracha</em> (<em>Sheailas Geshamim</em>) is recited.
290         * 
291         * @see #isVeseinTalUmatarStartDate(JewishCalendar)
292         * @see #isVeseinTalUmatarStartingTonight(JewishCalendar)
293         */
294        public boolean isVeseinTalUmatarRecited(JewishCalendar jewishCalendar) {
295                if (jewishCalendar.getJewishMonth() == JewishDate.NISSAN && jewishCalendar.getJewishDayOfMonth() < 15) {
296                        return true;
297                }
298                if (jewishCalendar.getJewishMonth() < JewishDate.CHESHVAN) {
299                        return false;
300                }
301                if (jewishCalendar.getInIsrael()) {
302                        return jewishCalendar.getJewishMonth() != JewishDate.CHESHVAN || jewishCalendar.getJewishDayOfMonth() >= 7;
303                } else {
304                        return jewishCalendar.getTekufasTishreiElapsedDays() >= 47;
305                }
306        }
307        
308        /**
309         * Returns if <em>Vesein Beracha</em> is recited. It is recited from 15 {@link JewishDate#NISSAN <em>Nissan</em>} to the
310         * point that {@link #isVeseinTalUmatarRecited(JewishCalendar) <em>vesein tal umatar</em> is recited}.
311         * 
312         * @param jewishCalendar the Jewish calendar day.
313         * @return true if <em>Vesein Beracha</em> is recited.
314         * @see #isVeseinTalUmatarRecited(JewishCalendar)
315         */
316        public boolean isVeseinBerachaRecited(JewishCalendar jewishCalendar) {
317                return ! isVeseinTalUmatarRecited(jewishCalendar);
318        }
319
320        /**
321         * Returns if the date is the start date for reciting <em>Mashiv Haruach Umorid Hageshem</em>. The date is 22
322         * {@link JewishDate#TISHREI <em>Tishrei</em>}.
323         * 
324         * @param jewishCalendar the Jewish calendar day.
325         * @return true if the date is the start date for reciting <em>Mashiv Haruach Umorid Hageshem</em>.
326         * @see #isMashivHaruachEndDate(JewishCalendar)
327         * @see #isMashivHaruachRecited(JewishCalendar)
328         */
329        public boolean isMashivHaruachStartDate(JewishCalendar jewishCalendar) {
330                return jewishCalendar.getJewishMonth() == JewishDate.TISHREI && jewishCalendar.getJewishDayOfMonth() == 22;
331        }
332
333        /**
334         * Returns if the date is the end date for reciting <em>Mashiv Haruach Umorid Hageshem</em>. The date is 15
335         * {@link JewishDate#NISSAN <em>Nissan</em>}.
336         * 
337         * @param jewishCalendar the Jewish calendar day.
338         * @return true if the date is the end date for reciting <em>Mashiv Haruach Umorid Hageshem</em>.
339         * @see #isMashivHaruachStartDate(JewishCalendar)
340         * @see #isMashivHaruachRecited(JewishCalendar)
341         */
342        public boolean isMashivHaruachEndDate(JewishCalendar jewishCalendar) {
343                return jewishCalendar.getJewishMonth() == JewishDate.NISSAN && jewishCalendar.getJewishDayOfMonth() == 15;
344        }
345
346        /**
347         * Returns if <em>Mashiv Haruach Umorid Hageshem</em> is recited. This period starts on 22 {@link
348         * JewishDate#TISHREI <em>Tishrei</em>} and ends on the 15th day of {@link JewishDate#NISSAN <em>Nissan</em>}.
349         * 
350         * @param jewishCalendar the Jewish calendar day.
351         * @return true if <em>Mashiv Haruach Umorid Hageshem</em> is recited.
352         * @see #isMashivHaruachStartDate(JewishCalendar)
353         * @see #isMashivHaruachEndDate(JewishCalendar)
354         */
355        public boolean isMashivHaruachRecited(JewishCalendar jewishCalendar) {
356                JewishDate startDate = new JewishDate(jewishCalendar.getJewishYear(), JewishDate.TISHREI, 22);
357                JewishDate endDate = new JewishDate(jewishCalendar.getJewishYear(), JewishDate.NISSAN, 15);
358                return jewishCalendar.compareTo(startDate) > 0 && jewishCalendar.compareTo(endDate) < 0;
359        }
360
361        /**
362         * Returns if <em>Morid Hatal</em> (or the lack of reciting <em>Mashiv Haruach</em> following <em>nussach Ashkenaz</em>) is
363         * recited. This period starts on the 15th day of {@link JewishDate#NISSAN <em>Nissan</em>} and ends on 22 {@link
364         * JewishDate#TISHREI <em>Tishrei</em>}.
365         * 
366         * @param jewishCalendar the Jewish calendar day.
367         * 
368         * @return true if <em>Morid Hatal</em> (or the lack of reciting <em>Mashiv Haruach</em> following <em>nussach Ashkenaz</em>) is recited.
369         */
370        public boolean isMoridHatalRecited(JewishCalendar jewishCalendar) {
371                return !isMashivHaruachRecited(jewishCalendar) || isMashivHaruachStartDate(jewishCalendar) || isMashivHaruachEndDate(jewishCalendar);
372        }
373        
374        /**
375         * Returns if <em>Hallel</em> is recited on the day in question. This will return true for both <em>Hallel shalem</em>
376         * and <em>Chatzi Hallel</em>. See {@link #isHallelShalemRecited(JewishCalendar)} to know if the complete <em>Hallel</em>
377         * is recited.
378         * 
379         * @param jewishCalendar the Jewish calendar day.
380         * @return if <em>Hallel</em> is recited.
381         * @see #isHallelShalemRecited(JewishCalendar)
382         */
383        public boolean isHallelRecited(JewishCalendar jewishCalendar) {
384                int day = jewishCalendar.getJewishDayOfMonth();
385                int month = jewishCalendar.getJewishMonth();
386                int holidayIndex = jewishCalendar.getYomTovIndex();
387                boolean inIsrael = jewishCalendar.getInIsrael();
388                
389                if(jewishCalendar.isRoshChodesh()) { //RH returns false for RC
390                        return true;
391                }
392                if(jewishCalendar.isChanukah()) {
393                        return true;
394                }
395                switch (month) {
396                        case JewishDate.NISSAN:
397                                if(day >= 15 && ((inIsrael && day <= 21) || (!inIsrael && day <= 22))){
398                                        return true;
399                                }
400                                break;
401                        case JewishDate.IYAR: // modern holidays
402                                if(jewishCalendar.isUseModernHolidays()  && (holidayIndex == JewishCalendar.YOM_HAATZMAUT
403                                                || holidayIndex == JewishCalendar.YOM_YERUSHALAYIM)){
404                                        return true;
405                                }
406                                break;
407                        case JewishDate.SIVAN:
408                                if (day == 6 || (!inIsrael && (day == 7))){
409                                        return true;
410                                }
411                                break;
412                        case JewishDate.TISHREI:
413                                if (day >= 15 && (day <= 22 || (!inIsrael && (day <= 23)))){
414                                        return true;
415                                }
416                }
417                return false;
418        }
419
420        /**
421         * Returns if <em>hallel shalem</em> is recited on the day in question. This will always return false if {@link
422         * #isHallelRecited(JewishCalendar)} returns false.
423         * 
424         * @param jewishCalendar the Jewish calendar day.
425         * @return if <em>hallel shalem</em> is recited.
426         * @see #isHallelRecited(JewishCalendar)
427         */
428        public boolean isHallelShalemRecited(JewishCalendar jewishCalendar) {
429                int day = jewishCalendar.getJewishDayOfMonth();
430                int month = jewishCalendar.getJewishMonth();
431                boolean inIsrael = jewishCalendar.getInIsrael();
432                if(isHallelRecited(jewishCalendar)) {
433                        if((jewishCalendar.isRoshChodesh() && ! jewishCalendar.isChanukah())
434                                        || (month == JewishDate.NISSAN && ((inIsrael && day > 15) || (!inIsrael && day > 16)))) {
435                                return false;
436                        } else {
437                                return true;
438                        }
439                } 
440                return false;
441        }
442        
443        /**
444         * Returns if <a href="https://en.wikipedia.org/wiki/Al_HaNissim"><em>Al HaNissim</em></a> is recited on the day in question.
445         * 
446         * @param jewishCalendar the Jewish calendar day.
447         * @return if <em>al hanissim</em> is recited.
448         * @see JewishCalendar#isChanukah()
449         * @see JewishCalendar#isPurim()
450         * @see JewishCalendar#getIsMukafChoma()
451         */
452        public boolean isAlHanissimRecited(JewishCalendar jewishCalendar) {
453            return jewishCalendar.isPurim() || jewishCalendar.isChanukah();
454        }
455        
456        /**
457         * Returns if <em>Yaaleh Veyavo</em> is recited on the day in question.
458         * 
459         * @param jewishCalendar the Jewish calendar day.
460         * @return if <em>Yaaleh Veyavo</em> is recited.
461         * @see JewishCalendar#isPesach()
462         * @see JewishCalendar#isShavuos()
463         * @see JewishCalendar#isRoshHashana()
464         * @see JewishCalendar#isYomKippur()
465         * @see JewishCalendar#isSuccos()
466         * @see JewishCalendar#isShminiAtzeres()
467         * @see JewishCalendar#isSimchasTorah()
468         * @see JewishCalendar#isRoshChodesh()
469         */
470        public boolean isYaalehVeyavoRecited(JewishCalendar jewishCalendar) {
471            return jewishCalendar.isPesach() || jewishCalendar.isShavuos() ||jewishCalendar.isRoshHashana() || jewishCalendar.isYomKippur()
472                        || jewishCalendar.isSuccos() || jewishCalendar.isShminiAtzeres() || jewishCalendar.isSimchasTorah()
473                        || jewishCalendar.isRoshChodesh();
474        }
475        
476        /**
477         * Is <em>tachanun</em> recited during the week of Purim, from the 11th through the 17th of {@link
478         * JewishDate#ADAR <em>Adar</em>} (on a non-leap year, or {@link JewishDate#ADAR_II <em>Adar II</em>} on a leap year). Some
479         * <em>chasidishe</em> communities do not recite <em>tachanun</em> during this period. See the <a href=
480         * "https://www.nli.org.il/he/books/NNL_ALEPH001141272/NLI">Minhag Yisrael Torah</a> 131 and <a href=
481         * "https://hebrewbooks.org/pdfpager.aspx?req=4692&st=&pgnum=70">Darkei Chaim Veshalom 191</a>who discuss the
482         * <em>minhag</em> not to recite <em>tachanun</em>. Also see the <a href=
483         * "https://hebrewbooks.org/pdfpager.aspx?req=8944&st=&pgnum=160">Mishmeres Shalom (Hadras Shalom)</a> who discusses the
484         * <em>minhag</em> of not reciting it on the 16th and 17th.
485         * @return If <em>tachanun</em> is set to be recited during the week of Purim from the 11th through the 17th of {@link
486         *         JewishDate#ADAR <em>Adar</em>} (on a non-leap year, or {@link JewishDate#ADAR_II <em>Adar II</em>} on a leap year).
487         * @see #setTachanunRecitedWeekOfPurim(boolean)
488         */
489        public boolean isTachanunRecitedWeekOfPurim() {
490                return tachanunRecitedWeekOfPurim;
491        }
492
493        /**
494         * Sets if <em>tachanun</em> should be recited during the week of Purim from the 11th through the 17th of {@link
495         * JewishDate#ADAR <em>Adar</em>} (on a non-leap year), or {@link JewishDate#ADAR_II <em>Adar II</em>} (on a leap year).
496         * @param tachanunRecitedWeekOfPurim Sets if <em>tachanun</em> is to recited during the week of Purim from the 11th
497         *         through the 17th of {@link JewishDate#ADAR <em>Adar</em>} (on a non-leap year), or {@link JewishDate#ADAR_II
498         *         <em>Adar II</em>} (on a leap year). Some <em>chasidishe</em> communities do not recite <em>tachanun</em>
499         *         during this period.
500         * @see #isTachanunRecitedWeekOfPurim()
501         */
502        public void setTachanunRecitedWeekOfPurim(boolean tachanunRecitedWeekOfPurim) {
503                this.tachanunRecitedWeekOfPurim = tachanunRecitedWeekOfPurim;
504        }
505
506        /**
507         * Is <em>tachanun</em> recited during the <em>sefira</em> week of <em>Hod</em> (14 - 20 {@link JewishDate#IYAR <em>Iyar</em>},
508         * or the 29th - 35th of the {@link JewishCalendar#getDayOfOmer() <em>Omer</em>}). Some <em>chasidishe</em> communities
509         * do not recite <em>tachanun</em> during this week. See Minhag Yisrael Torah 131:Iyar.
510         * @return If <em>tachanun</em> is set to be recited during the <em>sefira</em> week of <em>Hod</em> (14 - 20 {@link
511         *         JewishDate#IYAR <em>Iyar</em>}, or the 29th - 35th of the {@link JewishCalendar#getDayOfOmer() <em>Omer</em>}).
512         * @see #setTachanunRecitedWeekOfHod(boolean)
513         */
514        public boolean isTachanunRecitedWeekOfHod() {
515                return tachanunRecitedWeekOfHod;
516        }
517
518        /**
519         * Sets if <em>tachanun</em> should be recited during the <em>sefira</em> week of <em>Hod</em> (14 - 20 {@link JewishDate#IYAR
520         * <em>Iyar</em>}, or the 29th - 35th of the {@link JewishCalendar#getDayOfOmer() <em>Omer</em>}).
521         * @param tachanunRecitedWeekOfHod Sets if <em>tachanun</em> should be recited during the <em>sefira</em> week of
522         * <em>Hod</em>.
523         * @see #isTachanunRecitedWeekOfHod()
524         */
525        public void setTachanunRecitedWeekOfHod(boolean tachanunRecitedWeekOfHod) {
526                this.tachanunRecitedWeekOfHod = tachanunRecitedWeekOfHod;
527        }
528
529        /**
530         * Is <em>tachanun</em> recited at the end Of {@link JewishDate#TISHREI <em>Tishrei</em>}.The Magen Avraham 669:1 and the Pri
531         * Chadash 131:7 state that some places to not recite <em>tachanun</em> during this period. The Sh"UT Chasam Sofer on Choshen
532         * Mishpat 77 writes that this is the <em>minhag</em> in Ashkenaz. The Shaarei Teshuva 131:19 quotes the Sheyarie Kneses
533         * Hagdola who also states that it should not be recited. The Aderes wanted to institute saying <em>tachanun</em> during this
534         * period, but was dissuaded from this by Rav Shmuel Salant who did not want to change the <em>minhag</em> in Yerushalayim.
535         * The Aruch Hashulchan is of the opinion that that this <em>minhag</em> is incorrect, and it should be recited, and The Chazon
536         * Ish also recited <em>tachanun</em> during this period. See the Dirshu edition of the Mishna Berurah for details.
537         * @return If <em>tachanun</em> is set to be recited at the end of {@link JewishDate#TISHREI <em>Tishrei</em>}.
538         * @see #setTachanunRecitedEndOfTishrei(tachanunRecitedEndOfTishrei)
539         */
540        public boolean isTachanunRecitedEndOfTishrei() {
541                return tachanunRecitedEndOfTishrei;
542        }
543
544        /**
545         * Sets if <em>tachanun</em> should be recited at the end of {@link JewishDate#TISHREI <em>Tishrei</em>}.
546         * @param tachanunRecitedEndOfTishrei is <em>tachanun</em> recited at the end of {@link JewishDate#TISHREI <em>Tishrei</em>}.
547         * @see #isTachanunRecitedEndOfTishrei()
548         */
549        public void setTachanunRecitedEndOfTishrei(boolean tachanunRecitedEndOfTishrei) {
550                this.tachanunRecitedEndOfTishrei = tachanunRecitedEndOfTishrei;
551        }
552        
553        /**
554         * Is <em>tachanun</em> recited during the week after <em>Shavuos</em>. This is the opinion of the Pri Megadim
555         * quoted by the Mishna Berurah. This is since <em>karbanos</em> of <em>Shavuos</em> have <em>tashlumim</em> for
556         * 7 days, it is still considered like a Yom Tov. The Chazon Ish quoted in the Orchos Rabainu vol. 1 page 68
557         * recited <em>tachanun</em> during this week.
558         * 
559         * @return If <em>tachanun</em> is set to be recited during the week after Shavuos.
560         * @see #setTachanunRecitedWeekAfterShavuos(boolean)
561         */
562        public boolean isTachanunRecitedWeekAfterShavuos() {
563                return tachanunRecitedWeekAfterShavuos;
564        }
565
566        /**
567         * Sets if <em>tachanun</em> should be recited during the week after <em>Shavuos</em>.
568         * @param tachanunRecitedWeekAfterShavuos is <em>tachanun</em> recited during the week after Shavuos.
569         * @see #isTachanunRecitedWeekAfterShavuos()
570         */
571        public void setTachanunRecitedWeekAfterShavuos(boolean tachanunRecitedWeekAfterShavuos) {
572                this.tachanunRecitedWeekAfterShavuos = tachanunRecitedWeekAfterShavuos;
573        }
574        
575        /**
576         * Is <em>tachanun</em> is recited on the 13th of {@link JewishDate#SIVAN <em>Sivan</em>} (<a href=
577         * "https://en.wikipedia.org/wiki/Yom_tov_sheni_shel_galuyot"><em>Yom Tov Sheni shel Galuyos</em></a> of the 7th
578         * day) outside Israel. This is brought down by the Shaarie Teshuva 131:19 quoting the <a href=
579         * "https://hebrewbooks.org/pdfpager.aspx?req=41295&st=&pgnum=39">Sheyarei Kneses Hagedola 131:12</a>that
580         * <em>tachanun</em> should not be recited on this day. Rav Shlomo Zalman Orbach in Halichos Shlomo on
581         * Shavuos 12:16:25 is of the opinion that even in <em>chutz laaretz</em> it should be recited since the <em>yemei
582         * Tashlumin</em> are counted based on Israel since that is where the <em>karbanos</em> are brought. Both
583         * {@link #isTachanunRecitedShacharis(JewishCalendar)} and {@link #isTachanunRecitedMincha(JewishCalendar)}
584         * only return false if the location is not set to {@link JewishCalendar#getInIsrael() Israel} and both
585         * {@link #tachanunRecitedWeekAfterShavuos} and {@link #setTachanunRecited13SivanOutOfIsrael} are set to false.
586         * 
587         * @return If <em>tachanun</em> is set to be recited on the 13th of {@link JewishDate#SIVAN <em>Sivan</em>} out of Israel.
588         * @see #setTachanunRecited13SivanOutOfIsrael(isTachanunRecitedThirteenSivanOutOfIsrael)
589         * @see #isTachanunRecitedWeekAfterShavuos()
590         */
591        public boolean isTachanunRecited13SivanOutOfIsrael() {
592                return tachanunRecited13SivanOutOfIsrael;
593        }
594
595        /**
596         * Sets if <em>tachanun</em> should be recited on the 13th of {@link JewishDate#SIVAN <em>Sivan</em>} (<a href=
597         * "https://en.wikipedia.org/wiki/Yom_tov_sheni_shel_galuyot"><em>Yom Tov Sheni shel Galuyos</em></a> of the 7th
598         * day) outside Israel. 
599         * @param tachanunRecitedThirteenSivanOutOfIsrael sets if <em>tachanun</em> should be recited on the 13th of {@link
600         *          JewishDate#SIVAN <em>Sivan</em>} out of Israel. Both {@link #isTachanunRecitedShacharis(JewishCalendar)} and
601         *          {@link #isTachanunRecitedMincha(JewishCalendar)} only return false if the location is not set to {@link
602         *          JewishCalendar#getInIsrael() Israel} and both {@link #tachanunRecitedWeekAfterShavuos} and
603         *          {@link #setTachanunRecited13SivanOutOfIsrael} are set to false.
604         * @see #isTachanunRecited13SivanOutOfIsrael()
605         */
606        public void setTachanunRecited13SivanOutOfIsrael(boolean tachanunRecitedThirteenSivanOutOfIsrael) {
607                this.tachanunRecited13SivanOutOfIsrael = tachanunRecitedThirteenSivanOutOfIsrael;
608        }
609        
610        /**
611         * Is <em>tachanun</em> recited on {@link JewishCalendar#PESACH_SHENI <em>Pesach Sheni</em>}. The Pri Chadash 131:7 states
612         * that <em>tachanun</em> should not be recited. The Aruch Hashulchan states that this is the minhag of the <em>sephardim</em>.
613         * the Shaarei Efraim 10:27 also mentions that it is not recited, as does the Siddur Yaavetz (Shaar Hayesod, Chodesh Iyar).
614         * The Pri Megadim (Mishbetzes Hazahav 131:15) and the Chazon Ish (Erev Pesahc Shchal Beshabos, page 203 in <a href=
615         * "https://he.wikipedia.org/wiki/%D7%A9%D7%A8%D7%99%D7%94_%D7%93%D7%91%D7%9C%D7%99%D7%A6%D7%A7%D7%99">Rav Sheraya
616         * Devlitzky's</a> comments).
617         * 
618         * @return If <em>tachanun</em> is recited on {@link JewishCalendar#PESACH_SHENI <em>Pesach Sheni</em>}.
619         * @see #setTachanunRecitedPesachSheni(boolean)
620         */
621        public boolean isTachanunRecitedPesachSheni() {
622                return tachanunRecitedPesachSheni;
623        }
624
625        /**
626         * Sets if <em>tachanun</em> should be recited on {@link JewishCalendar#PESACH_SHENI <em>Pesach Sheni</em>}.
627         * @param tachanunRecitedPesachSheni sets if <em>tachanun</em> should be recited on <em>Pesach Sheni</em>.
628         * @see #isTachanunRecitedPesachSheni()
629         */
630        public void setTachanunRecitedPesachSheni(boolean tachanunRecitedPesachSheni) {
631                this.tachanunRecitedPesachSheni = tachanunRecitedPesachSheni;
632        }
633        
634        /**
635         * Is <em>tachanun</em> recited on 15 {@link JewishDate#IYAR <em>Iyar</em>} (<em>sfaika deyoma</em> of {@link JewishCalendar#PESACH_SHENI
636         * <em>Pesach Sheni</em>}) out of Israel. If {@link #isTachanunRecitedPesachSheni()} is <code>true</code> this will be
637         * ignored even if <code>false</code>.
638         * 
639         * @return if <em>tachanun</em> is recited on 15 {@link JewishDate#IYAR <em>Iyar</em>}  (<em>sfaika deyoma</em> of {@link
640         *          JewishCalendar#PESACH_SHENI <em>Pesach Sheni</em>} out of Israel. If {@link #isTachanunRecitedPesachSheni()}
641         *          is <code>true</code> this will be ignored even if <code>false</code>.
642         * @see #setTachanunRecited15IyarOutOfIsrael(boolean)
643         * @see #setTachanunRecitedPesachSheni(boolean)
644         * @see #isTachanunRecitedPesachSheni()
645         */
646        public boolean isTachanunRecited15IyarOutOfIsrael() {
647                return tachanunRecited15IyarOutOfIsrael;
648        }
649
650        /**
651         * Sets if <em>tachanun</em> should be recited on the 15th of {@link JewishDate#IYAR <em>Iyar</em>}  (<a href=
652         * "https://en.wikipedia.org/wiki/Yom_tov_sheni_shel_galuyot"><em>Yom Tov Sheni shel Galuyos</em></a> of
653         * {@link JewishCalendar#PESACH_SHENI <em>Pesach Sheni</em>}) out of Israel. Ignored if {@link
654         * #isTachanunRecitedPesachSheni()} is <code>true</code>.
655         * 
656         * @param tachanunRecited15IyarOutOfIsrael if <em>tachanun</em> should be recited on the 15th of {@link JewishDate#IYAR
657         *          <em>Iyar</em>} (<em>sfaika deyoma</em> of {@link JewishCalendar#PESACH_SHENI <em>Pesach Sheni</em>}) out of Israel.
658         * @see #isTachanunRecited15IyarOutOfIsrael()
659         */
660        public void setTachanunRecited15IyarOutOfIsrael(boolean tachanunRecited15IyarOutOfIsrael) {
661                this.tachanunRecited15IyarOutOfIsrael = tachanunRecited15IyarOutOfIsrael;
662        }
663        
664        /**
665         * Is <em>tachanun</em> recited on <em>mincha</em> on <em>erev {@link JewishCalendar#LAG_BAOMER Lag Baomer}</em>.
666         * @return if <em>tachanun</em> is recited in <em>mincha</em> on <em>erev</em>
667         *          {@link JewishCalendar#LAG_BAOMER <em>Lag Baomer</em>}.
668         * @see #setTachanunRecitedMinchaErevLagBaomer(boolean)
669         */
670        public boolean isTachanunRecitedMinchaErevLagBaomer() {
671                return tachanunRecitedMinchaErevLagBaomer;
672        }
673
674        /**
675         * Sets if <em>tachanun</em> should be recited on <em>erev {@link JewishCalendar#LAG_BAOMER Lag Baomer}</em>.
676         * @param tachanunRecitedMinchaErevLagBaomer sets if <em>tachanun</em> should be recited on <em>mincha</em>
677         *          of <em>erev {@link JewishCalendar#LAG_BAOMER Lag Baomer}</em>.
678         * @see #isTachanunRecitedMinchaErevLagBaomer()
679         */
680        public void setTachanunRecitedMinchaErevLagBaomer(boolean tachanunRecitedMinchaErevLagBaomer) {
681                this.tachanunRecitedMinchaErevLagBaomer = tachanunRecitedMinchaErevLagBaomer;
682        }
683        
684        /**
685         * Is <em>tachanun</em> recited during the <em>Shivas Yemei Hamiluim</em>, from the 23 of {@link
686         * JewishDate#ADAR <em>Adar</em>} on a non-leap-year or {@link JewishDate#ADAR_II <em>Adar II</em>} on a
687         * leap year to the end of the month. Some <em>chasidishe</em> communities do not say <em>tachanun</em>
688         * during this week. See <a href="https://hebrewbooks.org/pdfpager.aspx?req=4692&st=&pgnum=70">Darkei
689         * Chaim Veshalom 191</a>.
690         * @return if <em>tachanun</em> is recited during the <em>Shivas Yemei Hamiluim</em>, from the 23 of {@link
691         *          JewishDate#ADAR <em>Adar</em>} on a non-leap-year or {@link JewishDate#ADAR_II <em>Adar II</em>}
692         *          on a leap year to the end of the month.
693         * @see #setTachanunRecitedShivasYemeiHamiluim(boolean)
694         */
695        public boolean isTachanunRecitedShivasYemeiHamiluim() {
696                return tachanunRecitedShivasYemeiHamiluim;
697        }
698
699        /**
700         * Sets if <em>tachanun</em> should be recited during the <em>Shivas Yemei Hamiluim</em>, from the 23 of
701         * {@link JewishDate#ADAR <em>Adar</em>} on a non-leap-year or {@link JewishDate#ADAR_II <em>Adar II</em>}
702         * on a leap year to the end of the month.
703         * @param tachanunRecitedShivasYemeiHamiluim sets if <em>tachanun</em> should be recited during the
704         *          <em>Shivas Yemei Hamiluim</em>.
705         * @see #isTachanunRecitedShivasYemeiHamiluim()
706         */
707        public void setTachanunRecitedShivasYemeiHamiluim(boolean tachanunRecitedShivasYemeiHamiluim) {
708                this.tachanunRecitedShivasYemeiHamiluim = tachanunRecitedShivasYemeiHamiluim;
709        }
710
711        /**
712         * Is <em>tachanun</em> recited on Fridays. Some <em>chasidishe</em> communities do not recite
713         * <em>tachanun</em> on Fridays. See <a href="https://hebrewbooks.org/pdfpager.aspx?req=41190&st=&pgnum=10">Likutei
714         * Maharich Vol 2 Seder Hanhagos Erev Shabbos</a>. This is also the <em>minhag</em> in Satmar.
715         * @return if <em>tachanun</em> is recited on Fridays.
716         * @see #setTachanunRecitedFridays(boolean)
717         */
718        public boolean isTachanunRecitedFridays() {
719                return tachanunRecitedFridays;
720        }
721
722        /**
723         * Sets if <em>tachanun</em> should be recited on Fridays. 
724         * @param tachanunRecitedFridays sets if <em>tachanun</em> should be recited on Fridays. Some <em>chasidishe</em>
725         *          communities do not recite <em>tachanun</em> on Fridays.
726         * @see #isTachanunRecitedFridays()
727         */
728        public void setTachanunRecitedFridays(boolean tachanunRecitedFridays) {
729                this.tachanunRecitedFridays = tachanunRecitedFridays;
730        }
731
732        /**
733         * Is <em>tachanun</em> recited on Sundays. Some <em>chasidishe</em> communities do not recite
734         * <em>tachanun</em> on Sundays. See <a href="https://hebrewbooks.org/pdfpager.aspx?req=41190&st=&pgnum=10">Likutei
735         * Maharich Vol 2 Seder Hanhagos Erev Shabbos</a>. 
736         * @return if <em>tachanun</em> is recited on Sundays.
737         * @see #setTachanunRecitedSundays(boolean)
738         */
739        public boolean isTachanunRecitedSundays() {
740                return tachanunRecitedSundays;
741        }
742
743        /**
744         * Sets if <em>tachanun</em> should be recited on Sundays. 
745         * @param tachanunRecitedSundays sets if <em>tachanun</em> should be recited on Sundays. Some <em>chasidishe</em>
746         *          communities do not recite <em>tachanun</em> on Sundays.
747         * @see #isTachanunRecitedSundays()
748         */
749        public void setTachanunRecitedSundays(boolean tachanunRecitedSundays) {
750                this.tachanunRecitedSundays = tachanunRecitedSundays;
751        }
752        
753        /**
754         * Is <em>tachanun</em> recited in <em>Mincha</em> the entire year. Some <em>chasidishe</em> communities do not recite
755         * <em>tachanun</em> by <em>Mincha</em> all year round. See<a href=
756         * "https://hebrewbooks.org/pdfpager.aspx?req=4751&st=&pgnum=105">Nemukei Orach Chaim 131:3</a>.
757         * @return if <em>tachanun</em> is recited in <em>Mincha</em> the entire year.
758         * @see #setTachanunRecitedMinchaAllYear(boolean)
759         */
760        public boolean isTachanunRecitedMinchaAllYear() {
761                return tachanunRecitedMinchaAllYear;
762        }
763
764        /**
765         * Sets if <em>tachanun</em> should be recited in <em>Mincha</em> the entire year.
766         * @param tachanunRecitedMinchaAllYear sets if <em>tachanun</em> should be recited by <em>mincha</em> all year. If set
767         *          to false, {@link #isTachanunRecitedMincha(JewishCalendar)} will always return false. If set to true (the
768         *          default), it will use the regular rules.
769         * @see #isTachanunRecitedMinchaAllYear()
770         */
771        public void setTachanunRecitedMinchaAllYear(boolean tachanunRecitedMinchaAllYear) {
772                this.tachanunRecitedMinchaAllYear = tachanunRecitedMinchaAllYear;
773        }
774}