void print_sunrise_sunset(date_t todayGreg) { double gmt_offset; double h_rise, h_set, N_rise, N_set; int rise_hour, rise_minute, set_hour, set_minute; get_rise_set(todayGreg, &h_rise, &h_set, &gmt_offset); N_rise = h_rise + gmt_offset; N_set = h_set + gmt_offset; if (N_rise > 24 || N_rise < 0) { N_rise -= floor(N_rise / 24) * 24; } rise_hour = (int) N_rise; if (rise_hour > 12 && !twentyFourHour_sw) { rise_hour = rise_hour % 12; } rise_minute = (int) (60 * (N_rise - (int) N_rise)); /* ugly: repeat for sunset */ if (N_set > 24 || N_set < 0) { N_set -= floor(N_set / 24) * 24; } set_hour = (int) N_set; if (set_hour > 12 && !twentyFourHour_sw) { set_hour = set_hour % 12; } set_minute = (int) (60 * (N_set - (int) N_set)); PrintGregDate (todayGreg); printf ("%s:%2d:%02d; %s:%2d:%02d\n", "Sunrise", rise_hour, rise_minute, "Sunset", set_hour, set_minute ); }
void hebcal_dafyomi( date_t *greg_day ) { int dafcnt = 40; int cno, dno, osday, nsday, total, count, j, cday, blatt; date_t tmp_date; char buffer[NM_LEN]; tmp_date.mm = 9; tmp_date.dd = 11; tmp_date.yy = 1923; osday = greg2abs(tmp_date); tmp_date.mm = 6; tmp_date.dd = 24; tmp_date.yy = 1975; nsday = greg2abs(tmp_date); cday = greg2abs(*greg_day); /* No cycle, new cycle, old cycle */ if (cday < osday) return; /* daf yomi hadn't started yet */ if (cday >= nsday) { cno = 8 + ( (cday - nsday) / 2711 ); dno = (cday - nsday) % 2711; } else { cno = 1 + ( (cday - osday) / 2702 ); dno = (cday - osday) / 2702; } /* Find the daf taking note that the cycle changed slightly after cycle 7. */ total = blatt = 0; count = -1; /* Fix Shekalim for old cycles */ if (cno <= 7) shas[4].blatt = 13; else shas[4].blatt = 22; /* Find the daf */ j = 0; while (j < dafcnt) { count++; total = total + shas[j].blatt - 1; if (dno < total) { blatt = (shas[j].blatt + 1) - (total - dno); /* fiddle with the weird ones near the end */ switch(count) { case 36: blatt = blatt + 21; break; case 37: blatt = blatt + 24; break; case 38: blatt = blatt + 33; break; default: break; } /* Bailout */ j = 1 + dafcnt; } j ++; } sprintf(buffer, _("Daf Yomi: %s %d"), _(shas[count].sname), blatt ); PrintGregDate(*greg_day); printf("%s\n", buffer); }
void main_calendar( long todayAbs, long endAbs) /* the range of the desired printout */ { date_t todayGreg, todayHeb; holstorep_t holi_start,holip; /* a list of holidays for today */ year_t theYear; char *omerStr ; int omer, day_of_week, first_weekday, returnedMask; int omer_today, sedra_today, candle_today, holidays_today, molad_today; molad_t moladNext; int monthNext; int today_zemanim, i_zman; int num_zmanim = sizeof (zemanim) / sizeof (struct _zman); char buffer[80]; /* Used to decide whether a particular type of daily info should be included in the abbreviated view. In abbreviated mode things like sunrise, daf, omer are printed once a week. */ #define INCLUDE_TODAY(_sw) \ ( (_sw) && ((!abbrev_sw) || (first_weekday == day_of_week))) todayHeb = abs2hebrew (todayAbs); todayGreg = abs2greg (todayAbs); theYear = yearData (todayHeb.yy); /* plug in light_offset before starting the loop */ for (i_zman = 0; i_zman < num_zmanim; i_zman ++) if (zemanim[i_zman].flags == ZMAN_CANDLES_BEFORE) zemanim[i_zman].min_offset = light_offset; else if (zemanim[i_zman].flags == ZMAN_CANDLES_AFTER || zemanim[i_zman].flags == ZMAN_HAVDALAH ) zemanim[i_zman].min_offset = havdalah_minutes; /*============== Main Year Loop ==============*/ reset_Omer (todayHeb.yy); if (sedraAllWeek_sw || sedrot_sw) reset_sedra (todayHeb.yy); first_weekday = day_of_week = (int) (todayAbs % 7L); while (todayAbs <= endAbs) { /* get the holidays for today */ returnedMask = getHebHolidays (todayHeb, &holip); sedra_today = sedraAllWeek_sw || (sedrot_sw && (day_of_week == SAT)); omer_today = printOmer_sw && (todayAbs >= beginOmer) && (todayAbs <= endOmer); holidays_today = holip && (!noHolidays_sw || (returnedMask & USER_EVENT)); molad_today = printMolad_sw && (day_of_week == SAT) && (todayHeb.dd >= 23 && todayHeb.dd <= 29) && (todayHeb.mm != ELUL); /* no birkat hachodesh before rosh hashana */ today_zemanim = 0; if (INCLUDE_TODAY(default_zemanim)) today_zemanim |= default_zemanim; if (candleLighting_sw) { if (day_of_week == FRI) today_zemanim |= ZMAN_CANDLES_BEFORE; else { if (returnedMask & LIGHT_CANDLES) today_zemanim |= (day_of_week == SAT) ? ZMAN_CANDLES_AFTER : ZMAN_CANDLES_BEFORE; else if ((returnedMask & LIGHT_CANDLES_TZEIS) && ! (returnedMask & YOM_TOV_ENDS)) today_zemanim |= ZMAN_CANDLES_AFTER; } if (!(today_zemanim & (ZMAN_CANDLES_BEFORE | ZMAN_CANDLES_AFTER)) && (day_of_week == SAT || returnedMask & YOM_TOV_ENDS)) today_zemanim |= ZMAN_HAVDALAH; if (!(today_zemanim & (ZMAN_CANDLES_BEFORE)) && (returnedMask & CHANUKAH_CANDLES)) today_zemanim |= ZMAN_CANDLES_AFTER; /* even if havdalah */ } if (INCLUDE_TODAY(printHebDates_sw) || ((printSomeHebDates_sw || printHebDates_sw) && (holidays_today || sedra_today || omer_today || (today_zemanim & (ZMAN_CANDLES_BEFORE|ZMAN_CANDLES_AFTER|ZMAN_HAVDALAH))))) { PrintGregDate (todayGreg); printf ("%d%s of %s, %d\n", todayHeb.dd, /* print the hebrew date */ numSuffix( todayHeb.dd ), _(hMonths[LEAP_YR_HEB( todayHeb.yy )][todayHeb.mm].name), todayHeb.yy); } if (printSunriseSunset_sw) { print_sunrise_sunset(todayGreg); } /* print the sedra, if desired */ if (sedra_today) { char sedraStr[40]; int foundSedra = sedra( todayAbs, sedraStr, 40 ); if (foundSedra) { PrintGregDate( todayGreg ); printf( "%s %s\n", _("Parashat"), sedraStr ); } } /* print today's holidays */ holi_start=holip; /* store the head of the list for freeing */ for (; holip; holip = holip->next) { if (!noHolidays_sw || (holip->typeMask & USER_EVENT)) { PrintGregDate( todayGreg ); puts( holip->name ); } } /* Print the Omer */ if (INCLUDE_TODAY(omer_today)) { initStr (&omerStr, NM_LEN); omer = (int) (todayAbs - beginOmer + 1L); if (!tabs_sw) { strncat (omerStr, hc_itoa (omer), NM_LEN); strncat (omerStr, numSuffix (omer), NM_LEN); strncat (omerStr, " day of the Omer", NM_LEN); } else { strncat (omerStr, "Omer: ", NM_LEN); strncat (omerStr, hc_itoa (omer), NM_LEN); } PrintGregDate (todayGreg); printf ("%s\n", omerStr); free( omerStr ); } if (INCLUDE_TODAY(dafYomi_sw)) hebcal_dafyomi(&todayGreg); /* Print CandleLighting times */ if (today_zemanim) { print_candlelighting_times (today_zemanim, day_of_week, todayGreg); } /* Print Molad */ if (molad_today) { PrintGregDate (todayGreg); monthNext = (todayHeb.mm == MONTHS_IN_HEB(todayHeb.yy) ? 1 : todayHeb.mm + 1); moladNext = get_molad(todayHeb.yy, monthNext); printf ("Molad %s: %s, %d minutes and %d chalakim after %d %s\n", hMonths[LEAP_YR_HEB(todayHeb.yy)][monthNext].name, ShortDayNames[dayOfWeek(abs2greg(moladNext.day))], (int) moladNext.chalakim / 18, moladNext.chalakim % 18, (moladNext.hour > 12 ? moladNext.hour - 12 : moladNext.hour), (moladNext.hour > 12 ? "PM" : "AM") ); } incHebGregDate (&todayHeb, &todayGreg, &todayAbs, &day_of_week, &theYear); # ifdef PLUG_LEAKS free_holidays(*holip); # endif } #undef INCLUDE_TODAY }
void print_candlelighting_times( int mask, int weekday, date_t todayGreg) { double gmt_offset; double h_rise, h_set, N; const int calc_sunset = 1; double n_offset; int hour, minute, pm; int rs; int num_zmanim = sizeof (zemanim) / sizeof (struct _zman); int i_zman; double var_hr_hours = 0.0, day_span; const char *zman_name; rs = get_rise_set(todayGreg, &h_rise, &h_set, &gmt_offset); if (rs != 0) { return; } day_span = h_set - h_rise; if (day_span < 0) day_span += 24; var_hr_hours = day_span / 12.0; for (i_zman = 0; i_zman < num_zmanim; i_zman ++) { double var_hour; int min_offset; char *name; if ( (zemanim[i_zman].flags & mask) == 0 ) continue; var_hour = zemanim[i_zman].variable_hour; min_offset = zemanim[i_zman].min_offset; if ((zemanim[i_zman].flags == ZMAN_MINCHA_GEDOLA) && var_hr_hours < 1) { /* In the winter, when half a solar hour is less than 30 minutes, some authorities use 30 minutes after noon instead of 6.5 solar hours. See Shaar HaTziyun 233:8 and other sources quoted at http://judaism.stackexchange.com/a/25738. myzemanim.com also appears to calculate this way.*/ var_hour = 6.0; min_offset = 30; } if (var_hour < 12.0) { N = h_rise + var_hour * var_hr_hours; n_offset = min_offset / 60.0; } else { N = h_set + (var_hour - 12) * var_hr_hours; n_offset = min_offset / 60.0; } N += gmt_offset; N += n_offset; if (N > 24 || N < 0) { N -= floor(N / 24) * 24; } hour = (int) N; pm = (hour > 11); if (hour > 12 && !twentyFourHour_sw) { hour = hour % 12; } minute = (int) (60 * (N - (int) N)); PrintGregDate (todayGreg); zman_name = _(zemanim[i_zman].name_sfrd); if (zemanim[i_zman].flags == ZMAN_HAVDALAH) { printf(_("%s (%d min):%2d:%02d\n"), zman_name, havdalah_minutes, hour, minute); } else { printf ("%s: %2d:%02d\n", zman_name, hour, minute); } } }