JapaneseImperialCalendar.java revision 2362
2215N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 1879N/A * <code>JapaneseImperialCalendar</code> implements a Japanese 1879N/A * calendar system in which the imperial era-based year numbering is 1879N/A * supported from the Meiji era. The following are the eras supported 1879N/A * ERA value Era name Since (in Gregorian) 1879N/A * ------------------------------------------------------ 1879N/A * 1 Meiji 1868-01-01 midnight local time 2796N/A * 2 Taisho 1912-07-30 midnight local time 2796N/A * 3 Showa 1926-12-25 midnight local time 2796N/A * 4 Heisei 1989-01-08 midnight local time 1879N/A * ------------------------------------------------------ 1879N/A * <p><code>ERA</code> value 0 specifies the years before Meiji and 0N/A * the Gregorian year values are used. Unlike {@link 0N/A * GregorianCalendar}, the Julian to Gregorian transition is not 0N/A * supported because it doesn't make any sense to the Japanese 0N/A * calendar systems used before Meiji. To represent the years before 4602N/A * Gregorian year 1, 0 and negative values are used. The Japanese 4602N/A * Imperial rescripts and government decrees don't specify how to deal 4602N/A * with time differences for applying the era transitions. This 4602N/A * calendar implementation assumes local time for all transitions. 1715N/A * sun.util.calendar.LocalGregorianCalendar to perform most of the 1715N/A * calendar calculations. LocalGregorianCalendar is configurable 0N/A * The ERA constant designating the era before Meiji. 0N/A * The ERA constant designating the Meiji era. 0N/A * The ERA constant designating the Taisho era. 0N/A * The ERA constant designating the Showa era. 13N/A * The ERA constant designating the Heisei era. 342N/A private static final int EPOCH_OFFSET =
719163;
// Fixed date of January 1, 1970 (Gregorian) 13N/A // Useful millisecond constants. Although ONE_DAY and ONE_WEEK can fit 13N/A // into ints, they must be longs in order to prevent arithmetic overflow 0N/A // when performing (bug 4173516). 13N/A // Reference to the sun.util.calendar.LocalGregorianCalendar instance (singleton). 13N/A // Gregorian calendar instance. This is required because era 0N/A // transition dates are given in Gregorian dates. 0N/A // The Era instance representing "before Meiji". 13N/A // Imperial eras. The sun.util.calendar.LocalGregorianCalendar 0N/A // doesn't have an Era representing before Meiji, which is 0N/A // inconvenient for a Calendar. So, era[0] is a reference to 13N/A // BEFORE_MEIJI_ERA. 13N/A // Fixed date of the first date of each era. 13N/A * Field name Minimum Minimum Maximum Maximum 13N/A * ---------- ------- ------- ------- ------- 0N/A * YEAR -292275055 1 ? ? 0N/A * WEEK_OF_YEAR 1 1 52* 53 0N/A * WEEK_OF_MONTH 0 0 4* 6 0N/A * DAY_OF_MONTH 1 1 28* 31 0N/A * DAY_OF_YEAR 1 1 365* 366 0N/A * DAY_OF_WEEK 1 1 7 7 0N/A * DAY_OF_WEEK_IN_MONTH -1 -1 4* 6 0N/A * HOUR_OF_DAY 0 0 23 23 0N/A * MILLISECOND 0 0 999 999 1387N/A * ZONE_OFFSET -13:00 -13:00 14:00 14:00 1387N/A * DST_OFFSET 0:00 0:00 0:20 2:00 0N/A 1,
// DAY_OF_WEEK_IN_MONTH 1387N/A 0,
// ERA (initialized later) 1387N/A 0,
// YEAR (initialized later) 1387N/A 0,
// WEEK_OF_YEAR (Showa 1 has only 6 days which could be 0 weeks.) 0N/A 0,
// DAY_OF_YEAR (initialized later) 13N/A 4,
// DAY_OF_WEEK_IN 13N/A 999,
// MILLISECOND 13N/A 53,
// WEEK_OF_YEAR 0N/A 6,
// DAY_OF_WEEK_IN 0N/A // Proclaim serialization compatibility with JDK 1.6 0N/A // eras[BEFORE_MEIJI] and sinceFixedDate[BEFORE_MEIJI] are the 0N/A // same as Gregorian. 0N/A // Calculate the least maximum year and least day of Year 0N/A // values. The following code assumes that there's at most one 0N/A // era transition in a Gregorian year. 0N/A // Unless the first year starts from January 1, the actual 0N/A // max value could be one year short. For example, if it's 0N/A // Showa 63 January 8, 63 is the actual max value since 0N/A // Showa 64 January 8 doesn't exist. 0N/A * jdate always has a sun.util.calendar.LocalGregorianCalendar.Date instance to 0N/A * avoid overhead of creating it for each calculation. 0N/A * Temporary int[2] to get time zone offsets. zoneOffsets[0] gets 0N/A * the GMT offset value and zoneOffsets[1] gets the daylight saving 13N/A * Temporary storage for saving original fields[] values in 13N/A * non-lenient mode. 0N/A * Constructs a <code>JapaneseImperialCalendar</code> based on the current time 0N/A * in the given time zone with the given locale. 13N/A * @param zone the given time zone. 13N/A * @param aLocale the given locale. 2215N/A * Compares this <code>JapaneseImperialCalendar</code> to the specified 2215N/A * <code>Object</code>. The result is <code>true</code> if and 13N/A * only if the argument is a <code>JapaneseImperialCalendar</code> object 13N/A * that represents the same time value (millisecond offset from 13N/A * <code>Calendar</code> parameters. 13N/A * @param obj the object to compare with. 13N/A * @return <code>true</code> if this object is equal to <code>obj</code>; 13N/A * <code>false</code> otherwise. 13N/A * @see Calendar#compareTo(Calendar) 13N/A * Generates the hash code for this 13N/A * <code>JapaneseImperialCalendar</code> object. 0N/A * Adds the specified (signed) amount of time to the given calendar field, 13N/A * based on the calendar's rules. 0N/A * <p><em>Add rule 1</em>. The value of <code>field</code> 0N/A * after the call minus the value of <code>field</code> before the 13N/A * call is <code>amount</code>, modulo any overflow that has occurred in 13N/A * <code>field</code>. Overflow occurs when a field value exceeds its 13N/A * range and, as a result, the next larger field is incremented or 13N/A * decremented and the field value is adjusted back into its range.</p> 13N/A * <p><em>Add rule 2</em>. If a smaller field is expected to be 13N/A * invariant, but it is impossible for it to be equal to its 2215N/A * prior value because of changes in its minimum or maximum after 13N/A * <code>field</code> is changed, then its value is adjusted to be as close 13N/A * as possible to its expected value. A smaller field represents a 13N/A * smaller unit of time. <code>HOUR</code> is a smaller field than 13N/A * <code>DAY_OF_MONTH</code>. No adjustment is made to smaller fields 13N/A * that are not expected to be invariant. The calendar system 13N/A * determines what fields are expected to be invariant.</p> 13N/A * @param field the calendar field. 13N/A * @param amount the amount of date or time to be added to the field. 13N/A * @exception IllegalArgumentException if <code>field</code> is 13N/A * <code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or unknown, 13N/A * or if any calendar fields have out-of-range values in 13N/A * non-lenient mode. 13N/A // If amount == 0, do nothing even the given field is out of 13N/A // range. This is tested by JCK. 13N/A return;
// Do nothing! 13N/A // Sync the time and calendar fields. 13N/A // Handle the time fields here. Convert the given 13N/A // amount to milliseconds and call setTimeInMillis. 0N/A delta *=
60 *
60 *
1000;
// hours to milliseconds 13N/A delta *=
60 *
1000;
// minutes to milliseconds 13N/A // Handle week, day and AM_PM fields which involves 13N/A // time zone offset change adjustment. Convert the 13N/A // given amount to the number of days. 13N/A // Convert the amount to the number of days (delta) 13N/A // and +12 or -12 hours (timeOfDay). 13N/A // The time fields don't require time zone offset change 13N/A // The rest of the fields (week, day or AM_PM fields) 13N/A // require time zone offset (both GMT and DST) change 0N/A // Translate the current time to the fixed date and time 13N/A fd +=
delta;
// fd is the expected fixed date after the calculation 13N/A // If the time zone offset has changed, then adjust the difference. 13N/A // If the adjustment has changed the date, then take 13N/A // the previous one. 0N/A * Adds a signed amount to the specified calendar field without changing larger fields. 0N/A * A negative roll amount means to subtract from field without changing 13N/A * larger fields. If the specified amount is 0, this method performs nothing. 0N/A * <p>This method calls {@link #complete()} before adding the 13N/A * amount so that all the calendar fields are normalized. If there 13N/A * is any calendar field having an out-of-range value in non-lenient mode, then an 13N/A * <code>IllegalArgumentException</code> is thrown. 13N/A * @param field the calendar field. 13N/A * @param amount the signed amount to add to <code>field</code>. 13N/A * @exception IllegalArgumentException if <code>field</code> is 13N/A * <code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or unknown, 2215N/A * or if any calendar fields have out-of-range values in 13N/A * non-lenient mode. 13N/A * @see #roll(int,boolean) 13N/A * @see #add(int,int) 13N/A * @see #set(int,int) 13N/A // If amount == 0, do nothing even the given field is out of 13N/A // range. This is tested by JCK. 13N/A // Sync the time and calendar fields. 13N/A // These fields are handled simply, since they have fixed 13N/A // minima and maxima. Other fields are complicated, since 13N/A // the range within they must roll varies depending on the 13N/A // date, a time zone and the era transitions. 1387N/A // The day might have changed, which could happen if 1387N/A // the daylight saving time transition brings it to 0N/A // the next day, although it's very unlikely. But we 0N/A // have to make sure not to change the larger fields. 0N/A // Time zone offset and/or daylight saving might have changed. 0N/A // Rolling the month involves both pinning the final value to [0, 11] 0N/A // and adjusting the DAY_OF_MONTH if necessary. We only adjust the 0N/A // DAY_OF_MONTH if, after updating the MONTH field, it is illegal. 0N/A // E.g., <jan31>.roll(MONTH, 1) -> <feb28> or <feb29>. 0N/A // To avoid overflow, use an equivalent year. 0N/A // Month may have changed by the normalization. 0N/A // To avoid underflow, use an equivalent year. 1387N/A // Month may have changed by the normalization. 1387N/A // Keep the day of month in the range. We 1387N/A // don't want to spill over into the next 0N/A // month; e.g., we don't want jan31 + 1 mo -> 0N/A // The year has only one month. No need to 0N/A // process further. (Showa Gan-nen (year 1) 0N/A // and the last year have only one month.) 0N/A // If the new value is in between min and max 0N/A // (exclusive), then we can use the value. 0N/A // Make sure that the min week has the current DAY_OF_WEEK 0N/A // Make sure the same thing for the max week 0N/A // Make sure that the min week has the current DAY_OF_WEEK 0N/A // Make sure the same thing for the max week 0N/A // value: the new WEEK_OF_YEAR which must be converted 0N/A // to month and day of month. 0N/A // dow: relative day of week from the first day of week 0N/A long month1;
// fixed date of the first day (usually 1) of the month 0N/A // the first day of week of the month. 0N/A // if the week has enough days to form a week, the 0N/A // week starts from the previous month. 0N/A // value: the new WEEK_OF_MONTH value 0N/A // nfd: fixed date of the rolled date // Unlike WEEK_OF_YEAR, we need to change day of week if the // nfd is out of the month. // TODO: Need to change the spec to be usable DAY_OF_MONTH rolling... // Transition handling. We can't change year and era // values here due to the Calendar roll spec! // It may not be a regular month. Convert the date and range to // the relative values, perform the roll, and // convert the result back to the rolled date. // Handle transition. We can't change year and era values // here due to the Calendar roll spec. // If the week of year is in the same year, we can // just change DAY_OF_WEEK. // We need to handle it in a different way around year // boundaries and in the transition year. Note that // changing era and year values violates the roll // rule: not changing larger calendar fields... min =
1;
// after having normalized, min should be 1. // Transition year handling. // "GanNen" is supported only in the LONG style. // If the ERA value is out of range for strings, then // try to get its name or abbreviation from the Era instance. // If strings[] has fewer than eras[], get more names from eras[]. * Returns the minimum value for the given calendar field of this * <code>Calendar</code> instance. The minimum value is * defined as the smallest value returned by the {@link * Calendar#get(int) get} method for any possible time value, * taking into consideration the current values of the * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek}, * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek}, * and {@link Calendar#getTimeZone() getTimeZone} methods. * @param field the calendar field. * @return the minimum value for the given calendar field. * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) * Returns the maximum value for the given calendar field of this * <code>GregorianCalendar</code> instance. The maximum value is * defined as the largest value returned by the {@link * Calendar#get(int) get} method for any possible time value, * taking into consideration the current values of the * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek}, * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek}, * and {@link Calendar#getTimeZone() getTimeZone} methods. * @param field the calendar field. * @return the maximum value for the given calendar field. * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) // The value should depend on the time zone of this calendar. * Returns the highest minimum value for the given calendar field * of this <code>GregorianCalendar</code> instance. The highest * minimum value is defined as the largest value returned by * {@link #getActualMinimum(int)} for any possible time value, * taking into consideration the current values of the * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek}, * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek}, * and {@link Calendar#getTimeZone() getTimeZone} methods. * @param field the calendar field. * @return the highest minimum value for the given calendar field. * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) * Returns the lowest maximum value for the given calendar field * of this <code>GregorianCalendar</code> instance. The lowest * maximum value is defined as the smallest value returned by * {@link #getActualMaximum(int)} for any possible time value, * taking into consideration the current values of the * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek}, * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek}, * and {@link Calendar#getTimeZone() getTimeZone} methods. * @param field the calendar field * @return the lowest maximum value for the given calendar field. * @see #getGreatestMinimum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) * Returns the minimum value that this calendar field could have, * taking into consideration the given time value and the current * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek}, * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek}, * and {@link Calendar#getTimeZone() getTimeZone} methods. * @param field the calendar field * @return the minimum of the given field for the time value of * this <code>JapaneseImperialCalendar</code> * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMaximum(int) // Get a local date which includes time of day and time zone, // which are missing in jc.jdate. // Use the same year in jd to take care of leap // years. i.e., both jd and d must agree on leap // Use an equvalent year of d.getYear() if // possible. Otherwise, ignore the leap year and // common year difference. // In Before Meiji and Meiji, January is the first month. // shift 400 years to avoid underflow * Returns the maximum value that this calendar field could have, * taking into consideration the given time value and the current * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek}, * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek}, * {@link Calendar#getTimeZone() getTimeZone} methods. * For example, if the date of this instance is Heisei 16February 1, * the actual maximum value of the <code>DAY_OF_MONTH</code> field * is 29 because Heisei 16 is a leap year, and if the date of this * instance is Heisei 17 February 1, it's 28. * @param field the calendar field * @return the maximum of the given field for the time value of * this <code>JapaneseImperialCalendar</code> * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) // TODO: there may be multiple transitions in a year. // Handle transition year. // TODO: there may be multiple transitions in a year. // shift 400 years to avoid underflow // Get the day of week of January 1 of the year // Normalize the day of week with the firstDayOfWeek value // Use an equivalent year for the // getYearOffsetInMillis call to avoid overflow. // Use the same year as d.getYear() to be // consistent with leap and common years. * Returns the millisecond offset from the beginning of the * year. In the year for Long.MIN_VALUE, it's a pseudo value * beyond the limit. The given CalendarDate object must have been * normalized before calling this method. // To share the zone by the CalendarDate // To share the zone by the CalendarDate * The fixed date corresponding to jdate. If the value is * Long.MIN_VALUE, the fixed date value is unknown. * Converts the time value (millisecond offset from the <a * href="Calendar.html#Epoch">Epoch</a>) to calendar field values. * The time is <em>not</em> * recomputed first; to recompute the time, then the fields, call the * <code>complete</code> method. // Determine which calendar fields need to be computed. // After computing all the fields, set the field state to `COMPUTED'. * This computeFields implements the conversion from UTC * (millisecond offset from the Epoch) to calendar * field values. fieldMask specifies which fields to change the * setting state to COMPUTED, although all fields are set to * the correct values. This is required to fix 4685354. * @param fieldMask a bit mask to specify which fields to change * @param tzMask a bit mask to specify which time zone offset * fields to be used for time calculations * @return a new field mask that indicates what field values have // By computing time and zoneOffset separately, we can take // the wider range of time+zoneOffset than the previous // See if we can use jdate to avoid date calculation. // Always set the ERA and YEAR values. // Set the basic date fields. // If it's a year of an era transition, we need to handle // irregular year boundaries. // The spec is to calculate WEEK_OF_YEAR in the // ISO8601-style. This creates problems, though. // If the date belongs to the last week of the // previous year, use the week number of "12/31" of // the "previous" year. Again, if the previous year is // a transition year, we need to take care of it. // Usually the previous day of the first day of a year // is December 31, which is not always true in the // Japanese imperial calendar system. // As of Heisei (since Meiji) there's no case // that there are multiple transitions in a // year. Historically there was such // case. There might be such case again in the // The first days forms a week in which the date is included. // The first days forms a week in which the date is included. * Returns the number of weeks in a period between fixedDay1 and * fixedDate. The getFirstDayOfWeek-getMinimalDaysInFirstWeek rule * is applied to calculate the number of weeks. * @param fixedDay1 the fixed date of the first day of the period * @param fixedDate the fixed date of the last day of the period * @return the number of weeks of the given period // We can always use `jcal' since Julian and Gregorian are the // same thing for this calculation. * Converts calendar field values to the time value (millisecond * @exception IllegalArgumentException if any calendar fields are invalid. // In non-lenient mode, perform brief checking of calendar // fields which have been set externally. Through this // checking, the field values are stored in originalFields[] // to see if any of them are normalized later. // Quick validation for any out of range values // Let the super class determine which calendar fields to be // used to calculate the time. // Equivalent to 1970 (Gregorian) // Calculate the time of day. We rely on the convention that // The default value of AM_PM is 0 which designates AM. // Convert the time of day to the number of days and the // millisecond offset from midnight. // Calculate the fixed date since January 1, 1 (Gregorian). // millis represents local wall-clock time in milliseconds. // Compute the time zone offset and DST offset. There are two potential // ambiguities here. We'll assume a 2:00 am (wall time) switchover time // for discussion purposes here. // 1. The transition into DST. Here, a designated time of 2:00 am - 2:59 am // can be in standard or in DST depending. However, 2:00 am is an invalid // representation (the representation jumps from 1:59:59 am Std to 3:00:00 am DST). // We assume standard time. // 2. The transition out of DST. Here, a designated time of 1:00 am - 1:59 am // can be in standard or DST. Both are valid representations (the rep // jumps from 1:59:59 DST to 1:00:00 Std). // Again, we assume standard time. // We use the TimeZone object, unless the user has explicitly set the ZONE_OFFSET // or DST_OFFSET fields; then we use those fields. // Adjust the time zone offset values to get the UTC time. // Set this calendar's time in milliseconds // Restore the original field values * Computes the fixed date under either the Gregorian or the * Julian calendar, using the given year and the specified calendar fields. * @param cal the CalendarSystem to be used for the date calculation * @param year the normalized year number, with 0 indicating the * year 1 BCE, -1 indicating 2 BCE, etc. * @param fieldMask the calendar fields to be used for the date calculation * @see Calendar#selectFields // No need to check if MONTH has been set (no isSet(MONTH) // call) since its unset value happens to be JANUARY (0). // If the month is out of range, adjust it into range. // Adjust the base date if year is the minimum value. // Get the fixed date since Jan 1, 1 (Gregorian). We are on // the first day of either `month' or January in 'year'. // Month-based calculations // We are on the "first day" of the month (which may // not be 1). Just add the offset if DAY_OF_MONTH is // set. If the isSet call returns false, that means // DAY_OF_MONTH has been selected just because of the // selected combination. We don't need to add any // since the default value is the "first day". // To avoid underflow with DAY_OF_MONTH-firstDayOfMonth, add // DAY_OF_MONTH, then subtract firstDayOfMonth. // If we have enough days in the first week, then // move to the previous week. // In lenient mode, we treat days of the previous // months as a part of the specified // WEEK_OF_MONTH. See 4633646. // We are basing this on the day-of-week-in-month. The only // trickiness occurs if the day-of-week-in-month is // Go to the first day of the next week of // the specified week boundary. // Then, get the day of week date on or before the last date. // We are on the first day of the year. // Add the offset, then subtract 1. (Make sure to avoid underflow.) // If we have enough days in the first week, then move * Returns the fixed date of the first day of the year (usually * January 1) before the specified date. * @param date the date for which the first day of the year is * calculated. The date has to be in the cut-over year. * @param fixedDate the fixed date representation of the date // There might be multiple era transitions in a year. * Returns the fixed date of the first date of the month (usually * the 1st of the month) before the specified date. * @param date the date for which the first day of the month is * calculated. The date must be in the era transition year. * @param fixedDate the fixed date representation of the date // If the given date is on or after the transition date, then // return the transition date. // Otherwise, we can use the 1st day of the month. * Returns a LocalGregorianCalendar.Date produced from the specified fixed date. * @param fd the fixed date * Returns the length of the specified month in the specified * Gregorian year. The year number must be normalized. * Returns the length of the specified month in the year provided * Returns the index to the new era if the given date is in a * transition month. For example, if the give date is Heisei 1 * (1989) January 20, then the era index for Heisei is * returned. Likewise, if the given date is Showa 64 (1989) * January 3, then the era index for Heisei is returned. If the * given date is not in any transition month, then -1 is returned. * Returns this object if it's normalized (all fields and time are * in sync). Otherwise, a cloned object is returned after calling * complete() in lenient mode. // Create a clone and normalize the calendar fields * After adjustments such as add(MONTH), add(YEAR), we don't want the * month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar * 3, we want it to go to Feb 28. Adjustments which might run into this * problem call this method to retain the proper month. // Use an equivalent year. // Don't normalize date here so as not to cause underflow. * Returns the new value after 'roll'ing the specified value and amount. * Returns the ERA. We need a special method for this because the * default ERA is the current era, but a zero (unset) ERA means before Meiji. * Updates internal state.