public void roll(int field, int amount) {

        switch (field) {
        case WEEK_OF_YEAR:
            {
                // Unlike WEEK_OF_MONTH, WEEK_OF_YEAR never shifts the day of the
                // week.  Also, rolling the week of the year can have seemingly
                // strange effects simply because the year of the week of year
                // may be different from the calendar year.  For example, the
                // date Dec 28, 1997 is the first day of week 1 of 1998 (if
                // weeks start on Sunday and the minimal days in first week is
                // <= 3).
                int woy = get(WEEK_OF_YEAR);
                // Get the ISO year, which matches the week of year.  This
                // may be one year before or after the calendar year.
                int isoYear = get(YEAR_WOY);
                int isoDoy = internalGet(DAY_OF_YEAR);
                if (internalGet(MONTH) == Calendar.JANUARY) {
                    if (woy >= 52) {
                        isoDoy += handleGetYearLength(isoYear);
                    }
                } else {
                    if (woy == 1) {
                        isoDoy -= handleGetYearLength(isoYear - 1);
                    }
                }
                woy += amount;
                // Do fast checks to avoid unnecessary computation:
                if (woy < 1 || woy > 52) {
                    // Determine the last week of the ISO year.
                    // We do this using the standard formula we use
                    // everywhere in this file.  If we can see that the
                    // days at the end of the year are going to fall into
                    // week 1 of the next year, we drop the last week by
                    // subtracting 7 from the last day of the year.
                    int lastDoy = handleGetYearLength(isoYear);
                    int lastRelDow = (lastDoy - isoDoy + internalGet(DAY_OF_WEEK) -
                                      getFirstDayOfWeek()) % 7;
                    if (lastRelDow < 0) lastRelDow += 7;
                    if ((6 - lastRelDow) >= getMinimalDaysInFirstWeek()) lastDoy -= 7;
                    int lastWoy = weekNumber(lastDoy, lastRelDow + 1);
                    woy = ((woy + lastWoy - 1) % lastWoy) + 1;
                }
                set(WEEK_OF_YEAR, woy);
                set(YEAR, isoYear); // Why not YEAR_WOY? - Alan 11/6/00
                return;
            }

        default:
            super.roll(field, amount);
            return;
        }
    }
public void roll ( int field , int amount ) { switch ( field ) { case WEEK_OF_YEAR : { int woy = get ( WEEK_OF_YEAR ) ; int isoYear = get ( YEAR_WOY ) ; int isoDoy = internalGet ( DAY_OF_YEAR ) ; if ( internalGet ( MONTH ) == Calendar . JANUARY ) { if ( woy >= 52 ) { isoDoy += handleGetYearLength ( isoYear ) ; } } else { if ( woy == 1 ) { isoDoy -= handleGetYearLength ( isoYear - 1 ) ; } } woy += amount ; if ( woy < 1 || woy > 52 ) { int lastDoy = handleGetYearLength ( isoYear ) ; int lastRelDow = ( lastDoy - isoDoy + internalGet ( DAY_OF_WEEK ) - getFirstDayOfWeek ( ) ) % 7 ; if ( lastRelDow < 0 ) lastRelDow += 7 ; if ( ( 6 - lastRelDow ) >= getMinimalDaysInFirstWeek ( ) ) lastDoy -= 7 ; int lastWoy = weekNumber ( lastDoy , lastRelDow + 1 ) ; woy = ( ( woy + lastWoy - 1 ) % lastWoy ) + 1 ; } set ( WEEK_OF_YEAR , woy ) ; set ( YEAR , isoYear ) ; return ; } default : super . roll ( field , amount ) ; return ; } }
Roll a field by a signed amount.