Skip to content

Commit

Permalink
Add getUpcomingParshah()
Browse files Browse the repository at this point in the history
This returns a value even during the week. Closes #191.
  • Loading branch information
KosherJava authored Nov 21, 2022
1 parent 35eef61 commit 52e49a8
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public class JewishCalendar extends JewishDate {
public static final int YOM_KIPPUR_KATAN = 36;

/**
* The Monday, Thursday and Monday after the first <em>Shabbos</em> after <em>Rosh Chodesh Cheshvan</em> and <em>Iyar</em>em>) are BeHab
* The Monday, Thursday and Monday after the first <em>Shabbos</em> after <em>Rosh Chodesh Cheshvan</em> and <em>Iyar</em>) are BeHab
* days. This constant is not actively in use.
* @see #isBeHaB()
*/
Expand Down Expand Up @@ -472,6 +472,29 @@ public Parsha getParshah() {
}
return Parsha.NONE; //keep the compiler happy
}

/**
* Returns the upcoming {@link Parsha <em>Parsha</em>} regardless of if it is the weekday or <em>Shabbos</em> (where next
* Shabbos's <em>Parsha</em> will be returned. This is unlike {@link #getParshah()} that returns {@link Parsha#NONE} if
* the date is not <em>Shabbos</em>. If the upcoming Shabbos is a <em>Yom Tov</em> and has no <em>Parsha</em>, the
* following week's <em>Parsha</em> will be returned.
*
* @return the upcoming <em>parsha</em>.
*/
public Parsha getUpcomingParshah() {
JewishCalendar clone = (JewishCalendar) clone();
int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek() + 7) % 7;
if (getDayOfWeek() != Calendar.SATURDAY) {
clone.forward(Calendar.DATE, daysToShabbos);
} else {
clone.forward(Calendar.DATE, 7);
}
while(clone.getParshah() == Parsha.NONE) { //Yom Kippur / Sukkos or Pesach with 2 potential non-parsha Shabbosim in a row
clone.forward(Calendar.DATE, 7);
}
return clone.getParshah();
}


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

0 comments on commit 52e49a8

Please sign in to comment.