Rolls (up/down) a single unit of time on the given field. If the field is rolled past its maximum allowable value, it will "wrap" back to its minimum and continue rolling. For example, to roll the current date up by one day, you can call:
roll( {@link #DATE}, true)
When rolling on the {@link #YEAR} field, it will roll the yearvalue in the range between 1 and the value returned by calling {@link #getMaximum getMaximum}( {@link #YEAR}).
When rolling on certain fields, the values of other fields may conflict and need to be changed. For example, when rolling the MONTH
field for the Gregorian date 1/31/96 upward, the DAY_OF_MONTH
field must be adjusted so that the result is 2/29/96 rather than the invalid 2/31/96.
Note: Calling roll(field, true) N times is not necessarily equivalent to calling roll(field, N). For example, imagine that you start with the date Gregorian date January 31, 1995. If you call roll(Calendar.MONTH, 2), the result will be March 31, 1995. But if you call roll(Calendar.MONTH, true), the result will be February 28, 1995. Calling it one more time will give March 28, 1995, which is usually not the desired result.
Note: You should always use roll and add rather than attempting to perform arithmetic operations directly on the fields of a Calendar. It is quite possible for Calendar subclasses to have fields with non-linear behavior, for example missing months or days during non-leap years. The subclasses' add and roll methods will take this into account, while simple arithmetic manipulations may give invalid results.
@param field the calendar field to roll.
@param up indicates if the value of the specified time field is to berolled up or rolled down. Use true
if rolling up, false
otherwise.
@exception IllegalArgumentException if the field is invalid or refersto a field that cannot be handled by this method.
@see #roll(int,int)
@see #add
@stable ICU 2.0