@Override
    public void add(int field, int amount) {
        // If amount == 0, do nothing even the given field is out of
        // range. This is tested by JCK.
        if (amount == 0) {
            return;   // Do nothing!
        }

        if (field < 0 || field >= ZONE_OFFSET) {
            throw new IllegalArgumentException();
        }

        // Sync the time and calendar fields.
        complete();

        if (field == YEAR) {
            int year = internalGet(YEAR);
            if (internalGetEra() == CE) {
                year += amount;
                if (year > 0) {
                    set(YEAR, year);
                } else { // year <= 0
                    set(YEAR, 1 - year);
                    // if year == 0, you get 1 BCE.
                    set(ERA, BCE);
                }
            }
            else { // era == BCE
                year -= amount;
                if (year > 0) {
                    set(YEAR, year);
                } else { // year <= 0
                    set(YEAR, 1 - year);
                    // if year == 0, you get 1 CE
                    set(ERA, CE);
                }
            }
            pinDayOfMonth();
        } else if (field == MONTH) {
            int month = internalGet(MONTH) + amount;
            int year = internalGet(YEAR);
            int y_amount;

            if (month >= 0) {
                y_amount = month/12;
            } else {
                y_amount = (month+1)/12 - 1;
            }
            if (y_amount != 0) {
                if (internalGetEra() == CE) {
                    year += y_amount;
                    if (year > 0) {
                        set(YEAR, year);
                    } else { // year <= 0
                        set(YEAR, 1 - year);
                        // if year == 0, you get 1 BCE
                        set(ERA, BCE);
                    }
                }
                else { // era == BCE
                    year -= y_amount;
                    if (year > 0) {
                        set(YEAR, year);
                    } else { // year <= 0
                        set(YEAR, 1 - year);
                        // if year == 0, you get 1 CE
                        set(ERA, CE);
                    }
                }
            }

            if (month >= 0) {
                set(MONTH,  month % 12);
            } else {
                // month < 0
                month %= 12;
                if (month < 0) {
                    month += 12;
                }
                set(MONTH, JANUARY + month);
            }
            pinDayOfMonth();
        } else if (field == ERA) {
            int era = internalGet(ERA) + amount;
            if (era < 0) {
                era = 0;
            }
            if (era > 1) {
                era = 1;
            }
            set(ERA, era);
        } else {
            long delta = amount;
            long timeOfDay = 0;
            switch (field) {
            // Handle the time fields here. Convert the given
            // amount to milliseconds and call setTimeInMillis.
            case HOUR:
            case HOUR_OF_DAY:
                delta *= 60 * 60 * 1000;        // hours to minutes
                break;

            case MINUTE:
                delta *= 60 * 1000;             // minutes to seconds
                break;

            case SECOND:
                delta *= 1000;                  // seconds to milliseconds
                break;

            case MILLISECOND:
                break;

            // Handle week, day and AM_PM fields which involves
            // time zone offset change adjustment. Convert the
            // given amount to the number of days.
            case WEEK_OF_YEAR:
            case WEEK_OF_MONTH:
            case DAY_OF_WEEK_IN_MONTH:
                delta *= 7;
                break;

            case DAY_OF_MONTH: // synonym of DATE
            case DAY_OF_YEAR:
            case DAY_OF_WEEK:
                break;

            case AM_PM:
                // Convert the amount to the number of days (delta)
                // and +12 or -12 hours (timeOfDay).
                delta = amount / 2;
                timeOfDay = 12 * (amount % 2);
                break;
            }

            // The time fields don't require time zone offset change
            // adjustment.
            if (field >= HOUR) {
                setTimeInMillis(time + delta);
                return;
            }

            // The rest of the fields (week, day or AM_PM fields)
            // require time zone offset (both GMT and DST) change
            // adjustment.

            // Translate the current time to the fixed date and time
            // of the day.
            long fd = getCurrentFixedDate();
            timeOfDay += internalGet(HOUR_OF_DAY);
            timeOfDay *= 60;
            timeOfDay += internalGet(MINUTE);
            timeOfDay *= 60;
            timeOfDay += internalGet(SECOND);
            timeOfDay *= 1000;
            timeOfDay += internalGet(MILLISECOND);
            if (timeOfDay >= ONE_DAY) {
                fd++;
                timeOfDay -= ONE_DAY;
            } else if (timeOfDay < 0) {
                fd--;
                timeOfDay += ONE_DAY;
            }

            fd += delta; // fd is the expected fixed date after the calculation
            // BEGIN Android-changed: time zone related calculation via helper methods
            // Calculate the time in the UTC time zone.
            long utcTime = (fd - EPOCH_OFFSET) * ONE_DAY + timeOfDay;

            // Neither of the time zone related fields are relevant because they have not been
            // set since the call to complete() above.
            int tzMask = 0;

            // Adjust the time to account for zone and daylight savings time offset.
            long millis = adjustForZoneAndDaylightSavingsTime(tzMask, utcTime, getZone());

            // Update the time and recompute the fields.
            setTimeInMillis(millis);
            // END Android-changed: time zone related calculation via helper methods
        }
    }
@ Override public void add ( int field , int amount ) { if ( amount == 0 ) { return ; } if ( field < 0 || field >= ZONE_OFFSET ) { throw new IllegalArgumentException ( ) ; } complete ( ) ; if ( field == YEAR ) { int year = internalGet ( YEAR ) ; if ( internalGetEra ( ) == CE ) { year += amount ; if ( year > 0 ) { set ( YEAR , year ) ; } else { set ( YEAR , 1 - year ) ; set ( ERA , BCE ) ; } } else { year -= amount ; if ( year > 0 ) { set ( YEAR , year ) ; } else { set ( YEAR , 1 - year ) ; set ( ERA , CE ) ; } } pinDayOfMonth ( ) ; } else if ( field == MONTH ) { int month = internalGet ( MONTH ) + amount ; int year = internalGet ( YEAR ) ; int y_amount ; if ( month >= 0 ) { y_amount = month / 12 ; } else { y_amount = ( month + 1 ) / 12 - 1 ; } if ( y_amount != 0 ) { if ( internalGetEra ( ) == CE ) { year += y_amount ; if ( year > 0 ) { set ( YEAR , year ) ; } else { set ( YEAR , 1 - year ) ; set ( ERA , BCE ) ; } } else { year -= y_amount ; if ( year > 0 ) { set ( YEAR , year ) ; } else { set ( YEAR , 1 - year ) ; set ( ERA , CE ) ; } } } if ( month >= 0 ) { set ( MONTH , month % 12 ) ; } else { month %= 12 ; if ( month < 0 ) { month += 12 ; } set ( MONTH , JANUARY + month ) ; } pinDayOfMonth ( ) ; } else if ( field == ERA ) { int era = internalGet ( ERA ) + amount ; if ( era < 0 ) { era = 0 ; } if ( era > 1 ) { era = 1 ; } set ( ERA , era ) ; } else { long delta = amount ; long timeOfDay = 0 ; switch ( field ) { case HOUR : case HOUR_OF_DAY : delta *= 60 * 60 * 1000 ; break ; case MINUTE : delta *= 60 * 1000 ; break ; case SECOND : delta *= 1000 ; break ; case MILLISECOND : break ; case WEEK_OF_YEAR : case WEEK_OF_MONTH : case DAY_OF_WEEK_IN_MONTH : delta *= 7 ; break ; case DAY_OF_MONTH : case DAY_OF_YEAR : case DAY_OF_WEEK : break ; case AM_PM : delta = amount / 2 ; timeOfDay = 12 * ( amount % 2 ) ; break ; } if ( field >= HOUR ) { setTimeInMillis ( time + delta ) ; return ; } long fd = getCurrentFixedDate ( ) ; timeOfDay += internalGet ( HOUR_OF_DAY ) ; timeOfDay *= 60 ; timeOfDay += internalGet ( MINUTE ) ; timeOfDay *= 60 ; timeOfDay += internalGet ( SECOND ) ; timeOfDay *= 1000 ; timeOfDay += internalGet ( MILLISECOND ) ; if ( timeOfDay >= ONE_DAY ) { fd ++ ; timeOfDay -= ONE_DAY ; } else if ( timeOfDay < 0 ) { fd -- ; timeOfDay += ONE_DAY ; } fd += delta ; long utcTime = ( fd - EPOCH_OFFSET ) * ONE_DAY + timeOfDay ; int tzMask = 0 ; long millis = adjustForZoneAndDaylightSavingsTime ( tzMask , utcTime , getZone ( ) ) ; setTimeInMillis ( millis ) ; } }
Adds the specified (signed) amount of time to the given calendar field,
based on the calendar's rules.

<p><em>Add rule 1</em>. The value of <code>field</code>
after the call minus the value of <code>field</code> before the
call is <code>amount</code>, modulo any overflow that has occurred in
<code>field</code>. Overflow occurs when a field value exceeds its
range and, as a result, the next larger field is incremented or
decremented and the field value is adjusted back into its range.</p>

<p><em>Add rule 2</em>. If a smaller field is expected to be
invariant, but it is impossible for it to be equal to its
prior value because of changes in its minimum or maximum after
<code>field</code> is changed, then its value is adjusted to be as close
as possible to its expected value. A smaller field represents a
smaller unit of time. <code>HOUR</code> is a smaller field than
<code>DAY_OF_MONTH</code>. No adjustment is made to smaller fields
that are not expected to be invariant. The calendar system
determines what fields are expected to be invariant.</p>

@param field the calendar field.
@param amount the amount of date or time to be added to the field.
@exception IllegalArgumentException if <code>field</code> is
<code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or unknown,
or if any calendar fields have out-of-range values in
non-lenient mode.