Skip to content

Commit 52e49a8

Browse files
authored
Add getUpcomingParshah()
This returns a value even during the week. Closes #191.
1 parent 35eef61 commit 52e49a8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishCalendar.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public class JewishCalendar extends JewishDate {
142142
public static final int YOM_KIPPUR_KATAN = 36;
143143

144144
/**
145-
* The Monday, Thursday and Monday after the first <em>Shabbos</em> after <em>Rosh Chodesh Cheshvan</em> and <em>Iyar</em>em>) are BeHab
145+
* The Monday, Thursday and Monday after the first <em>Shabbos</em> after <em>Rosh Chodesh Cheshvan</em> and <em>Iyar</em>) are BeHab
146146
* days. This constant is not actively in use.
147147
* @see #isBeHaB()
148148
*/
@@ -472,6 +472,29 @@ public Parsha getParshah() {
472472
}
473473
return Parsha.NONE; //keep the compiler happy
474474
}
475+
476+
/**
477+
* Returns the upcoming {@link Parsha <em>Parsha</em>} regardless of if it is the weekday or <em>Shabbos</em> (where next
478+
* Shabbos's <em>Parsha</em> will be returned. This is unlike {@link #getParshah()} that returns {@link Parsha#NONE} if
479+
* the date is not <em>Shabbos</em>. If the upcoming Shabbos is a <em>Yom Tov</em> and has no <em>Parsha</em>, the
480+
* following week's <em>Parsha</em> will be returned.
481+
*
482+
* @return the upcoming <em>parsha</em>.
483+
*/
484+
public Parsha getUpcomingParshah() {
485+
JewishCalendar clone = (JewishCalendar) clone();
486+
int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek() + 7) % 7;
487+
if (getDayOfWeek() != Calendar.SATURDAY) {
488+
clone.forward(Calendar.DATE, daysToShabbos);
489+
} else {
490+
clone.forward(Calendar.DATE, 7);
491+
}
492+
while(clone.getParshah() == Parsha.NONE) { //Yom Kippur / Sukkos or Pesach with 2 potential non-parsha Shabbosim in a row
493+
clone.forward(Calendar.DATE, 7);
494+
}
495+
return clone.getParshah();
496+
}
497+
475498

476499
/**
477500
* Returns a {@link Parsha <em>Parsha</em>} enum if the <em>Shabbos</em> is one of the four <em>parshiyos</em> of {@link

0 commit comments

Comments
 (0)