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 week_number(int day, int month, int32_t year,
                       const struct cal_control* ctl)
{
    int fday = 0, yday;
    const int wday = day_in_week(ctl, 1, JANUARY, year);

    if (ctl->weektype & WEEK_NUM_ISO)
        fday = wday + (wday >= FRIDAY ? -2 : 5);
    else
    {
        /* WEEK_NUM_US: Jan 1 is always First week, that may
         * begin previous year.  That means there is very seldom
         * more than 52 weeks, */
        fday = wday + 6;
    }
    /* For julian dates the month can be set to 1, the global julian
     * variable cannot be relied upon here, because we may recurse
     * internally for 31.12. which would not work. */
    if (day > DAYS_IN_MONTH)
        month = JANUARY;

    yday = day_in_year(ctl, day, month, year);
    if (year == ctl->reform_year && yday >= YDAY_AFTER_MISSING)
        fday -= NUMBER_MISSING_DAYS;

    /* Last year is last year */
    if (yday + fday < DAYS_IN_WEEK)
        return week_number(31, DECEMBER, year - 1, ctl);

    /* Or it could be part of the next year.  The reformation year had less
     * days than 365 making this check invalid, but reformation year ended
     * on Sunday and in week 51, so it's ok here. */
    if (ctl->weektype == WEEK_NUM_ISO && yday >= 363 &&
        day_in_week(ctl, day, month, year) >= MONDAY &&
        day_in_week(ctl, day, month, year) <= WEDNESDAY &&
        day_in_week(ctl, 31, DECEMBER, year) >= MONDAY &&
        day_in_week(ctl, 31, DECEMBER, year) <= WEDNESDAY)
        return week_number(1, JANUARY, year + 1, ctl);

    return (yday + fday) / DAYS_IN_WEEK;
}
/*
 * week_number
 *      return the week number of a given date, 1..54.
 *      Supports ISO-8601 and North American modes.
 *      Day may be given as Julian day of the year mode, in which
 *      case the month is disregarded entirely.
 */
week_number
return the week number of a given date, 1..54.
Supports ISO-8601 and North American modes.
Day may be given as Julian day of the year mode, in which
case the month is disregarded entirely.
week_number return the week number of a given date 1 .. 54 . Supports ISO - 8601 and North American modes . Day may be given as Julian day of the year mode in which case the month is disregarded entirely .
static int week_number(int day, int month, int32_t year,
                       const struct cal_control* ctl)
{
    int fday = 0, yday;
    const int wday = day_in_week(ctl, 1, JANUARY, year);
    if (ctl->weektype & WEEK_NUM_ISO)
        fday = wday + (wday >= FRIDAY ? -2 : 5);
    else
    {
        fday = wday + 6;
    }
    if (day > DAYS_IN_MONTH)
        month = JANUARY;
    yday = day_in_year(ctl, day, month, year);
    if (year == ctl->reform_year && yday >= YDAY_AFTER_MISSING)
        fday -= NUMBER_MISSING_DAYS;
    if (yday + fday < DAYS_IN_WEEK)
        return week_number(31, DECEMBER, year - 1, ctl);
    if (ctl->weektype == WEEK_NUM_ISO && yday >= 363 &&
        day_in_week(ctl, day, month, year) >= MONDAY &&
        day_in_week(ctl, day, month, year) <= WEDNESDAY &&
        day_in_week(ctl, 31, DECEMBER, year) >= MONDAY &&
        day_in_week(ctl, 31, DECEMBER, year) <= WEDNESDAY)
        return week_number(1, JANUARY, year + 1, ctl);
    return (yday + fday) / DAYS_IN_WEEK;
}
static int week_number ( int day , int month , int32_t year , const struct cal_control * ctl ) { int fday = 0 , yday ; const int wday = day_in_week ( ctl , 1 , JANUARY , year ) ; if ( ctl -> weektype & WEEK_NUM_ISO ) fday = wday + ( wday >= FRIDAY ? -2 : 5 ) ; else { fday = wday + 6 ; } if ( day > DAYS_IN_MONTH ) month = JANUARY ; yday = day_in_year ( ctl , day , month , year ) ; if ( year == ctl -> reform_year && yday >= YDAY_AFTER_MISSING ) fday -= NUMBER_MISSING_DAYS ; if ( yday + fday < DAYS_IN_WEEK ) return week_number ( 31 , DECEMBER , year - 1 , ctl ) ; if ( ctl -> weektype == WEEK_NUM_ISO && yday >= 363 && day_in_week ( ctl , day , month , year ) >= MONDAY && day_in_week ( ctl , day , month , year ) <= WEDNESDAY && day_in_week ( ctl , 31 , DECEMBER , year ) >= MONDAY && day_in_week ( ctl , 31 , DECEMBER , year ) <= WEDNESDAY ) return week_number ( 1 , JANUARY , year + 1 , ctl ) ; return ( yday + fday ) / DAYS_IN_WEEK ; }
week_number
      return the week number of a given date, 1..54.
week_number return the week number of a given date 1 .. 54 .
/* WEEK_NUM_US: Jan 1 is always First week, that may
         * begin previous year.  That means there is very seldom
         * more than 52 weeks, */ /* For julian dates the month can be set to 1, the global julian
     * variable cannot be relied upon here, because we may recurse
     * internally for 31.12. which would not work. */ /* Last year is last year */ /* Or it could be part of the next year.  The reformation year had less
     * days than 365 making this check invalid, but reformation year ended
     * on Sunday and in week 51, so it's ok here. */