コード例 #1
0
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;
}
コード例 #2
0
ファイル: sedra.c プロジェクト: acli/hebcal
/* 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);
}
コード例 #3
0
ファイル: holidays.c プロジェクト: fbialek/hebcal
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]);

    }
}