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 tekufa methods #226

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 @@ -1601,6 +1601,84 @@ public boolean isIsruChag() {
return holidayIndex == ISRU_CHAG;
}

/**
* Returns a <code>Double</code> that represents the hours for when the Tekufa (season) changes. There are 4 tekufas
* a year: Nissan/Spring, Tammuz/Summer, Tishri/Fall, and Tevet/Winter. This is calculation is according to Shmuel
* in Eruvin 56a, which is a more rounded up version of Rav Adda's calculation. The Rama writes in Yoreh De'ah 116:5
* writes that one should not dring water during the tekufa change.
*
* @return the number of hours into the hebrew day that the tekufa (season) change takes place, or null if the
* tekufa does not occur on current day. For example: 19.5 would mean that the tekufa occurs 19 hours and a half into
* the hebrew date, or 13 and a half hours (-6 hours) into the gregorian date.
*/
public Double getTekufa() {
double INITIAL_TEKUFA_OFFSET = 12.625; // the number of days Tekufas Tishrei occurs before JEWISH_EPOCH

double days = getJewishCalendarElapsedDays(getJewishYear()) + getDaysSinceStartOfJewishYear() + INITIAL_TEKUFA_OFFSET - 1; // total days since first Tekufas Tishrei event

double solarDaysElapsed = days % 365.25; // total days elapsed since start of solar year
double tekufaDaysElapsed = solarDaysElapsed % 91.3125; // the number of days that have passed since a tekufa event
if (tekufaDaysElapsed > 0 && tekufaDaysElapsed <= 1) { // if the tekufa happens in the upcoming 24 hours
return ((1.0 - tekufaDaysElapsed) * 24.0) % 24;// rationalize the tekufa event to number of hours since start of jewish day
} else {
return null;
}
}

/**
* Returns the name of the upcoming tekufa/season.
* @return the name of the upcoming tekufa/season, which could be: "Tishrei", "Teves", "Nissan", "Tammuz"
*/
public String getTekufaName() {
String[] tekufaNames = new String[]{"Tishrei", "Teves", "Nissan", "Tammuz"};

double INITIAL_TEKUFA_OFFSET = 12.625; // the number of days Tekufas Tishrei occurs before JEWISH_EPOCH
double days = getJewishCalendarElapsedDays(getJewishYear()) + getDaysSinceStartOfJewishYear() + INITIAL_TEKUFA_OFFSET - 1; // total days since first Tekufas Tishrei event

double solarDaysElapsed = days % 365.25; // total days elapsed since start of solar year
int currentTekufaNumber = (int) (solarDaysElapsed / 91.3125); // the current quarter of the solar year
double tekufaDaysElapsed = solarDaysElapsed % 91.3125; // the number of days that have passed since a tekufa event
if (tekufaDaysElapsed > 0 && tekufaDaysElapsed <= 1) { // if the tekufa happens in the upcoming 24 hours
return tekufaNames[currentTekufaNumber];//0 for Tishrei, 1 for Tevet, 2, for Nissan, 3 for Tammuz
} else {
return "";
}
}

/**
* Returns a Date if the current day has a tekufa (season) change. The Date will contain the time that the tekufa (season)
* is arriving. If this method is called on a day without a tekufa change, it will return a null.
* The default implementation of this method will return the Tekufa change according to the calculations of Rabbi
* Tulchinsky in his calendar <a href="https://zmanim.online/">Luach Itim
* Lebinah</a>. However, there is also the opinion of Rabbi Yonah Mertzbach, who says to calculate
* the tekufa based on local midday in Israel which causes a 21-minute difference. There is a third opinion as well
* to use seasonal midday but that is not a generally accepted opinion, so it has not been included.
* @param shouldMinus21Minutes if true, removes 21 minutes from the time of Rabbi Tulchinsky's tekufa which is the
* opinion of Rabbi Yonah Mertzbach.
* @return a Date with the time that the tekufa (season) changes or a null on a day with no tekufa change
*/
public Date getTekufaAsDate(boolean shouldMinus21Minutes) {
// The tekufa Date (point in time) must be generated using standard time. Using "Asia/Jerusalem" timezone will result in the time
// being incorrectly off by an hour in the summer due to DST. Proper adjustment for the actual time in DST will be done by the date
// formatter class used to display the Date.
TimeZone yerushalayimStandardTZ = TimeZone.getTimeZone("GMT+2");
Calendar cal = Calendar.getInstance(yerushalayimStandardTZ);
cal.clear();
if (getTekufa() == null) {
return null;
}
double hours = getTekufa() - 6; // minus 6 hours because the hebrew date starts at sunset which is at 6PM
int minutes = (int) ((hours - (int) hours) * 60);
if (shouldMinus21Minutes) {
minutes -= 21; //minus 21 minutes to get to local midday
}
cal.set(getGregorianYear(), getGregorianMonth(), getGregorianDayOfMonth(), 0, 0, 0);
cal.add(Calendar.HOUR_OF_DAY, (int) hours);
cal.add(Calendar.MINUTE, minutes);

return cal.getTime();
}

/**
* Indicates whether some other object is "equal to" this one.
* @see Object#equals(Object)
Expand Down
Loading