Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add two methods to check for this week's parasha #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,38 @@ public Parsha getParshah() {
}
return Parsha.NONE; //keep the compiler happy
}

/**
* Returns this week's {@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. If the upcoming <em>Shabbos</em> is a <em>Yom Tov</em> and has no <em>Parsha</em>,
* {@link Parsha#NONE} will be returned.
*
* @return the upcoming <em>parsha</em>.
*/
public Parsha getThisWeeksParshah() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Elyahu41 , the name needs more clarity (I think). getUpcomingParsha is very similar, with the only difference being that this will return null if it is YT. We probably want to overrride getUcomomingParsha() with a boolean to control this, and we can deprecate the one without a parameter for removal in 3.0.

Copy link
Contributor Author

@Elyahu41 Elyahu41 Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. How about something like this:

	public Parsha getUpcomingParshah(boolean thisWeek) {
		JewishCalendar clone = (JewishCalendar) clone();
		int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek() + 7) % 7;
		if (getDayOfWeek() != Calendar.SATURDAY) {
			clone.forward(Calendar.DATE, daysToShabbos);
                if (thisWeek) {
                return clone.getParshah();
                }
		} 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();
	}

JewishCalendar clone = (JewishCalendar) clone();
int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek() + 7) % 7;
if (getDayOfWeek() != Calendar.SATURDAY) {
clone.forward(Calendar.DATE, daysToShabbos);
}
return clone.getParshah();
}

/**
* Returns this week's {@link #getSpecialShabbos() special shabbos} regardless of if it is the weekday or <em>Shabbos</em> (where next
* Shabbos's <em>Parsha</em> will be returned. If the upcoming <em>Shabbos</em> is a <em>Yom Tov</em> and has no <em>Parsha</em>
* or special shabbos, {@link Parsha#NONE} will be returned.
*
* @return the upcoming <em>parsha</em>.
*/
public Parsha getThisWeeksSpecialParshah() {
JewishCalendar clone = (JewishCalendar) clone();
int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek() + 7) % 7;
if (getDayOfWeek() != Calendar.SATURDAY) {
clone.forward(Calendar.DATE, daysToShabbos);
}
return clone.getSpecialShabbos();
}

/**
* Returns the upcoming {@link Parsha <em>Parsha</em>} regardless of if it is the weekday or <em>Shabbos</em> (where next
Expand All @@ -517,7 +549,7 @@ public Parsha getParshah() {
*/
public Parsha getUpcomingParshah() {
JewishCalendar clone = (JewishCalendar) clone();
int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek() + 7) % 7;
int daysToShabbos = (Calendar.SATURDAY - getDayOfWeek() + 7) % 7;
if (getDayOfWeek() != Calendar.SATURDAY) {
clone.forward(Calendar.DATE, daysToShabbos);
} else {
Expand Down
Loading