001/* 002 * Zmanim Java API 003 * Copyright © 2011 - 2026 Eliyahu Hershfeld 004 * 005 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General 006 * Public License as published by the Free Software Foundation; version 2.1 of the License. 007 * 008 * This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied 009 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 010 * details. 011 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to 012 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA, 013 * or connect to: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 014 */ 015package com.kosherjava.zmanim.hebrewcalendar; 016 017import java.time.format.DateTimeFormatter; 018import java.util.EnumMap; 019 020/** 021 * The HebrewDateFormatter class formats a {@link JewishDate}. The class formats Jewish dates, numbers, <em>Daf Yomi</em> 022 * (<em>Bavli</em> and <em>Yerushalmi</em>), the <em>Omer</em>, <em>Parshas Hashavua</em> (including the special <em>parshiyos</em> 023 * of <em>Shekalim</em>, <em>Zachor</em>, <em>Parah</em> and <em>Hachodesh</em>), <em>Yomim Tovim</em> in Hebrew or Latin chars, and 024 * has various settings. Sample full date output includes (using various options): 025 * <ul> 026 * <li>21 Shevat, 5729</li> 027 * <li>כא שבט תשכט</li> 028 * <li>כ״א שבט ה׳תשכ״ט</li> 029 * <li>כ״א שבט תש״פ or כ״א שבט תש״ף</li> 030 * <li>כ׳ שבט ו׳ אלפים</li> 031 * </ul> 032 * 033 * @see JewishDate 034 * @see JewishCalendar 035 * @author © Eliyahu Hershfeld 2011 - 2026 036 */ 037public class HebrewDateFormatter { 038 039 /** 040 * See {@link #isHebrewFormat()} and {@link #setHebrewFormat(boolean)}. 041 */ 042 private boolean hebrewFormat = false; 043 044 /** 045 * See {@link #isUseLongHebrewYears()} and {@link #setUseLongHebrewYears(boolean)}. 046 */ 047 private boolean useLonghebrewYears = false; 048 049 /** 050 * See {@link #isUseGershGershayim()} and {@link #setUseGershGershayim(boolean)}. 051 */ 052 private boolean useGershGershayim = true; 053 054 /** 055 * See {@link #isLongWeekFormat()} and {@link #setLongWeekFormat(boolean)}. 056 */ 057 private boolean longWeekFormat = true; 058 059 /** 060 * See {@link #isUseFinalFormLetters()} and {@link #setUseFinalFormLetters(boolean)}. 061 */ 062 private boolean useFinalFormLetters = false; 063 064 /** 065 * The internal DateFormat. See {@link #isLongWeekFormat()} and {@link #setLongWeekFormat(boolean)}. 066 */ 067 private DateTimeFormatter weekFormat; 068 069 /** 070 * List of transliterated parshiyos using the default <em>Ashkenazi</em> pronunciation. For information on the format, see 071 * {@link #getTransliteratedParshiosList()}. 072 * 073 * @see #getTransliteratedParshiosList() 074 * @see #setTransliteratedParshiosList(EnumMap) 075 * @see #HebrewDateFormatter() where the map is initially set. 076 */ 077 private EnumMap<JewishCalendar.Parsha, String> transliteratedParshaMap; 078 079 /** 080 * An {@link EnumMap} of Hebrew <em>parshiyos</em>. The list includes double and special <em>parshiyos</em> and contains<br> 081 * <code>‏בראשית, נח, לך לך,וירא, חיי שרה,תולדות, ויצא, וישלח,וישב, מקץ, ויגש, ויחי,שמות, וארא, בא, בשלח,יתרו, משפטים, תרומה,תצוה, כי תשא, ויקהל,פקודי, 082 * ויקרא, צו,שמיני, תזריע, מצרע,אחרי מות, קדושים,אמור, בהר, בחקתי,במדבר, נשא, בהעלתך,שלח לך, קרח, חוקת, בלק,פינחס, מטות, מסעי,דברים, ואתחנן, עקב,ראה, שופטים, כי תצא,כי 083 * תבוא, נצבים, וילך,האזינו, וזאת הברכה,ויקהל פקודי, תזריעמצרע, אחרי מותקדושים, בהר בחקתי,חוקת בלק, מטות מסעי,נצבים וילך, 084 * שקלים,זכור, פרה, החדש,שובה,שירה,הגדול,חזון,נחמו</code> 085 */ 086 private final EnumMap<JewishCalendar.Parsha, String> hebrewParshaMap; 087 088 /** 089 * Default constructor sets the {@link EnumMap}s of Hebrew and default transliterated parshiyos. 090 */ 091 public HebrewDateFormatter() { 092 weekFormat = DateTimeFormatter.ofPattern("EEEE"); 093 transliteratedParshaMap = new EnumMap<>(JewishCalendar.Parsha.class); 094 transliteratedParshaMap.put(JewishCalendar.Parsha.NONE, ""); 095 transliteratedParshaMap.put(JewishCalendar.Parsha.BERESHIS, "Bereshis"); 096 transliteratedParshaMap.put(JewishCalendar.Parsha.NOACH, "Noach"); 097 transliteratedParshaMap.put(JewishCalendar.Parsha.LECH_LECHA, "Lech Lecha"); 098 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYERA, "Vayera"); 099 transliteratedParshaMap.put(JewishCalendar.Parsha.CHAYEI_SARA, "Chayei Sara"); 100 transliteratedParshaMap.put(JewishCalendar.Parsha.TOLDOS, "Toldos"); 101 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYETZEI, "Vayetzei"); 102 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYISHLACH, "Vayishlach"); 103 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYESHEV, "Vayeshev"); 104 transliteratedParshaMap.put(JewishCalendar.Parsha.MIKETZ, "Miketz"); 105 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYIGASH, "Vayigash"); 106 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYECHI, "Vayechi"); 107 transliteratedParshaMap.put(JewishCalendar.Parsha.SHEMOS, "Shemos"); 108 transliteratedParshaMap.put(JewishCalendar.Parsha.VAERA, "Vaera"); 109 transliteratedParshaMap.put(JewishCalendar.Parsha.BO, "Bo"); 110 transliteratedParshaMap.put(JewishCalendar.Parsha.BESHALACH, "Beshalach"); 111 transliteratedParshaMap.put(JewishCalendar.Parsha.YISRO, "Yisro"); 112 transliteratedParshaMap.put(JewishCalendar.Parsha.MISHPATIM, "Mishpatim"); 113 transliteratedParshaMap.put(JewishCalendar.Parsha.TERUMAH, "Terumah"); 114 transliteratedParshaMap.put(JewishCalendar.Parsha.TETZAVEH, "Tetzaveh"); 115 transliteratedParshaMap.put(JewishCalendar.Parsha.KI_SISA, "Ki Sisa"); 116 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYAKHEL, "Vayakhel"); 117 transliteratedParshaMap.put(JewishCalendar.Parsha.PEKUDEI, "Pekudei"); 118 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYIKRA, "Vayikra"); 119 transliteratedParshaMap.put(JewishCalendar.Parsha.TZAV, "Tzav"); 120 transliteratedParshaMap.put(JewishCalendar.Parsha.SHMINI, "Shmini"); 121 transliteratedParshaMap.put(JewishCalendar.Parsha.TAZRIA, "Tazria"); 122 transliteratedParshaMap.put(JewishCalendar.Parsha.METZORA, "Metzora"); 123 transliteratedParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS, "Achrei Mos"); 124 transliteratedParshaMap.put(JewishCalendar.Parsha.KEDOSHIM, "Kedoshim"); 125 transliteratedParshaMap.put(JewishCalendar.Parsha.EMOR, "Emor"); 126 transliteratedParshaMap.put(JewishCalendar.Parsha.BEHAR, "Behar"); 127 transliteratedParshaMap.put(JewishCalendar.Parsha.BECHUKOSAI, "Bechukosai"); 128 transliteratedParshaMap.put(JewishCalendar.Parsha.BAMIDBAR, "Bamidbar"); 129 transliteratedParshaMap.put(JewishCalendar.Parsha.NASSO, "Nasso"); 130 transliteratedParshaMap.put(JewishCalendar.Parsha.BEHAALOSCHA, "Beha'aloscha"); 131 transliteratedParshaMap.put(JewishCalendar.Parsha.SHLACH, "Sh'lach"); 132 transliteratedParshaMap.put(JewishCalendar.Parsha.KORACH, "Korach"); 133 transliteratedParshaMap.put(JewishCalendar.Parsha.CHUKAS, "Chukas"); 134 transliteratedParshaMap.put(JewishCalendar.Parsha.BALAK, "Balak"); 135 transliteratedParshaMap.put(JewishCalendar.Parsha.PINCHAS, "Pinchas"); 136 transliteratedParshaMap.put(JewishCalendar.Parsha.MATOS, "Matos"); 137 transliteratedParshaMap.put(JewishCalendar.Parsha.MASEI, "Masei"); 138 transliteratedParshaMap.put(JewishCalendar.Parsha.DEVARIM, "Devarim"); 139 transliteratedParshaMap.put(JewishCalendar.Parsha.VAESCHANAN, "Vaeschanan"); 140 transliteratedParshaMap.put(JewishCalendar.Parsha.EIKEV, "Eikev"); 141 transliteratedParshaMap.put(JewishCalendar.Parsha.REEH, "Re'eh"); 142 transliteratedParshaMap.put(JewishCalendar.Parsha.SHOFTIM, "Shoftim"); 143 transliteratedParshaMap.put(JewishCalendar.Parsha.KI_SEITZEI, "Ki Seitzei"); 144 transliteratedParshaMap.put(JewishCalendar.Parsha.KI_SAVO, "Ki Savo"); 145 transliteratedParshaMap.put(JewishCalendar.Parsha.NITZAVIM, "Nitzavim"); 146 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYEILECH, "Vayeilech"); 147 transliteratedParshaMap.put(JewishCalendar.Parsha.HAAZINU, "Ha'Azinu"); 148 transliteratedParshaMap.put(JewishCalendar.Parsha.VZOS_HABERACHA, "Vezos Habracha"); 149 transliteratedParshaMap.put(JewishCalendar.Parsha.VAYAKHEL_PEKUDEI, "Vayakhel Pekudei"); 150 transliteratedParshaMap.put(JewishCalendar.Parsha.TAZRIA_METZORA, "Tazria Metzora"); 151 transliteratedParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS_KEDOSHIM, "Achrei Mos Kedoshim"); 152 transliteratedParshaMap.put(JewishCalendar.Parsha.BEHAR_BECHUKOSAI, "Behar Bechukosai"); 153 transliteratedParshaMap.put(JewishCalendar.Parsha.CHUKAS_BALAK, "Chukas Balak"); 154 transliteratedParshaMap.put(JewishCalendar.Parsha.MATOS_MASEI, "Matos Masei"); 155 transliteratedParshaMap.put(JewishCalendar.Parsha.NITZAVIM_VAYEILECH, "Nitzavim Vayeilech"); 156 transliteratedParshaMap.put(JewishCalendar.Parsha.SHKALIM, "Shekalim"); 157 transliteratedParshaMap.put(JewishCalendar.Parsha.ZACHOR, "Zachor"); 158 transliteratedParshaMap.put(JewishCalendar.Parsha.PARA, "Parah"); 159 transliteratedParshaMap.put(JewishCalendar.Parsha.HACHODESH, "Hachodesh"); 160 transliteratedParshaMap.put(JewishCalendar.Parsha.SHUVA, "Shuva"); 161 transliteratedParshaMap.put(JewishCalendar.Parsha.SHIRA, "Shira"); 162 transliteratedParshaMap.put(JewishCalendar.Parsha.HAGADOL, "Hagadol"); 163 transliteratedParshaMap.put(JewishCalendar.Parsha.CHAZON, "Chazon"); 164 transliteratedParshaMap.put(JewishCalendar.Parsha.NACHAMU, "Nachamu"); 165 166 hebrewParshaMap = new EnumMap<>(JewishCalendar.Parsha.class); 167 hebrewParshaMap.put(JewishCalendar.Parsha.NONE, ""); 168 hebrewParshaMap.put(JewishCalendar.Parsha.BERESHIS, "בראשית"); 169 hebrewParshaMap.put(JewishCalendar.Parsha.NOACH, "נח"); 170 hebrewParshaMap.put(JewishCalendar.Parsha.LECH_LECHA, "לך לך"); 171 hebrewParshaMap.put(JewishCalendar.Parsha.VAYERA, "וירא"); 172 hebrewParshaMap.put(JewishCalendar.Parsha.CHAYEI_SARA, "חיי שרה"); 173 hebrewParshaMap.put(JewishCalendar.Parsha.TOLDOS, "תולדות"); 174 hebrewParshaMap.put(JewishCalendar.Parsha.VAYETZEI, "ויצא"); 175 hebrewParshaMap.put(JewishCalendar.Parsha.VAYISHLACH, "וישלח"); 176 hebrewParshaMap.put(JewishCalendar.Parsha.VAYESHEV, "וישב"); 177 hebrewParshaMap.put(JewishCalendar.Parsha.MIKETZ, "מקץ"); 178 hebrewParshaMap.put(JewishCalendar.Parsha.VAYIGASH, "ויגש"); 179 hebrewParshaMap.put(JewishCalendar.Parsha.VAYECHI, "ויחי"); 180 hebrewParshaMap.put(JewishCalendar.Parsha.SHEMOS, "שמות"); 181 hebrewParshaMap.put(JewishCalendar.Parsha.VAERA, "וארא"); 182 hebrewParshaMap.put(JewishCalendar.Parsha.BO, "בא"); 183 hebrewParshaMap.put(JewishCalendar.Parsha.BESHALACH, "בשלח"); 184 hebrewParshaMap.put(JewishCalendar.Parsha.YISRO, "יתרו"); 185 hebrewParshaMap.put(JewishCalendar.Parsha.MISHPATIM, "משפטים"); 186 hebrewParshaMap.put(JewishCalendar.Parsha.TERUMAH, "תרומה"); 187 hebrewParshaMap.put(JewishCalendar.Parsha.TETZAVEH, "תצוה"); 188 hebrewParshaMap.put(JewishCalendar.Parsha.KI_SISA, "כי תשא"); 189 hebrewParshaMap.put(JewishCalendar.Parsha.VAYAKHEL, "ויקהל"); 190 hebrewParshaMap.put(JewishCalendar.Parsha.PEKUDEI, "פקודי"); 191 hebrewParshaMap.put(JewishCalendar.Parsha.VAYIKRA, "ויקרא"); 192 hebrewParshaMap.put(JewishCalendar.Parsha.TZAV, "צו"); 193 hebrewParshaMap.put(JewishCalendar.Parsha.SHMINI, "שמיני"); 194 hebrewParshaMap.put(JewishCalendar.Parsha.TAZRIA, "תזריע"); 195 hebrewParshaMap.put(JewishCalendar.Parsha.METZORA, "מצרע"); 196 hebrewParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS, "אחרי מות"); 197 hebrewParshaMap.put(JewishCalendar.Parsha.KEDOSHIM, "קדושים"); 198 hebrewParshaMap.put(JewishCalendar.Parsha.EMOR, "אמור"); 199 hebrewParshaMap.put(JewishCalendar.Parsha.BEHAR, "בהר"); 200 hebrewParshaMap.put(JewishCalendar.Parsha.BECHUKOSAI, "בחקתי"); 201 hebrewParshaMap.put(JewishCalendar.Parsha.BAMIDBAR, "במדבר"); 202 hebrewParshaMap.put(JewishCalendar.Parsha.NASSO, "נשא"); 203 hebrewParshaMap.put(JewishCalendar.Parsha.BEHAALOSCHA, "בהעלתך"); 204 hebrewParshaMap.put(JewishCalendar.Parsha.SHLACH, "שלח לך"); 205 hebrewParshaMap.put(JewishCalendar.Parsha.KORACH, "קרח"); 206 hebrewParshaMap.put(JewishCalendar.Parsha.CHUKAS, "חוקת"); 207 hebrewParshaMap.put(JewishCalendar.Parsha.BALAK, "בלק"); 208 hebrewParshaMap.put(JewishCalendar.Parsha.PINCHAS, "פינחס"); 209 hebrewParshaMap.put(JewishCalendar.Parsha.MATOS, "מטות"); 210 hebrewParshaMap.put(JewishCalendar.Parsha.MASEI, "מסעי"); 211 hebrewParshaMap.put(JewishCalendar.Parsha.DEVARIM, "דברים"); 212 hebrewParshaMap.put(JewishCalendar.Parsha.VAESCHANAN, "ואתחנן"); 213 hebrewParshaMap.put(JewishCalendar.Parsha.EIKEV, "עקב"); 214 hebrewParshaMap.put(JewishCalendar.Parsha.REEH, "ראה"); 215 hebrewParshaMap.put(JewishCalendar.Parsha.SHOFTIM, "שופטים"); 216 hebrewParshaMap.put(JewishCalendar.Parsha.KI_SEITZEI, "כי תצא"); 217 hebrewParshaMap.put(JewishCalendar.Parsha.KI_SAVO, "כי תבוא"); 218 hebrewParshaMap.put(JewishCalendar.Parsha.NITZAVIM, "נצבים"); 219 hebrewParshaMap.put(JewishCalendar.Parsha.VAYEILECH, "וילך"); 220 hebrewParshaMap.put(JewishCalendar.Parsha.HAAZINU, "האזינו"); 221 hebrewParshaMap.put(JewishCalendar.Parsha.VZOS_HABERACHA, "וזאת הברכה"); 222 hebrewParshaMap.put(JewishCalendar.Parsha.VAYAKHEL_PEKUDEI, "ויקהל פקודי"); 223 hebrewParshaMap.put(JewishCalendar.Parsha.TAZRIA_METZORA, "תזריע מצרע"); 224 hebrewParshaMap.put(JewishCalendar.Parsha.ACHREI_MOS_KEDOSHIM, "אחרי מות קדושים"); 225 hebrewParshaMap.put(JewishCalendar.Parsha.BEHAR_BECHUKOSAI, "בהר בחקתי"); 226 hebrewParshaMap.put(JewishCalendar.Parsha.CHUKAS_BALAK, "חוקת בלק"); 227 hebrewParshaMap.put(JewishCalendar.Parsha.MATOS_MASEI, "מטות מסעי"); 228 hebrewParshaMap.put(JewishCalendar.Parsha.NITZAVIM_VAYEILECH, "נצבים וילך"); 229 hebrewParshaMap.put(JewishCalendar.Parsha.SHKALIM, "שקלים"); 230 hebrewParshaMap.put(JewishCalendar.Parsha.ZACHOR, "זכור"); 231 hebrewParshaMap.put(JewishCalendar.Parsha.PARA, "פרה"); 232 hebrewParshaMap.put(JewishCalendar.Parsha.HACHODESH, "החדש"); 233 hebrewParshaMap.put(JewishCalendar.Parsha.SHUVA, "שובה"); 234 hebrewParshaMap.put(JewishCalendar.Parsha.SHIRA, "שירה"); 235 hebrewParshaMap.put(JewishCalendar.Parsha.HAGADOL, "הגדול"); 236 hebrewParshaMap.put(JewishCalendar.Parsha.CHAZON, "חזון"); 237 hebrewParshaMap.put(JewishCalendar.Parsha.NACHAMU, "נחמו"); 238 } 239 240 /** 241 * Returns if the {@link #formatDayOfWeek(JewishDate)} will use the long format such as ראשון or short such as א when formatting 242 * the day of week in {@link #isHebrewFormat() Hebrew}. 243 * 244 * @return the longWeekFormat 245 * @see #setLongWeekFormat(boolean) 246 * @see #formatDayOfWeek(JewishDate) 247 */ 248 public boolean isLongWeekFormat() { 249 return longWeekFormat; 250 } 251 252 /** 253 * Setting to control if the {@link #formatDayOfWeek(JewishDate)} will use the long format such as ראשון or short such as א when 254 * formatting the day of week in {@link #isHebrewFormat() Hebrew}. 255 * 256 * @param longWeekFormat the longWeekFormat to set 257 */ 258 public void setLongWeekFormat(boolean longWeekFormat) { 259 this.longWeekFormat = longWeekFormat; 260 if (longWeekFormat) { 261 weekFormat = DateTimeFormatter.ofPattern("EEEE"); 262 } else { 263 weekFormat = DateTimeFormatter.ofPattern("EEE"); 264 } 265 } 266 267 /** 268 * The <a href="https://en.wikipedia.org/wiki/Geresh#Punctuation_mark">gersh</a> character is the ׳ char that is similar to a 269 * single quote and is used in formatting Hebrew numbers. 270 */ 271 private static final String GERESH = "׳"; 272 273 /** 274 * The <a href="https://en.wikipedia.org/wiki/Gershayim#Punctuation_mark">gershyim</a> character is the ״ char that is similar 275 * to a double quote and is used in formatting Hebrew numbers. 276 */ 277 private static final String GERSHAYIM = "״"; 278 279 /** 280 * Transliterated month names that default to <code>["Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Cheshvan", 281 * "Kislev", "Teves", "Shevat", "Adar", "Adar II", "Adar I" ]</code>. 282 * @see #getTransliteratedMonthList() 283 * @see #setTransliteratedMonthList(String[]) 284 */ 285 private String[] transliteratedMonths = { "Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Cheshvan", 286 "Kislev", "Teves", "Shevat", "Adar", "Adar II", "Adar I" }; 287 288 /** 289 * The Hebrew omer prefix charachter. It defaults to ב producing בעומר, but can be set to ל to produce לעומר (or any other prefix). 290 * @see #getHebrewOmerPrefix() 291 * @see #setHebrewOmerPrefix(String) 292 */ 293 private String hebrewOmerPrefix = "ב"; 294 295 /** 296 * The default value for formatting "Shabbos" (Saturday) when transliterated. 297 * @see #getTransliteratedShabbosDayOfWeek() 298 * @see #setTransliteratedShabbosDayOfWeek(String) 299 */ 300 private String transliteratedShabbosDayOfWeek = "Shabbos"; 301 302 /** 303 * Returns the day of Shabbos transliterated into Latin chars. The default uses Ashkenazi pronunciation "Shabbos". This can be 304 * overwritten using the {@link #setTransliteratedShabbosDayOfWeek(String)}. It is uesd by {@link #formatDayOfWeek(JewishDate)}. 305 * 306 * @return the transliteratedShabbos. The default list of months uses Ashkenazi pronunciation "Shabbos". 307 * @see #setTransliteratedShabbosDayOfWeek(String) 308 * @see #formatDayOfWeek(JewishDate) 309 */ 310 public String getTransliteratedShabbosDayOfWeek() { 311 return transliteratedShabbosDayOfWeek; 312 } 313 314 /** 315 * Setter to override the default transliterated name of "Shabbos" to alternate spelling such as "Shabbat" used by 316 * the {@link #formatDayOfWeek(JewishDate)}. 317 * 318 * @param transliteratedShabbos the transliteratedShabbos to set 319 * @see #getTransliteratedShabbosDayOfWeek() 320 * @see #formatDayOfWeek(JewishDate) 321 */ 322 public void setTransliteratedShabbosDayOfWeek(String transliteratedShabbos) { 323 this.transliteratedShabbosDayOfWeek = transliteratedShabbos; 324 } 325 326 /** 327 * See {@link #getTransliteratedHolidayList()} and {@link #setTransliteratedHolidayList(String[])}. 328 */ 329 private String[] transliteratedHolidays = {"Erev Pesach", "Pesach", "Chol Hamoed Pesach", "Pesach Sheni", 330 "Erev Shavuos", "Shavuos", "Seventeenth of Tammuz", "Tishah B'Av", "Tu B'Av", "Erev Rosh Hashana", 331 "Rosh Hashana", "Fast of Gedalyah", "Erev Yom Kippur", "Yom Kippur", "Erev Succos", "Succos", 332 "Chol Hamoed Succos", "Hoshana Rabbah", "Shemini Atzeres", "Simchas Torah", "Erev Chanukah", "Chanukah", 333 "Tenth of Teves", "Tu B'Shvat", "Fast of Esther", "Purim", "Shushan Purim", "Purim Katan", "Rosh Chodesh", 334 "Yom HaShoah", "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim", "Lag B'Omer", "Shushan Purim Katan", 335 "Isru Chag"}; 336 337 /** 338 * Returns the array of <em>Yomim Tovim</em> (holidays) transliterated into Latin chars. This is used by the {@link 339 * #formatYomTov(JewishCalendar)} when formatting the <em>Yom Tov</em> String. The default list of months usesnAshkenazi 340 * pronunciation in typical American English spelling. The default list is currently 341 * <code>["Erev Pesach", "Pesach", "Chol Hamoed Pesach", "Pesach Sheni", "Erev Shavuos", "Shavuos", "Seventeenth of Tammuz", 342 * "Tishah B'Av", "Tu B'Av", "Erev Rosh Hashana", "Rosh Hashana", "Fast of Gedalyah", "Erev Yom Kippur", "Yom Kippur", "Erev 343 * Succos", "Succos", "Chol Hamoed Succos", "Hoshana Rabbah", "Shemini Atzeres", "Simchas Torah", "Erev Chanukah", "Chanukah", 344 * "Tenth of Teves", "Tu B'Shvat", "Fast of Esther", "Purim", "Shushan Purim",m"Purim Katan", "Rosh Chodesh", "Yom HaShoah", 345 * "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim", "Lag B'Omer", "Shushan Purim Katan", "Isru Chag"]</code>. 346 * 347 * @return the array of transliterated <em>Yomim Tovim</em> (holidays). 348 * @see #setTransliteratedMonthList(String[]) 349 * @see #formatYomTov(JewishCalendar) 350 * @see #isHebrewFormat() 351 */ 352 public String[] getTransliteratedHolidayList() { 353 return transliteratedHolidays; 354 } 355 356 /** 357 * Sets the array of <em>Yomim Tovim</em> (holidays) transliterated into Latin chars. This is used by the 358 * {@link #formatYomTov(JewishCalendar)} when formatting the <em>Yom Tov</em> String. The list uses the following order and uses 359 * the spelling as follows. 360 * <code>["Erev Pesach", "Pesach", "Chol Hamoed Pesach", "Pesach Sheni", "Erev Shavuos", "Shavuos", "Seventeenth of Tammuz", 361 * "Tishah B'Av", "Tu B'Av", "Erev Rosh Hashana", "Rosh Hashana", "Fast of Gedalyah", "Erev Yom Kippur", "Yom Kippur", "Erev 362 * Succos", "Succos", "Chol Hamoed Succos", "Hoshana Rabbah", "Shemini Atzeres", "Simchas Torah", "Erev Chanukah", "Chanukah", 363 * "Tenth of Teves", "Tu B'Shvat", "Fast of Esther", "Purim", "Shushan Purim", "Purim Katan", "Rosh Chodesh", "Yom HaShoah", 364 * "Yom Hazikaron", "Yom Ha'atzmaut", "Yom Yerushalayim", "Lag B'Omer", "Shushan Purim Katan", "Isru Chag"]</code>. 365 * 366 * @param transliteratedHolidays the transliteratedHolidays to set. Ensure that the sequence exactly matches the list returned 367 * by the default. 368 */ 369 public void setTransliteratedHolidayList(String[] transliteratedHolidays) { 370 this.transliteratedHolidays = transliteratedHolidays; 371 } 372 373 /** 374 * Hebrew <em>Yomim Tovim</em> (holidays) array in the following format.<br> 375 * <code>‏["ערב פסח", "פסח", "חול המועד פסח", "פסח שני", "ערב שבועות", "שבועות", "שבעה עשר בתמוז", "תשעה באב", "ט״ו באב", "ערב ראש השנה", "ראש השנה", 376 * "צום גדליה", "ערב יום כיפור", "יום כיפור", "ערב סוכות", "סוכות", "חול המועד סוכות", "הושענא רבה", "שמיני עצרת", "שמחת תורה", "ערב חנוכה", "חנוכה", "עשרה בטבת", 377 * "ט״ו בשבט", "תענית אסתר", "פורים", "שושן פורים", "פורים קטן", "ראש חודש", "יום השואה", "יום הזיכרון", "יום העצמאות", "יום ירושלים", "ל״ג בעומר", "שושן פורים קטן"]</code> 378 */ 379 private final String[] hebrewHolidays = { "ערב פסח", "פסח", "חול המועד פסח", "פסח שני", "ערב שבועות", "שבועות", "שבעה עשר בתמוז", 380 "תשעה באב", "ט״ו באב", "ערב ראש השנה", "ראש השנה", "צום גדליה", "ערב יום כיפור", "יום כיפור", "ערב סוכות", "סוכות", "חול המועד סוכות", 381 "הושענא רבה", "שמיני עצרת", "שמחת תורה", "ערב חנוכה", "חנוכה", "עשרה בטבת", "ט״ו בשבט", "תענית אסתר", "פורים", "שושן פורים", 382 "פורים קטן", "ראש חודש", "יום השואה", "יום הזיכרון", "יום העצמאות", "יום ירושלים", "ל״ג בעומר", "שושן פורים קטן", "אסרו חג"}; 383 384 /** The transliterated <em>tekufa</em> names.*/ 385 private final String[] transliteratedTekufaNames = new String[] {"Tishrei", "Teves", "Nissan", "Tammuz"}; 386 387 /** The <em>tekufa</em> names.*/ 388 private final String[] tekufaNames = new String[] {"תשרי", "טבת", "ניסן", "תמוז"}; 389 390 /** 391 * Formats the <em>Yom Tov</em> (holiday) in Hebrew or transliterated Latin characters. 392 * 393 * @param jewishCalendar the JewishCalendar 394 * @return the formatted <em>Yom Tov</em> (holiday) or an empty String if the day is not a <em>Yom Tov</em> (holiday). 395 * @see #isHebrewFormat() 396 */ 397 public String formatYomTov(JewishCalendar jewishCalendar) { 398 int index = jewishCalendar.getYomTovIndex(); 399 if (index == JewishCalendar.CHANUKAH) { 400 int dayOfChanukah = jewishCalendar.getDayOfChanukah(); 401 return hebrewFormat ? (formatHebrewNumber(dayOfChanukah) + " " + hebrewHolidays[index]) 402 : (transliteratedHolidays[index] + " " + dayOfChanukah); 403 } 404 return index == -1 ? "" : hebrewFormat ? hebrewHolidays[index] : transliteratedHolidays[index]; 405 } 406 407 /** 408 * Formats a day as Rosh Chodesh in the format of in the format of ראש חודש שבט or Rosh Chodesh Shevat. If it is not Rosh Chodesh, 409 * an empty <code>String</code> will be returned. 410 * @param jewishCalendar the JewishCalendar 411 * @return The formatted <code>String</code> in the format of ראש חודש שבט or Rosh Chodesh Shevat. If it is not Rosh Chodesh, an 412 * empty <code>String</code> will be returned. 413 */ 414 public String formatRoshChodesh(JewishCalendar jewishCalendar) { 415 if (!jewishCalendar.isRoshChodesh()) { 416 return ""; 417 } 418 int month = jewishCalendar.getJewishMonth(); 419 if (jewishCalendar.getJewishDayOfMonth() == 30) { 420 if (month < JewishCalendar.ADAR || (month == JewishCalendar.ADAR && jewishCalendar.isJewishLeapYear())) { 421 month++; 422 } else { // roll to Nissan 423 month = JewishCalendar.NISSAN; 424 } 425 } 426 427 // This method is only about formatting, so we shouldn't make any changes to the params passed in... 428 jewishCalendar = (JewishCalendar) jewishCalendar.clone(); 429 jewishCalendar.setJewishMonth(month); 430 String formattedRoshChodesh = hebrewFormat ? hebrewHolidays[JewishCalendar.ROSH_CHODESH] 431 : transliteratedHolidays[JewishCalendar.ROSH_CHODESH]; 432 formattedRoshChodesh += " " + formatMonth(jewishCalendar); 433 return formattedRoshChodesh; 434 } 435 436 /** 437 * Returns if the formatter is set to use Hebrew formatting in the various formatting methods. 438 * 439 * @return the hebrewFormat 440 * @see #setHebrewFormat(boolean) 441 * @see #format(JewishDate) 442 * @see #formatDayOfWeek(JewishDate) 443 * @see #formatMonth(JewishDate) 444 * @see #formatOmer(JewishCalendar) 445 * @see #formatYomTov(JewishCalendar) 446 */ 447 public boolean isHebrewFormat() { 448 return hebrewFormat; 449 } 450 451 /** 452 * Sets the formatter to format in Hebrew in the various formatting methods. 453 * 454 * @param hebrewFormat <code>true</code> to format in Hebrew. 455 * @see #isHebrewFormat() 456 * @see #format(JewishDate) 457 * @see #formatDayOfWeek(JewishDate) 458 * @see #formatMonth(JewishDate) 459 * @see #formatOmer(JewishCalendar) 460 * @see #formatYomTov(JewishCalendar) 461 */ 462 public void setHebrewFormat(boolean hebrewFormat) { 463 this.hebrewFormat = hebrewFormat; 464 } 465 466 /** 467 * Returns the Hebrew Omer prefix. By default it is the letter ב producing בעומר, but it can be set to ל to produce לעומר (or any 468 * other prefix) using the {@link #setHebrewOmerPrefix(String)}. 469 * 470 * @return the hebrewOmerPrefix 471 * @see #hebrewOmerPrefix 472 * @see #setHebrewOmerPrefix(String) 473 * @see #formatOmer(JewishCalendar) 474 */ 475 public String getHebrewOmerPrefix() { 476 return hebrewOmerPrefix; 477 } 478 479 /** 480 * Method to set the Hebrew Omer prefix. By default it is the letter ב producing בעומר, but it can be set to ל to format it לעומר 481 * (or any other prefix). 482 * @param hebrewOmerPrefix the hebrewOmerPrefix to set. You can set it to ל to produce to לעומר. 483 * @see #hebrewOmerPrefix 484 * @see #getHebrewOmerPrefix() 485 * @see #formatOmer(JewishCalendar) 486 */ 487 public void setHebrewOmerPrefix(String hebrewOmerPrefix) { 488 this.hebrewOmerPrefix = hebrewOmerPrefix; 489 } 490 491 /** 492 * Returns the Hebrew array of months in the order of<br><code>‏["ניסן", "אייר", "סיון", "תמוז", "אב", "אלול", "תשרי", "חשון", "כסלו", "טבת", "שבט", "אדר", 493 * "אדר ב", "אדר א"]</code>. This list has a length of 14 starting with "ניסן" and ending with 3 variations of Adar - 494 * "אדר", "אדר ב", "אדר א". 495 * @return the array of Hebrew months. 496 * @see #hebrewMonths 497 * @see #setHebrewMonthList(String[]) 498 */ 499 public String[] getHebrewMonthList() { 500 return hebrewMonths; 501 } 502 503 /** 504 * Setter method to allow overriding of the default list of Hebrew month names. This allows changing things such as the default 505 * month name of חשון to מרחשון, etc. This list expects a length of 14 starting with "ניסן" and ending with 3 variations of Adar - 506 * "אדר", "אדר ב", "אדר". 507 * 508 * @param hebrewMonths the array of Hebrew months beginning in "ניסן" and ending in "אדר", "אדר ב", "אדר א" 509 * @see #getHebrewMonthList() 510 */ 511 public void setHebrewMonthList(String[] hebrewMonths) { 512 if(hebrewMonths.length !=14) { 513 throw new IllegalArgumentException("The Hebrew month array must have a length of 14."); 514 } 515 this.hebrewMonths = hebrewMonths; 516 } 517 518 /** 519 * Returns the array of months transliterated into Latin chars. The default list of months uses Ashkenazi pronunciation in 520 * typical American English spelling. This list has a length of 14 with 3 variations for Adar - "Adar", "Adar II", "Adar I". 521 * The array of months beginn in Nissan and end in "Adar", "Adar II", "Adar I". The default list is 522 * <code>["Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Cheshvan", "Kislev", "Teves", "Shevat", "Adar", 523 * "Adar II", "Adar I"]</code>. 524 * 525 * @return the array of 14 month names beginning in Nissan and ending in "Adar", "Adar II", "Adar I". 526 * @see #setTransliteratedMonthList(String[]) 527 */ 528 public String[] getTransliteratedMonthList() { 529 return transliteratedMonths; 530 } 531 532 /** 533 * Setter method to allow overriding of the default list of months transliterated into Latin chars. The default list uses 534 * Ashkenazi American English transliteration. The array of 14 transliterated month names begin in "Nissan" and end in the 535 * 3 Adar variations - "Adar", "Adar II", "Adar I". The default list is 536 * <code>["Nissan", "Iyar", "Sivan", "Tammuz", "Av", "Elul", "Tishrei", "Cheshvan", "Kislev", "Teves", "Shevat", "Adar", 537 * "Adar II", "Adar I"]</code>. 538 * 539 * @param transliteratedMonths the array of 14 month names beginning in Nissan and ending in "Adar", "Adar II", "Adar I". 540 * @see #getTransliteratedMonthList() 541 */ 542 public void setTransliteratedMonthList(String[] transliteratedMonths) { 543 if(transliteratedMonths.length !=14) { 544 throw new IllegalArgumentException("The transliterated month array must have a length of 14."); 545 } 546 this.transliteratedMonths = transliteratedMonths; 547 } 548 549 /** 550 * List of Hebrew months. The list has* a length of 14 starting with "ניסן" and ending with the 3 variations of Adar - 551 * "אדר", "אדר ב", "אדר א". 552 * 553 * @see #getHebrewMonthList() 554 * @see #setHebrewMonthList(String[]) 555 * @see #formatMonth(JewishDate) 556 */ 557 private String[] hebrewMonths = { "ניסן", "אייר", 558 "סיון", "תמוז", "אב", "אלול", 559 "תשרי", "חשון", "כסלו", 560 "טבת", "שבט", "אדר", "אדר ב", 561 "אדר א" }; 562 563 /** 564 * Unicode list of Hebrew days of week in the format of <code>‏["ראשון", "שני", "שלישי", "רביעי", "חמישי", "ששי", "שבת"]</code> 565 */ 566 private static final String[] hebrewDaysOfWeek = { "ראשון", "שני", "שלישי", "רביעי", "חמישי", "ששי", "שבת" }; 567 568 /** 569 * Formats the day of week. If {@link #isHebrewFormat() Hebrew formatting} is set, it will display in the format ראשון etc. If 570 * Hebrew formatting is not in use it will return it in the format of Sunday etc. There are various formatting options that will 571 * affect the output. 572 * 573 * @param jewishDate the JewishDate Object 574 * @return the formatted day of week 575 * @see #isHebrewFormat() 576 * @see #isLongWeekFormat() 577 */ 578 public String formatDayOfWeek(JewishDate jewishDate) { 579 if (hebrewFormat) { 580 if (isLongWeekFormat()) { 581 return hebrewDaysOfWeek[jewishDate.getDayOfWeek() - 1]; 582 } else { 583 if (jewishDate.getDayOfWeek() == 7) { 584 return formatHebrewNumber(300); 585 } else { 586 return formatHebrewNumber(jewishDate.getDayOfWeek()); 587 } 588 } 589 } else { 590 if (jewishDate.getDayOfWeek() == 7) { 591 if (isLongWeekFormat()) { 592 return getTransliteratedShabbosDayOfWeek(); 593 } else { 594 return getTransliteratedShabbosDayOfWeek().substring(0,3); 595 } 596 } else { 597 return weekFormat.format(jewishDate.getLocalDate()); 598 } 599 } 600 } 601 602 /** 603 * Returns whether the class is set to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers. When true and 604 * output would look like כ״א שבט תש״כ (or כ״א שבט תש״ך). When set to false, this output would display as כא שבט תשכ. 605 * 606 * @return true if set to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers. 607 */ 608 public boolean isUseGershGershayim() { 609 return useGershGershayim; 610 } 611 612 /** 613 * Sets whether to use the Geresh ׳ and Gershayim ״ in formatting Hebrew dates and numbers. The default value is true and output 614 * would look like כ״א שבט תש״כ (or כ״א שבט תש״ך). When set to false, this output would display as כא שבט תשכ (or כא שבט תשך). 615 * Single digit days or month or years such as כ׳ שבט ו׳ אלפים show the use of the Geresh. 616 * 617 * @param useGershGershayim set this to false to omit the Geresh ׳ and Gershayim ״ in formatting 618 */ 619 public void setUseGershGershayim(boolean useGershGershayim) { 620 this.useGershGershayim = useGershGershayim; 621 } 622 623 /** 624 * Returns whether the class is set to use the מנצפ״ך letters when formatting years ending in 20, 40, 50, 80 and 90 to produce 625 * תש״פ if false or תש״ף if true. Traditionally non-final form letters are used, so the year 5780 would be formatted as תש״פ if 626 * the default false is used here. If this returns true, the format תש״ף would be used. 627 * 628 * @return true if set to use final form letters when formatting Hebrew years. The default value is false. 629 */ 630 public boolean isUseFinalFormLetters() { 631 return useFinalFormLetters; 632 } 633 634 /** 635 * When formatting a Hebrew Year, traditionally years ending in 20, 40, 50, 80 and 90 are formatted using non-final form letters 636 * for example תש״פ for the year 5780. Setting this to true (the default is false) will use the final form letters for מנצפ״ך and 637 * will format the year 5780 as תש״ף. 638 * 639 * @param useFinalFormLetters Set this to true to use final form letters when formatting Hebrew years. 640 */ 641 public void setUseFinalFormLetters(boolean useFinalFormLetters) { 642 this.useFinalFormLetters = useFinalFormLetters; 643 } 644 645 /** 646 * Returns whether the class is set to use the thousands digit when formatting a Hebrew Year. Traditionally the thousands digit 647 * is omitted and output for a year such as 5729 (1969 Gregorian) would be calculated as 729 and formatted as תשכ״ט. When set to 648 * true the long format year such, as ה׳ תשכ״ט for 5729/1969 is returned. 649 * 650 * @return true if set to use the thousands digit when formatting Hebrew dates and numbers. 651 */ 652 public boolean isUseLongHebrewYears() { 653 return useLonghebrewYears; 654 } 655 656 /** 657 * When formatting a Hebrew Year, traditionally the thousands digit is omitted and output for a year such as 5729 (1969 658 * Gregorian) would be calculated for 729 and format as תשכ״ט. This method allows setting this to true to return the long format 659 * year such as ה׳ תשכ״ט for 5729/1969. 660 * 661 * @param useLongHebrewYears Set this to true to use the long formatting 662 */ 663 public void setUseLongHebrewYears(boolean useLongHebrewYears) { 664 this.useLonghebrewYears = useLongHebrewYears; 665 } 666 /** 667 * Formats the Jewish date. If the formatter is set to Hebrew, it will format in the form, "day Month year" for example 668 * כ״א שבט תשכ״ט, and the format "21 Shevat, 5729" if not. 669 * 670 * @param jewishDate the JewishDate to be formatted 671 * @return the formatted date. If the formatter is set to Hebrew, it will format in the form, "day Month year" as כ״א שבט תשכ״ט, 672 * and "21 Shevat, 5729" if not. 673 */ 674 public String format(JewishDate jewishDate) { 675 if (isHebrewFormat()) { 676 return formatHebrewNumber(jewishDate.getJewishDayOfMonth()) + " " + formatMonth(jewishDate) + " " 677 + formatHebrewNumber(jewishDate.getJewishYear()); 678 } else { 679 return jewishDate.getJewishDayOfMonth() + " " + formatMonth(jewishDate) + ", " + jewishDate.getJewishYear(); 680 } 681 } 682 683 /** 684 * Returns a string of the current Hebrew month formatted as "אדר ב׳" or "Adar II" depending on how {@link #isHebrewFormat()} 685 * is set. 686 * 687 * @param jewishDate the JewishDate to format 688 * @return the formatted month name formatted as "אדר ב׳" or "Adar II" depending on how {@link #isHebrewFormat()} is set. 689 * @see #isHebrewFormat() 690 * @see #setHebrewFormat(boolean) 691 * @see #getTransliteratedMonthList() 692 * @see #setTransliteratedMonthList(String[]) 693 */ 694 public String formatMonth(JewishDate jewishDate) { 695 final int month = jewishDate.getJewishMonth(); 696 if (isHebrewFormat()) { 697 if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR) { 698 return hebrewMonths[JewishDate.ADAR_II] + (useGershGershayim ? GERESH : ""); // return Adar I, not Adar in a leap year 699 } else if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR_II) { 700 return hebrewMonths[JewishDate.ADAR] + (useGershGershayim ? GERESH : ""); 701 } else { 702 return hebrewMonths[month - 1]; 703 } 704 } else { 705 if (jewishDate.isJewishLeapYear() && month == JewishDate.ADAR) { 706 return transliteratedMonths[JewishDate.ADAR_II]; // return Adar I, not Adar in a leap year 707 } else { 708 return transliteratedMonths[month - 1]; 709 } 710 } 711 } 712 713 /** 714 * Returns a String of the Omer day in the form ל״ג בעומר if Hebrew Format is set, or "Omer X" or "Lag B'Omer" if not. An empty 715 * string if there is no Omer this day. 716 * 717 * @param jewishCalendar the JewishCalendar to be formatted 718 * @return a String of the Omer day in the form or an empty string if there is no Omer this day. The default formatting has a 719 * ב prefix that would output בעומר, but this can be set via the {@link #setHebrewOmerPrefix(String)} method to use a ל and 720 * output ל״ג לעומר. 721 * @see #isHebrewFormat() 722 * @see #getHebrewOmerPrefix() 723 * @see #setHebrewOmerPrefix(String) 724 */ 725 public String formatOmer(JewishCalendar jewishCalendar) { 726 int omer = jewishCalendar.getDayOfOmer(); 727 if (omer == -1) { 728 return ""; 729 } 730 if (hebrewFormat) { 731 return formatHebrewNumber(omer) + " " + hebrewOmerPrefix + "עומר"; 732 } else { 733 if (omer == 33) { // if Lag B'Omer 734 return transliteratedHolidays[33]; 735 } else { 736 return "Omer " + omer; 737 } 738 } 739 } 740 741 /** 742 * Returns the kviah in the traditional 3 letter Hebrew format where the first letter represents the day of week of Rosh Hashana, 743 * the second letter represents the lengths of Cheshvan and Kislev ({@link JewishDate#SHELAIMIM Shelaimim} , {@link 744 * JewishDate#KESIDRAN Kesidran} or {@link JewishDate#CHASERIM Chaserim}) and the 3rd letter represents the day of week of Pesach. 745 * For example 5729 (1969) would return בשה (Rosh Hashana on Monday, Shelaimim, and Pesach on Thursday), while 5771 (2011) would 746 * return השג (Rosh Hashana on Thursday, Shelaimim, and Pesach on Tuesday). 747 * 748 * @param jewishYear the Jewish year 749 * @return the Hebrew String such as בשה for 5729 (1969) and השג for 5771 (2011). 750 */ 751 public String getFormattedKviah(int jewishYear) { 752 JewishDate jewishDate = new JewishDate(jewishYear, JewishDate.TISHREI, 1); // set date to Rosh Hashana 753 int kviah = jewishDate.getCheshvanKislevKviah(); 754 int roshHashanaDayOfWeek = jewishDate.getDayOfWeek(); 755 String returnValue = formatHebrewNumber(roshHashanaDayOfWeek); 756 returnValue += (kviah == JewishDate.CHASERIM ? "ח" : kviah == JewishDate.SHELAIMIM ? "ש" : "כ"); 757 jewishDate.setJewishDate(jewishYear, JewishDate.NISSAN, 15); // set to Pesach of the given year 758 int pesachDayOfWeek = jewishDate.getDayOfWeek(); 759 returnValue += formatHebrewNumber(pesachDayOfWeek); 760 returnValue = returnValue.replaceAll(GERESH, "");// geresh is never used in the kviah format 761 // boolean isLeapYear = JewishDate.isJewishLeapYear(jewishYear); 762 // for efficiency we can avoid the expensive recalculation of the pesach day of week by adding 1 day to Rosh 763 // Hashana for a 353-day year, 2 for a 354-day year, 3 for a 355 or 383-day year, 4 for a 384-day year and 5 for 764 // a 385-day year 765 return returnValue; 766 } 767 768 /** 769 * Formats the <a href="https://en.wikipedia.org/wiki/Daf_Yomi">Daf Yomi</a> Bavli in the format of "עירובין נ״ב" if {@link 770 * #isHebrewFormat()} is set to <code>true</code>, or the transliterated format of "Eruvin 52" if set to <code>false</code>. 771 * @param daf the Daf to be formatted. 772 * @return the formatted daf. 773 */ 774 public String formatDafYomiBavli(Daf daf) { 775 if (hebrewFormat) { 776 return daf.getMasechta() + " " + formatHebrewNumber(daf.getDaf()); 777 } else { 778 return daf.getMasechtaTransliterated() + " " + daf.getDaf(); 779 } 780 } 781 782 /** 783 * Formats the <a href="https://en.wikipedia.org/wiki/Jerusalem_Talmud#Daf_Yomi_Yerushalmi">Daf Yomi Yerushalmi</a> in the format 784 * of "עירובין נ״ב" in {@link #isHebrewFormat()} is set to <code>true</code>, or the transliterated format of "Eruvin 52" if set to 785 * <code>false</code>. 786 * 787 * @param daf the Daf to be formatted. 788 * @return the formatted daf. 789 */ 790 public String formatDafYomiYerushalmi(Daf daf) { 791 if (daf == null) { 792 if (hebrewFormat) { 793 return Daf.getYerushalmiMasechtos()[39]; 794 } else { 795 return Daf.getYerushalmiMasechtosTransliterated()[39]; 796 } 797 } 798 if (hebrewFormat) { 799 return daf.getYerushalmiMasechta() + " " + formatHebrewNumber(daf.getDaf()); 800 } else { 801 return daf.getYerushalmiMasechtaTransliterated() + " " + daf.getDaf(); 802 } 803 } 804 805 /** 806 * Returns a Hebrew formatted string of a number. The method can calculate from 0 to 9999. 807 * <ul> 808 * <li>Single digit numbers such as 3, 30 and 100 will be returned with a ׳ (<a 809 * href="http://en.wikipedia.org/wiki/Geresh">Geresh</a>) appended as at the end. For example ג׳, ל׳ and ק׳</li> 810 * <li>multi digit numbers such as 21 and 769 will be returned with a ״ (<a 811 * href="http://en.wikipedia.org/wiki/Gershayim">Gershayim</a>) between the second to last and last letters. For 812 * example כ״א, תשכ״ט</li> 813 * <li>15 and 16 will be returned as ט״ו and ט״ז</li> 814 * <li>Single digit numbers (years assumed) such as 6000 (%1000=0) will be returned as ו׳אלפים</li> 815 * <li>0 will return אפס</li> 816 * </ul> 817 * 818 * @param number the number to be formatted. It will throw an IllegalArgumentException if the number is < 0 or > 9999. 819 * @return the Hebrew formatted number such as תשכ״ט 820 * @see #isUseFinalFormLetters() 821 * @see #isUseGershGershayim() 822 * @see #isHebrewFormat() 823 * 824 */ 825 public String formatHebrewNumber(int number) { 826 if (number < 0) { 827 throw new IllegalArgumentException("negative numbers can't be formatted"); 828 } else if (number > 9999) { 829 throw new IllegalArgumentException("numbers > 9999 can't be formatted"); 830 } 831 832 String ALAFIM = "אלפים"; 833 String EFES = "אפס"; 834 835 String[] jHundreds = new String[] { "", "ק", "ר", "ש", "ת", "תק", "תר", "תש", "תת", "תתק" }; 836 String[] jTens = new String[] { "", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ" }; 837 String[] jTenEnds = new String[] { "", "י", "ך", "ל", "ם", "ן", "ס", "ע", "ף", "ץ" }; 838 String[] tavTaz = new String[] { "טו", "טז" }; 839 String[] jOnes = new String[] { "", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט" }; 840 841 if (number == 0) { // do we really need this? Should it be applicable to a date? 842 return EFES; 843 } 844 int shortNumber = number % 1000; // discard thousands 845 // next check for all possible single Hebrew digit years 846 boolean singleDigitNumber = (shortNumber < 11 || (shortNumber < 100 && shortNumber % 10 == 0) || 847 (shortNumber <= 400 && shortNumber % 100 == 0)); 848 int thousands = number / 1000; // get # thousands 849 StringBuilder sb = new StringBuilder(); 850 // append thousands to String 851 if (number % 1000 == 0) { // in year is 5000, 4000 etc 852 sb.append(jOnes[thousands]); 853 if (isUseGershGershayim()) { 854 sb.append(GERESH); 855 } 856 sb.append(" "); 857 sb.append(ALAFIM); // add # of thousands plus the word "thousand" (override alafim boolean) 858 return sb.toString(); 859 } else if (useLonghebrewYears && number >= 1000) { // if alafim boolean display thousands 860 sb.append(jOnes[thousands]); 861 if (isUseGershGershayim()) { 862 sb.append(GERESH); // append thousands quote 863 } 864 sb.append(" "); 865 } 866 number = number % 1000; // remove 1000s 867 int hundreds = number / 100; // # of hundreds 868 sb.append(jHundreds[hundreds]); // add hundreds to String 869 number = number % 100; // remove 100s 870 if (number == 15) { // special case 15 871 sb.append(tavTaz[0]); 872 } else if (number == 16) { // special case 16 873 sb.append(tavTaz[1]); 874 } else { 875 int tens = number / 10; 876 if (number % 10 == 0) { // if evenly divisible by 10 877 if (!singleDigitNumber) { 878 if (isUseFinalFormLetters()) { 879 sb.append(jTenEnds[tens]); // years like 5780 will end with a final form ף 880 } else { 881 sb.append(jTens[tens]); // years like 5780 will end with a regular פ 882 } 883 } else { 884 sb.append(jTens[tens]); // standard letters so years like 5050 will end with a regular nun 885 } 886 } else { 887 sb.append(jTens[tens]); 888 number = number % 10; 889 sb.append(jOnes[number]); 890 } 891 } 892 if (isUseGershGershayim()) { 893 if (singleDigitNumber) { 894 sb.append(GERESH); // append single quote 895 } else { // append double quote before last digit 896 sb.insert(sb.length() - 1, GERSHAYIM); 897 } 898 } 899 return sb.toString(); 900 } 901 902 /** 903 * Returns the map of transliterated parshiyos used by this formatter. This list using the default <em>Ashkenazi</em> 904 * pronunciation. This list can be overridden (for <em>Sephardi</em> English transliteration for example) by setting the 905 * {@link #setTransliteratedParshiosList(EnumMap)}. The list includes double and special <em>parshiyos</em> in the following 906 * order and spelling "<em>Bereshis, Noach, Lech Lecha, Vayera, Chayei Sara, Toldos, Vayetzei, Vayishlach, Vayeshev, Miketz, 907 * Vayigash, Vayechi, Shemos, Vaera, Bo, Beshalach, Yisro, Mishpatim, Terumah, Tetzaveh, Ki Sisa, Vayakhel, Pekudei, Vayikra, 908 * Tzav, Shmini, Tazria, Metzora, Achrei Mos, Kedoshim, Emor, Behar, Bechukosai, Bamidbar, Nasso, Beha'aloscha, Sh'lach, 909 * Korach, Chukas, Balak, Pinchas, Matos, Masei, Devarim, Vaeschanan, Eikev, Re'eh, Shoftim, Ki Seitzei, Ki Savo, Nitzavim, 910 * Vayeilech, Ha'Azinu, Vezos Habracha, Vayakhel Pekudei, Tazria Metzora, Achrei Mos Kedoshim, Behar Bechukosai, Chukas Balak, 911 * Matos Masei, Nitzavim Vayeilech, Shekalim, Zachor, Parah, Hachodesh,Shuva, Shira, Hagadol, Chazon, Nachamu</em>". 912 * 913 * @return the map of transliterated Parshios 914 * @see #setTransliteratedParshiosList(EnumMap) 915 * @see #formatParsha(JewishCalendar) 916 * @see #formatParsha(JewishCalendar.Parsha) 917 */ 918 public EnumMap<JewishCalendar.Parsha, String> getTransliteratedParshiosList() { 919 return transliteratedParshaMap; 920 } 921 922 /** 923 * Setter method to allow overriding of the default list of parshiyos transliterated into Latin chars. The 924 * default uses Ashkenazi American English transliteration. 925 * 926 * @param transliteratedParshaMap the transliterated Parshios as an EnumMap to set 927 * @see #getTransliteratedParshiosList() for information on the format. 928 */ 929 public void setTransliteratedParshiosList(EnumMap<JewishCalendar.Parsha, String> transliteratedParshaMap) { 930 this.transliteratedParshaMap = transliteratedParshaMap; 931 } 932 933 /** 934 * Returns a String with the name of the current parsha(ios). This method gets the current <em>parsha</em> by calling {@link 935 * JewishCalendar#getParshah()} that does not return a <em>parsha</em> for any non-<em>Shabbos</em> or a <em>Shabbos</em> that 936 * occurs on a <em>Yom Tov</em>, and will return an empty <code>String</code> in those cases. If the class {@link 937 * #isHebrewFormat() is set to format in Hebrew} it will return a <code>String</code> of the current parsha(ios) in Hebrew for 938 * example בראשית or נצבים וילך for a double parsha, or an empty string will be returned if there is not parsha that week. If not set 939 * to Hebrew, it returns a string of the parsha(ios) transliterated into Latin chars. The default uses Ashkenazi pronunciation 940 * in typical American English spelling, for example Bereshis, Nitzavim Vayeilech for a double parsha, An empty string if there 941 * are none. 942 * 943 * @param jewishCalendar the JewishCalendar Object 944 * @return today's parsha(ios) in Hebrew for example, if the formatter is set to format in Hebrew, returns a string of the current 945 * parsha(ios) in Hebrew for example בראשית or נצבים וילך, for a double parsha or an empty <code>String</code> if there is 946 * no parsha that week. If not set to Hebrew, it returns a string of the parsha(ios) transliterated into Latin chars. The 947 * default uses Ashkenazi pronunciation in typical American English spelling, for example Bereshis, Nitzavim Vayeilech for 948 * a double parsha, or an empty <code>String</code> if there are none. 949 * @see #formatParsha(JewishCalendar) 950 * @see #isHebrewFormat() 951 * @see JewishCalendar#getParshah() 952 */ 953 public String formatParsha(JewishCalendar jewishCalendar) { 954 JewishCalendar.Parsha parsha = jewishCalendar.getParshah(); 955 return formatParsha(parsha); 956 } 957 958 /** 959 * Returns a <code>String</code> with the name of the current parsha(ios). This method overloads {@link 960 * #formatParsha(JewishCalendar)} and unlike that method, it will format the <em>parsha</em> passed to this method regardless of 961 * the day of week. This is the way to format a <em>parsha</em> retrieved from calling 962 * {@link JewishCalendar#getUpcomingParshah()}. 963 * 964 * @param parsha a JewishCalendar.Parsha object 965 * @return today's parsha(ios) in Hebrew for example, if the formatter is set to format in Hebrew, returns a <code>String</code> 966 * of the current parsha(ios) in Hebrew for example בראשית or נצבים וילך for a double parsha, or an empty <code>String</code> 967 * if there is no parsha that week. If not set to Hebrew, it returns a string of the parsha(ios) transliterated into 968 * Latin chars. The default uses Ashkenazi pronunciation in typical American English spelling, for example Bereshis, or 969 * Nitzavim Vayeilech for a double parsha, or an empty string if there are none. 970 * @see #formatParsha(JewishCalendar) 971 * @see JewishCalendar#getUpcomingParshah() 972 */ 973 public String formatParsha(JewishCalendar.Parsha parsha) { 974 return hebrewFormat ? hebrewParshaMap.get(parsha) : transliteratedParshaMap.get(parsha); 975 } 976 977 /** 978 * Returns a String with the name of the current special parsha of Shekalim, Zachor, Parah or Hachodesh or an empty String for a 979 * non-special parsha. If the formatter is set to format in Hebrew, it returns a string of the current special parsha in Hebrew, 980 * for example שקלים, זכור, פרה or החדש, or an empty <code>string</code> if the date is not a special parsha. If not set to Hebrew, 981 * it returns a string of the special parsha transliterated into Latin chars. The default uses Ashkenazi pronunciation in typical 982 * American English spelling Shekalim, Zachor, Parah or Hachodesh. 983 * 984 * @param jewishCalendar the JewishCalendar Object 985 * @return today's special parsha. If the formatter is set to format in Hebrew, returns a string of the current special parsha in 986 * Hebrew for in the format of שקלים, זכור, פרה or החדש or an empty string if there are none. If not set to Hebrew, it 987 * returns a string of the special parsha transliterated into Latin chars. The default uses Ashkenazi pronunciation in 988 * typical American English spelling of Shekalim, Zachor, Parah or Hachodesh. An empty string if there are none. 989 */ 990 public String formatSpecialParsha(JewishCalendar jewishCalendar) { 991 JewishCalendar.Parsha specialParsha = jewishCalendar.getSpecialShabbos(); 992 return hebrewFormat ? hebrewParshaMap.get(specialParsha) : transliteratedParshaMap.get(specialParsha); 993 } 994 995 /** 996 * Returns a the formatted <em>tekufa</em> name if it is the day of the <em>tekufa</em> event, or an empty {@code String} if it 997 * is not. 998 * @param jewishCalendar the {@code JewishCalendar} to format the <em>tekufa</em> name for. 999 * @return a {@code String} with the name of the upcoming tekufa/season, in the format of "תקופת תשרי" if {@link #isHebrewFormat()} 1000 * is set to {@code true}, or "Tekufas Tishrei" if set to {@code false} or an empty string on a day without a 1001 * <em>tekufa</em> event. 1002 */ 1003 public String formatTekufaName(JewishCalendar jewishCalendar) { 1004 double INITIAL_TEKUFA_OFFSET = 12.625; // the number of days Tekufas Tishrei occurs before JEWISH_EPOCH 1005 double days = JewishDate.getJewishCalendarElapsedDays(jewishCalendar.getJewishYear()) + jewishCalendar.getDaysSinceStartOfJewishYear() + INITIAL_TEKUFA_OFFSET - 1; // total days since first Tekufas Tishrei event 1006 1007 double solarDaysElapsed = days % 365.25; // total days elapsed since start of solar year 1008 int currentTekufaNumber = (int) (solarDaysElapsed / 91.3125); // the current quarter of the solar year 1009 double tekufaDaysElapsed = solarDaysElapsed % 91.3125; // the number of days that have passed since a tekufa event 1010 if (tekufaDaysElapsed > 0 && tekufaDaysElapsed <= 1) { // if the tekufa happens in the upcoming 24 hours 1011 return isHebrewFormat() ? "תקופת " + tekufaNames[currentTekufaNumber] : "Tekufas " + transliteratedTekufaNames[currentTekufaNumber];//0 for Tishrei, 1 for Tevet, 2, for Nissan, 3 for Tammuz 1012 } else { 1013 return ""; 1014 } 1015 } 1016}