openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/misc-utils/cal.c
static int day_in_week(const struct cal_control* ctl, int day, int month,
                       int32_t year)
{
    /*
     * The magic constants in the reform[] array are, in a simplified
     * sense, the remaining days after slicing into one week periods the total
     * days from the beginning of the year to the target month. That is,
     * weeks + reform[] days gets us to the target month. The exception is,
     * that for the months past February 'DOY - 1' must be used.
     *
     *   DoY (Day of Year): total days to the target month
     *
     *   Month            1  2  3  4   5   6   7   8   9  10  11  12
     *   DoY              0 31 59 90 120 151 181 212 243 273 304 334
     *   DoY % 7          0  3
     *   DoY - 1 % 7      - --  2  5   0   3   5   1   4   6   2   4
     *       reform[] = { 0, 3, 2, 5,  0,  3,  5,  1,  4,  6,  2,  4 };
     *
     *  Note: these calculations are for non leap years.
     */
    static const int reform[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    static const int old[] = {5, 1, 0, 3, 5, 1, 3, 6, 2, 4, 0, 2};

    if (year != ctl->reform_year + 1)
        year -= month < MARCH;
    else
        year -= (month < MARCH) + 14;
    if (ctl->reform_year < year ||
        (year == ctl->reform_year && REFORMATION_MONTH < month) ||
        (year == ctl->reform_year && month == REFORMATION_MONTH && 13 < day))
    {
        return ((int64_t)year + (year / 4) - (year / 100) + (year / 400) +
                reform[month - 1] + day) %
               DAYS_IN_WEEK;
    }
    if (year < ctl->reform_year ||
        (year == ctl->reform_year && month < REFORMATION_MONTH) ||
        (year == ctl->reform_year && month == REFORMATION_MONTH && day < 3))
        return ((int64_t)year + year / 4 + old[month - 1] + day) % DAYS_IN_WEEK;
    return NONEDAY;
}
/*
 * day_in_week
 *	return the 0 based day number for any date from 1 Jan. 1 to
 *	31 Dec. 9999.  Assumes the Gregorian reformation eliminates
 *	3 Sep. 1752 through 13 Sep. 1752, and returns invalid weekday
 *	during the period of 11 days.
 */
day_in_week
return the 0 based day number for any date from 1 Jan.
day_in_week return the 0 based day number for any date from 1 Jan .
static int day_in_week(const struct cal_control* ctl, int day, int month,
                       int32_t year)
{
    static const int reform[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    static const int old[] = {5, 1, 0, 3, 5, 1, 3, 6, 2, 4, 0, 2};
    if (year != ctl->reform_year + 1)
        year -= month < MARCH;
    else
        year -= (month < MARCH) + 14;
    if (ctl->reform_year < year ||
        (year == ctl->reform_year && REFORMATION_MONTH < month) ||
        (year == ctl->reform_year && month == REFORMATION_MONTH && 13 < day))
    {
        return ((int64_t)year + (year / 4) - (year / 100) + (year / 400) +
                reform[month - 1] + day) %
               DAYS_IN_WEEK;
    }
    if (year < ctl->reform_year ||
        (year == ctl->reform_year && month < REFORMATION_MONTH) ||
        (year == ctl->reform_year && month == REFORMATION_MONTH && day < 3))
        return ((int64_t)year + year / 4 + old[month - 1] + day) % DAYS_IN_WEEK;
    return NONEDAY;
}
static int day_in_week ( const struct cal_control * ctl , int day , int month , int32_t year ) { static const int reform [ ] = { 0 , 3 , 2 , 5 , 0 , 3 , 5 , 1 , 4 , 6 , 2 , 4 } ; static const int old [ ] = { 5 , 1 , 0 , 3 , 5 , 1 , 3 , 6 , 2 , 4 , 0 , 2 } ; if ( year != ctl -> reform_year + 1 ) year -= month < MARCH ; else year -= ( month < MARCH ) + 14 ; if ( ctl -> reform_year < year || ( year == ctl -> reform_year && REFORMATION_MONTH < month ) || ( year == ctl -> reform_year && month == REFORMATION_MONTH && 13 < day ) ) { return ( ( int64_t ) year + ( year / 4 ) - ( year / 100 ) + ( year / 400 ) + reform [ month - 1 ] + day ) % DAYS_IN_WEEK ; } if ( year < ctl -> reform_year || ( year == ctl -> reform_year && month < REFORMATION_MONTH ) || ( year == ctl -> reform_year && month == REFORMATION_MONTH && day < 3 ) ) return ( ( int64_t ) year + year / 4 + old [ month - 1 ] + day ) % DAYS_IN_WEEK ; return NONEDAY ; }
day_in_week
      return the 0 based day number for any date from 1 Jan. 1 to
      31 Dec. 9999.
day_in_week return the 0 based day number for any date from 1 Jan . 1 to 31 Dec . 9999 .
/*
     * The magic constants in the reform[] array are, in a simplified
     * sense, the remaining days after slicing into one week periods the total
     * days from the beginning of the year to the target month. That is,
     * weeks + reform[] days gets us to the target month. The exception is,
     * that for the months past February 'DOY - 1' must be used.
     *
     *   DoY (Day of Year): total days to the target month
     *
     *   Month            1  2  3  4   5   6   7   8   9  10  11  12
     *   DoY              0 31 59 90 120 151 181 212 243 273 304 334
     *   DoY % 7          0  3
     *   DoY - 1 % 7      - --  2  5   0   3   5   1   4   6   2   4
     *       reform[] = { 0, 3, 2, 5,  0,  3,  5,  1,  4,  6,  2,  4 };
     *
     *  Note: these calculations are for non leap years.
     */