int KCalendarSystemHebrew::hndays(int mon, int year) const { if ( mon == 6 && is_leap_year(year) ) mon = 13; /*Adar I*/ else if ( mon == 7 && is_leap_year(year) ) mon = 14; /*Adar II*/ else if ( mon > 7 && is_leap_year(year) ) mon--; //Because of Adar II if( mon == 8 /*IYYAR*/ || mon == 10 /*TAMUZ*/ || mon == 12 /*ELUL*/ || mon == 4 /*TEVET*/ || mon == 14 /*ADAR 2*/|| ( mon == 6 /*ADAR*/ && !is_leap_year(year)) || (mon == 2 /*CHESHVAN*/ && !long_cheshvan(year)) || (mon == 3 /*KISLEV*/ && short_kislev(year))) return 29; else return 30; }
void init_yahrtzeits( int hyear ) { holstorep_t tmpholp; char *s, *monthStr, *eventStr, nextChar; int index, inMonth, inDay, inYear, lineNum = 1; date_t hDeath, gDeath; initStr (&s, MAX_LINE_LEN); initStr (&monthStr, MAX_LINE_LEN); rewind (yFile); nextChar = (char) getc (yFile); /* priming getc */ for (; !feof (yFile); lineNum++, nextChar = (char) getc (yFile)) { /* force an EOF */ ungetc (nextChar, yFile); if (!fgets (s, MAX_LINE_LEN, yFile)) { warn ("yahrtzeit file read error. Skipping line %s", hc_itoa (lineNum)); continue; } if (s[0] == '\n') /* blank line */ continue; if (sscanf (s, "%s %d %d%n", monthStr, &inDay, &inYear, &index) < 3) { warn ("Error in yahrtzeit file. Skipping line %s", hc_itoa (lineNum)); continue; } if (!isAllNums (monthStr)) { warn ("Non-numeric month in yahrtzeit file. Skipping line %s", hc_itoa (lineNum)); continue; } sscanf (monthStr, "%d", &inMonth); if (inMonth > 12 || inMonth < 1 || inDay < 1 || inDay > MonthLengths[LEAP (inYear)][inMonth]) { warn ("Date out of range in yahrtzeit file. Skipping line %s", hc_itoa (lineNum)); continue; } gDeath.dd = inDay; gDeath.mm = inMonth; gDeath.yy = inYear; hDeath = abs2hebrew (greg2abs (gDeath)); /* If it's Heshvan 30 it depends on the first anniversary; if that was not Heshvan 30, use the day before Kislev 1. */ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !long_cheshvan (hDeath.yy + 1)) { hDeath.dd = 1; hDeath.mm = KISLEV; hDeath.yy = hyear; hDeath = abs2hebrew (hebrew2abs (hDeath) - 1L); } /* If it's Kislev 30 it depends on the first anniversary; if that was not Kislev 30, use the day before Teveth 1. */ else if (hDeath.mm == KISLEV && hDeath.dd == 30 && !short_kislev (hDeath.yy + 1)) { hDeath.dd = 1; hDeath.mm = TEVET; hDeath.yy = hyear; hDeath = abs2hebrew (hebrew2abs (hDeath) - 1L); } /* If it's Adar II, use the same day in last month of year (Adar or Adar II). */ else if (hDeath.mm == ADAR_II) { hDeath.mm = MONTHS_IN_HEB (hyear); } /* If it's the 30th in Adar I and year is not a leap year (so Adar has only 29 days), use the last day in Shevat. */ else if (hDeath.mm == ADAR_I && hDeath.dd == 30 && !LEAP_YR_HEB (hyear)) { hDeath.dd = 30; hDeath.mm = SHVAT; } /* In all other cases, use the normal anniversary of the date of death. */ /* advance day to rosh chodesh if needed */ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !long_cheshvan(hyear)) { hDeath.mm = KISLEV; hDeath.dd = 1; } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && short_kislev(hyear)) { hDeath.mm = TEVET; hDeath.dd = 1; } eventStr = s + index + 1; /* get the name of the event */ /* if (eventStr[strlen(eventStr)-1] == '\n') */ eventStr[strlen (eventStr) - 1] = '\0'; /* chop off the \n */ /* store the holiday in the LUT */ tmpholp = getHolstorep (); initStr (&tmpholp->name, MAX_LINE_LEN); strcpy (tmpholp->name, eventStr); /* load the user holiday into it. */ tmpholp->typeMask = USER_EVENT; PushHoliday (tmpholp, &var_holidays[hDeath.mm][hDeath.dd]); } }
/* sets static globals based on this year. */ void reset_sedra( int hebYr ) /* the hebrew year */ { date_t tempDt; int long_c, short_k, rosh_hashana_day, type; long int rosh_hashana; size_t theSedraArraySize; long_c = long_cheshvan (hebYr); short_k = short_kislev (hebYr); if (long_c && !short_k) type = COMPLETE; else if (!long_c && short_k) type = INCOMPLETE; else type = REGULAR; tempDt.dd = 1; tempDt.mm = TISHREI; tempDt.yy = hebYr; rosh_hashana = hebrew2abs (tempDt); rosh_hashana_day = (int) (rosh_hashana % 7L); /* find the first saturday on or after Rosh Hashana */ first_saturday = day_on_or_before (6, rosh_hashana + 6L); if (!LEAP_YR_HEB(hebYr)) { switch (rosh_hashana_day) { case SAT: if (type == INCOMPLETE) { theSedraArray = Sat_short; theSedraArraySize = sizeof(Sat_short); } else if (type == COMPLETE) { theSedraArray = Sat_long; theSedraArraySize = sizeof(Sat_long); } break; case MON: if (type == INCOMPLETE) { theSedraArray = Mon_short; theSedraArraySize = sizeof(Mon_short); } else if (type == COMPLETE) { theSedraArray = israel_sw ? Mon_short : Mon_long; theSedraArraySize = israel_sw ? sizeof(Mon_short) : sizeof(Mon_long); } break; case TUE: if (type == REGULAR) { theSedraArray = israel_sw ? Mon_short : Mon_long; theSedraArraySize = israel_sw ? sizeof(Mon_short) : sizeof(Mon_long); } break; case THU: if (type == REGULAR) { theSedraArray = israel_sw ? Thu_normal_Israel : Thu_normal; theSedraArraySize = israel_sw ? sizeof(Thu_normal_Israel) : sizeof(Thu_normal); } else if (type == COMPLETE) { theSedraArray = Thu_long; theSedraArraySize = sizeof(Thu_long); } break; default: die ("improper sedra year type calculated.", ""); } } else { /* leap year */ switch (rosh_hashana_day) { case SAT: if (type == INCOMPLETE) { theSedraArray = Sat_short_leap; theSedraArraySize = sizeof(Sat_short_leap); } else if (type == COMPLETE) { theSedraArray = israel_sw ? Sat_short_leap : Sat_long_leap; theSedraArraySize = israel_sw ? sizeof(Sat_short_leap) : sizeof(Sat_long_leap); } break; case MON: if (type == INCOMPLETE) { theSedraArray = israel_sw ? Mon_short_leap_Israel : Mon_short_leap; theSedraArraySize = israel_sw ? sizeof(Mon_short_leap_Israel) : sizeof(Mon_short_leap); } else if (type == COMPLETE) { theSedraArray = israel_sw ? Mon_long_leap_Israel : Mon_long_leap; theSedraArraySize = israel_sw ? sizeof(Mon_long_leap_Israel) : sizeof(Mon_long_leap); } break; case TUE: if (type == REGULAR) { theSedraArray = israel_sw ? Mon_long_leap_Israel : Mon_long_leap; theSedraArraySize = israel_sw ? sizeof(Mon_long_leap_Israel) : sizeof(Mon_long_leap); } break; case THU: if (type == INCOMPLETE) { theSedraArray = Thu_short_leap; theSedraArraySize = sizeof(Thu_short_leap); } else if (type == COMPLETE) { theSedraArray = Thu_long_leap; theSedraArraySize = sizeof(Thu_long_leap); } break; default: die ("improper sedra year type calculated.", ""); } } sedraNumWeeks = theSedraArraySize / sizeof(int); }
static void load_variable_holidays( int hYear ) { date_t tempDt; long int roshHashana, passover, tishaBav, tevet10; holstorep_t tmpholp; tempDt.yy = hYear; tempDt.mm = TISHREI; tempDt.dd = 1; roshHashana = hebrew2abs (tempDt); tempDt.yy = hYear; tempDt.mm = TEVET; tempDt.dd = 10; tevet10 = hebrew2abs (tempDt); tempDt.mm = NISAN; tempDt.dd = 15; passover = hebrew2abs (tempDt); tempDt.mm = AV; tempDt.dd = 9; tishaBav = hebrew2abs (tempDt); tmpholp = getHolstorep (); /* allocate hsnode */ tmpholp->name = HOLIDAY_TZOM_GEDALIAH; PushHoliday (tmpholp, &var_holidays[TISHREI] [roshHashana % 7L == THU ? 4 : 3]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_SHUVA; tempDt = abs2hebrew (day_on_or_before (SAT, 7L + roshHashana)); PushHoliday (tmpholp, &var_holidays[TISHREI][tempDt.dd]); /* printf( "hyear is %d\n",hYear); */ if (short_kislev (hYear)) { tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_CHANUKAH_7_CANDLES; tmpholp->typeMask = CHANUKAH_CANDLES; PushHoliday (tmpholp, &var_holidays[TEVET][1]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_CHANUKAH_8_CANDLES; tmpholp->typeMask = CHANUKAH_CANDLES; PushHoliday (tmpholp, &var_holidays[TEVET][2]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_CHANUKAH_8TH_DAY; PushHoliday (tmpholp, &var_holidays[TEVET][3]); } else { tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_CHANUKAH_7_CANDLES; tmpholp->typeMask = CHANUKAH_CANDLES; PushHoliday (tmpholp, &var_holidays[KISLEV][30]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_CHANUKAH_8_CANDLES; tmpholp->typeMask = CHANUKAH_CANDLES; PushHoliday (tmpholp, &var_holidays[TEVET][1]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_CHANUKAH_8TH_DAY; PushHoliday (tmpholp, &var_holidays[TEVET][2]); } tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_SHEKALIM; tempDt = abs2hebrew (day_on_or_before (SAT, passover - 43L)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_ZACHOR; tempDt = abs2hebrew (day_on_or_before (SAT, passover - 30L)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_TA_ANIT_ESTHER; tempDt = abs2hebrew (passover - (passover % 7L == TUE ? 33L : 31)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); if (LEAP_YR_HEB (hYear)) { tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_PURIM_KATAN; PushHoliday (tmpholp, &var_holidays[ADAR_I][14]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_EREV_PURIM; PushHoliday (tmpholp, &var_holidays[ADAR_II][13]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_PURIM; PushHoliday (tmpholp, &var_holidays[ADAR_II][14]); } else { tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_EREV_PURIM; PushHoliday (tmpholp, &var_holidays[ADAR_I][13]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_PURIM; PushHoliday (tmpholp, &var_holidays[ADAR_I][14]); } tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHUSHAN_PURIM; tempDt = abs2hebrew (passover - (passover % 7L == SUN ? 28L : 29)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_PARAH; tempDt = abs2hebrew (day_on_or_before (SAT, passover - 14L) - 7L); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_HACHODESH; tempDt = abs2hebrew (day_on_or_before (SAT, passover - 14L)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_TA_ANIT_BECHOROT; if ((passover - 1L) % 7L == SAT) { /* if the fast falls on Shabbat, move to Thursday */ tempDt = abs2hebrew (day_on_or_before (THU, passover)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); } else PushHoliday (tmpholp, &var_holidays[NISAN][14]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_HAGADOL; tempDt = abs2hebrew (day_on_or_before (SAT, passover - 1L)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); if (hYear >= 5711) { /* Yom HaShoah first observed in 1951 */ long int nisan27; int nisan_day = 27; tempDt.mm = NISAN; tempDt.dd = 27; nisan27 = hebrew2abs (tempDt); /* When the actual date of Yom Hashoah falls on a Friday, the * state of Israel observes Yom Hashoah on the preceding * Thursday. When it falls on a Sunday, Yom Hashoah is observed * on the following Monday. * http://www.ushmm.org/remembrance/dor/calendar/ */ if (nisan27 % 7L == FRI) nisan_day = 26; else if (nisan27 % 7L == SUN) nisan_day = 28; tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_YOM_HASHOAH; PushHoliday (tmpholp, &var_holidays[NISAN][nisan_day]); } if (hYear > 5708) { /* only really makes sense after 1948 */ tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_YOM_HAZIKARON; if (passover % 7L == SUN) tempDt.dd = 3; else if (passover % 7L == SAT) tempDt.dd = 4; else if( hYear < 5764 ) tempDt.dd = 5; else if( passover % 7L == TUE ) /* no Yom Hazikaron on motzei shabbat allowed after 5764*/ tempDt.dd = 6; else tempDt.dd = 5; PushHoliday (tmpholp, &var_holidays[IYYAR][tempDt.dd - 1]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_YOM_HAATZMA_UT; PushHoliday (tmpholp, &var_holidays[IYYAR][tempDt.dd]); } if (hYear > 5727) { /* only really makes sense after 1967 */ tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_YOM_YERUSHALAYIM; PushHoliday (tmpholp, &var_holidays[IYYAR][28]); } if (hYear >= 5769) { tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SIGD; PushHoliday (tmpholp, &var_holidays[CHESHVAN][29]); } tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_TZOM_TAMMUZ; if (tishaBav % 7L == SAT) tempDt = abs2hebrew (tishaBav - 20L); else tempDt = abs2hebrew (tishaBav - 21L); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_CHAZON; tempDt = abs2hebrew (day_on_or_before (SAT, tishaBav)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_EREV_TISH_A_B_AV; PushHoliday (tmpholp, &var_holidays[AV] [tishaBav % 7L == SAT ? 9 : 8]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_TISH_A_B_AV; PushHoliday (tmpholp, &var_holidays[AV] [tishaBav % 7L == SAT ? 10 : 9]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_SHABBAT_NACHAMU; tempDt = abs2hebrew (day_on_or_before (SAT, tishaBav + 7L)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_ASARA_B_TEVET; if (tevet10 % 7L == SAT) PushHoliday (tmpholp, &var_holidays[TEVET][11]); else PushHoliday (tmpholp, &var_holidays[TEVET][10]); tempDt.mm = TISHREI; tempDt.dd = 1; tempDt.yy = hYear + 1; tmpholp = getHolstorep (); tmpholp->name = HOLIDAY_LEIL_SELICHOT; tempDt = abs2hebrew (day_on_or_before (SAT, hebrew2abs (tempDt) - 4L)); PushHoliday (tmpholp, &var_holidays[tempDt.mm][tempDt.dd]); }