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

Why is getParsha defined only on shabbos/saturday #191

Closed
srulih opened this issue Nov 20, 2022 · 11 comments
Closed

Why is getParsha defined only on shabbos/saturday #191

srulih opened this issue Nov 20, 2022 · 11 comments

Comments

@srulih
Copy link

srulih commented Nov 20, 2022

getParsha() defined here returns Parsha.NONE if the day is not Saturday. However, the parsha of the week is defined for any week by the parsha that is going to be read on that shabbos. So why don't we add logic to getParsha() to return the parsha that is due to be read on the upcoming Saturday

@KosherJava
Copy link
Owner

@srulih ,
Thanks for your report. This was done by design, and the documentation is clear about it. I am open to change it (I get contacted about this from time to time). The design for this was for a luach, and in almost all cases returning a parsha during the week would force the developer to code to exclude the parsha display if it was not Shabbos. Please note that the current code will NOT work as expected if you comment out the https://github.com/KosherJava/zmanim/blob/master/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishCalendar.java#L463 line. I am open to a PR to change the current behavior.

@zachweix
Copy link

You can always just do a look-ahead to see what is this coming shabbos's parsha

@KosherJava
Copy link
Owner

@zachweix , that is true, but comes with a small performance hit.
@srulih , what would be your expectation when the next Shabbos (or 2) are Yomim Tovim. Would you expect it to show the parsha of the next regular parsha for a few weeks? It would help to know your use case. Is it just for Shabbos Mincha, sheni vachamishi laining, or do you have something else in mind?

@srulih
Copy link
Author

srulih commented Nov 21, 2022 via email

@KosherJava
Copy link
Owner

@srulih , I understand what you want, but I am trying to understand the point (I am sure that you have a good reason, but I am curious). About my other question, if you are between YK and Sukkos and want the parsha, when the next one or 2 weeks may have no parsha, would you expect it to return Bereishis that will occur in a few weeks, or NONE? The same can happen by Pesach.

@KosherJava
Copy link
Owner

@srulih and @zachweix , assuming we build a getUpcomingParsha(), if you call it when the date is set to Shabbos, would you expect it to return the parsha of the current parsha, or the following one?

@zachweix
Copy link

That's an interesting question. I like to show the parsha every day on a calendar, so that if you're looking on Wednesday you know that shabbos is Toldos (for example) and on shabbos you know it's toldos. But in theory I can first check the parsha and then only if that fails get the upcoming parsha.

@srulih
Copy link
Author

srulih commented Nov 21, 2022 via email

@KosherJava
Copy link
Owner

Yes it implies that, but it also forces the person using the API to check the day of week. In any case, @zachweix and @srulih ,
How does this look?

public Parsha getUpcomingParshah() {
    JewishCalendar clone = (JewishCalendar) clone();
    int daysToShabbos = ((int) Calendar.SATURDAY - getDayOfWeek()  + 7) % 7;
    clone.forward(Calendar.DATE, daysTohabbos);
    while(clone.getParshah() == Parsha.NONE) {
        clone.forward(Calendar.DATE, 7);
    }
    return clone.getParshah();
}

@zachweix
Copy link

Interesting, this way when Pesach starts on shabbos for example, then the 9th of nissan will return the parsha on the 29th.

@KosherJava
Copy link
Owner

Slightly tweaked to guard against an error when it is Shabbos

/**
 * 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 e return. 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();
}

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants