/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* (C) Copyright Taligent, Inc. 1996-1998 - All Rights Reserved
* (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
*
* The original version of this source code and documentation is copyrighted
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
* materials are provided under terms of a License Agreement between Taligent
* and Sun. This technology is protected by multiple US and International
* patents. This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
*/
/**
* <code>GregorianCalendar</code> is a concrete subclass of
* <code>Calendar</code> and provides the standard calendar system
* used by most of the world.
*
* <p> <code>GregorianCalendar</code> is a hybrid calendar that
* supports both the Julian and Gregorian calendar systems with the
* support of a single discontinuity, which corresponds by default to
* the Gregorian date when the Gregorian calendar was instituted
* (October 15, 1582 in some countries, later in others). The cutover
* date may be changed by the caller by calling {@link
* #setGregorianChange(Date) setGregorianChange()}.
*
* <p>
* Historically, in those countries which adopted the Gregorian calendar first,
* October 4, 1582 (Julian) was thus followed by October 15, 1582 (Gregorian). This calendar models
* this correctly. Before the Gregorian cutover, <code>GregorianCalendar</code>
* implements the Julian calendar. The only difference between the Gregorian
* and the Julian calendar is the leap year rule. The Julian calendar specifies
* leap years every four years, whereas the Gregorian calendar omits century
* years which are not divisible by 400.
*
* <p>
* <code>GregorianCalendar</code> implements <em>proleptic</em> Gregorian and
* Julian calendars. That is, dates are computed by extrapolating the current
* rules indefinitely far backward and forward in time. As a result,
* <code>GregorianCalendar</code> may be used for all years to generate
* meaningful and consistent results. However, dates obtained using
* <code>GregorianCalendar</code> are historically accurate only from March 1, 4
* AD onward, when modern Julian calendar rules were adopted. Before this date,
* leap year rules were applied irregularly, and before 45 BC the Julian
* calendar did not even exist.
*
* <p>
* Prior to the institution of the Gregorian calendar, New Year's Day was
* March 25. To avoid confusion, this calendar always uses January 1. A manual
* adjustment may be made if desired for dates that are prior to the Gregorian
* changeover and which fall between January 1 and March 24.
*
* <h4><a name="week_and_year">Week Of Year and Week Year</a></h4>
*
* <p>Values calculated for the {@link Calendar#WEEK_OF_YEAR
* WEEK_OF_YEAR} field range from 1 to 53. The first week of a
* calendar year is the earliest seven day period starting on {@link
* Calendar#getFirstDayOfWeek() getFirstDayOfWeek()} that contains at
* least {@link Calendar#getMinimalDaysInFirstWeek()
* getMinimalDaysInFirstWeek()} days from that year. It thus depends
* on the values of {@code getMinimalDaysInFirstWeek()}, {@code
* getFirstDayOfWeek()}, and the day of the week of January 1. Weeks
* between week 1 of one year and week 1 of the following year
* (exclusive) are numbered sequentially from 2 to 52 or 53 (except
* for year(s) involved in the Julian-Gregorian transition).
*
* <p>The {@code getFirstDayOfWeek()} and {@code
* getMinimalDaysInFirstWeek()} values are initialized using
* locale-dependent resources when constructing a {@code
* GregorianCalendar}. <a name="iso8601_compatible_setting">The week
* determination is compatible</a> with the ISO 8601 standard when {@code
* getFirstDayOfWeek()} is {@code MONDAY} and {@code
* getMinimalDaysInFirstWeek()} is 4, which values are used in locales
* where the standard is preferred. These values can explicitly be set by
* calling {@link Calendar#setFirstDayOfWeek(int) setFirstDayOfWeek()} and
* {@link Calendar#setMinimalDaysInFirstWeek(int)
* setMinimalDaysInFirstWeek()}.
*
* <p>A <a name="week_year"><em>week year</em></a> is in sync with a
* {@code WEEK_OF_YEAR} cycle. All weeks between the first and last
* weeks (inclusive) have the same <em>week year</em> value.
* Therefore, the first and last days of a week year may have
* different calendar year values.
*
* <p>For example, January 1, 1998 is a Thursday. If {@code
* getFirstDayOfWeek()} is {@code MONDAY} and {@code
* getMinimalDaysInFirstWeek()} is 4 (ISO 8601 standard compatible
* setting), then week 1 of 1998 starts on December 29, 1997, and ends
* on January 4, 1998. The week year is 1998 for the last three days
* of calendar year 1997. If, however, {@code getFirstDayOfWeek()} is
* {@code SUNDAY}, then week 1 of 1998 starts on January 4, 1998, and
* ends on January 10, 1998; the first three days of 1998 then are
* part of week 53 of 1997 and their week year is 1997.
*
* <h4>Week Of Month</h4>
*
* <p>Values calculated for the <code>WEEK_OF_MONTH</code> field range from 0
* to 6. Week 1 of a month (the days with <code>WEEK_OF_MONTH =
* 1</code>) is the earliest set of at least
* <code>getMinimalDaysInFirstWeek()</code> contiguous days in that month,
* ending on the day before <code>getFirstDayOfWeek()</code>. Unlike
* week 1 of a year, week 1 of a month may be shorter than 7 days, need
* not start on <code>getFirstDayOfWeek()</code>, and will not include days of
* the previous month. Days of a month before week 1 have a
* <code>WEEK_OF_MONTH</code> of 0.
*
* <p>For example, if <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>
* and <code>getMinimalDaysInFirstWeek()</code> is 4, then the first week of
* January 1998 is Sunday, January 4 through Saturday, January 10. These days
* have a <code>WEEK_OF_MONTH</code> of 1. Thursday, January 1 through
* Saturday, January 3 have a <code>WEEK_OF_MONTH</code> of 0. If
* <code>getMinimalDaysInFirstWeek()</code> is changed to 3, then January 1
* through January 3 have a <code>WEEK_OF_MONTH</code> of 1.
*
* <h4>Default Fields Values</h4>
*
* <p>The <code>clear</code> method sets calendar field(s)
* undefined. <code>GregorianCalendar</code> uses the following
* default value for each calendar field if its value is undefined.
*
* <table cellpadding="0" cellspacing="3" border="0"
* summary="GregorianCalendar default field values"
* style="text-align: left; width: 66%;">
* <tbody>
* <tr>
* <th style="vertical-align: top; background-color: rgb(204, 204, 255);
* text-align: center;">Field<br>
* </th>
* <th style="vertical-align: top; background-color: rgb(204, 204, 255);
* text-align: center;">Default Value<br>
* </th>
* </tr>
* <tr>
* <td style="vertical-align: middle;">
* <code>ERA<br></code>
* </td>
* <td style="vertical-align: middle;">
* <code>AD<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: middle; background-color: rgb(238, 238, 255);">
* <code>YEAR<br></code>
* </td>
* <td style="vertical-align: middle; background-color: rgb(238, 238, 255);">
* <code>1970<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: middle;">
* <code>MONTH<br></code>
* </td>
* <td style="vertical-align: middle;">
* <code>JANUARY<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: top; background-color: rgb(238, 238, 255);">
* <code>DAY_OF_MONTH<br></code>
* </td>
* <td style="vertical-align: top; background-color: rgb(238, 238, 255);">
* <code>1<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: middle;">
* <code>DAY_OF_WEEK<br></code>
* </td>
* <td style="vertical-align: middle;">
* <code>the first day of week<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: top; background-color: rgb(238, 238, 255);">
* <code>WEEK_OF_MONTH<br></code>
* </td>
* <td style="vertical-align: top; background-color: rgb(238, 238, 255);">
* <code>0<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: top;">
* <code>DAY_OF_WEEK_IN_MONTH<br></code>
* </td>
* <td style="vertical-align: top;">
* <code>1<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: middle; background-color: rgb(238, 238, 255);">
* <code>AM_PM<br></code>
* </td>
* <td style="vertical-align: middle; background-color: rgb(238, 238, 255);">
* <code>AM<br></code>
* </td>
* </tr>
* <tr>
* <td style="vertical-align: middle;">
* <code>HOUR, HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND<br></code>
* </td>
* <td style="vertical-align: middle;">
* <code>0<br></code>
* </td>
* </tr>
* </tbody>
* </table>
* <br>Default values are not applicable for the fields not listed above.
*
* <p>
* <strong>Example:</strong>
* <blockquote>
* <pre>
* // get the supported ids for GMT-08:00 (Pacific Standard Time)
* String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
* // if no ids were returned, something is wrong. get out.
* if (ids.length == 0)
* System.exit(0);
*
* // begin output
* System.out.println("Current Time");
*
* // create a Pacific Standard Time time zone
* SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
*
* // set up rules for Daylight Saving Time
* pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
* pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
*
* // create a GregorianCalendar with the Pacific Daylight time zone
* // and the current date and time
* Calendar calendar = new GregorianCalendar(pdt);
* Date trialTime = new Date();
* calendar.setTime(trialTime);
*
* // print out a bunch of interesting things
* System.out.println("ERA: " + calendar.get(Calendar.ERA));
* System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
* System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
* System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
* System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
* System.out.println("DATE: " + calendar.get(Calendar.DATE));
* System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
* System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
* System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
* System.out.println("DAY_OF_WEEK_IN_MONTH: "
* + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
* System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
* System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
* System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
* System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
* System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
* System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
* System.out.println("ZONE_OFFSET: "
* + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000)));
* System.out.println("DST_OFFSET: "
* + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));
* System.out.println("Current Time, with hour reset to 3");
* calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
* calendar.set(Calendar.HOUR, 3);
* System.out.println("ERA: " + calendar.get(Calendar.ERA));
* System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
* System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
* System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
* System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
* System.out.println("DATE: " + calendar.get(Calendar.DATE));
* System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
* System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
* System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
* System.out.println("DAY_OF_WEEK_IN_MONTH: "
* + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
* System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
* System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
* System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
* System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
* System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
* System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
* System.out.println("ZONE_OFFSET: "
* + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); // in hours
* System.out.println("DST_OFFSET: "
* + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))); // in hours
* </pre>
* </blockquote>
*
* @see TimeZone
* @author David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
* @since JDK1.1
*/
/*
* Implementation Notes
*
* The epoch is the number of days or milliseconds from some defined
* starting point. The epoch for java.util.Date is used here; that is,
* milliseconds from January 1, 1970 (Gregorian), midnight UTC. Other
* epochs which are used are January 1, year 1 (Gregorian), which is day 1
* of the Gregorian calendar, and December 30, year 0 (Gregorian), which is
* day 1 of the Julian calendar.
*
* We implement the proleptic Julian and Gregorian calendars. This means we
* implement the modern definition of the calendar even though the
* historical usage differs. For example, if the Gregorian change is set
* to new Date(Long.MIN_VALUE), we have a pure Gregorian calendar which
* labels dates preceding the invention of the Gregorian calendar in 1582 as
* if the calendar existed then.
*
* Likewise, with the Julian calendar, we assume a consistent
* 4-year leap year rule, even though the historical pattern of
* leap years is irregular, being every 3 years from 45 BCE
* through 9 BCE, then every 4 years from 8 CE onwards, with no
* leap years in-between. Thus date computations and functions
* such as isLeapYear() are not intended to be historically
* accurate.
*/
//////////////////
// Class Variables
//////////////////
/**
* Value of the <code>ERA</code> field indicating
* the period before the common era (before Christ), also known as BCE.
* The sequence of years at the transition from <code>BC</code> to <code>AD</code> is
* ..., 2 BC, 1 BC, 1 AD, 2 AD,...
*
* @see #ERA
*/
/**
* Value of the {@link #ERA} field indicating
* the period before the common era, the same value as {@link #BC}.
*
* @see #CE
*/
/**
* Value of the <code>ERA</code> field indicating
* the common era (Anno Domini), also known as CE.
* The sequence of years at the transition from <code>BC</code> to <code>AD</code> is
* ..., 2 BC, 1 BC, 1 AD, 2 AD,...
*
* @see #ERA
*/
/**
* Value of the {@link #ERA} field indicating
* the common era, the same value as {@link #AD}.
*
* @see #BCE
*/
static final int MONTH_LENGTH[]
= {31,28,31,30,31,30,31,31,30,31,30,31}; // 0-based
static final int LEAP_MONTH_LENGTH[]
= {31,29,31,30,31,30,31,31,30,31,30,31}; // 0-based
// Useful millisecond constants. Although ONE_DAY and ONE_WEEK can fit
// into ints, they must be longs in order to prevent arithmetic overflow
// when performing (bug 4173516).
/*
* <pre>
* Greatest Least
* Field name Minimum Minimum Maximum Maximum
* ---------- ------- ------- ------- -------
* ERA 0 0 1 1
* YEAR 1 1 292269054 292278994
* MONTH 0 0 11 11
* WEEK_OF_YEAR 1 1 52* 53
* WEEK_OF_MONTH 0 0 4* 6
* DAY_OF_MONTH 1 1 28* 31
* DAY_OF_YEAR 1 1 365* 366
* DAY_OF_WEEK 1 1 7 7
* DAY_OF_WEEK_IN_MONTH -1 -1 4* 6
* AM_PM 0 0 1 1
* HOUR 0 0 11 11
* HOUR_OF_DAY 0 0 23 23
* MINUTE 0 0 59 59
* SECOND 0 0 59 59
* MILLISECOND 0 0 999 999
* ZONE_OFFSET -13:00 -13:00 14:00 14:00
* DST_OFFSET 0:00 0:00 0:20 2:00
* </pre>
* *: depends on the Gregorian change date
*/
static final int MIN_VALUES[] = {
BCE, // ERA
1, // YEAR
JANUARY, // MONTH
1, // WEEK_OF_YEAR
0, // WEEK_OF_MONTH
1, // DAY_OF_MONTH
1, // DAY_OF_YEAR
SUNDAY, // DAY_OF_WEEK
1, // DAY_OF_WEEK_IN_MONTH
AM, // AM_PM
0, // HOUR
0, // HOUR_OF_DAY
0, // MINUTE
0, // SECOND
0, // MILLISECOND
0 // DST_OFFSET
};
static final int LEAST_MAX_VALUES[] = {
CE, // ERA
292269054, // YEAR
DECEMBER, // MONTH
52, // WEEK_OF_YEAR
4, // WEEK_OF_MONTH
28, // DAY_OF_MONTH
365, // DAY_OF_YEAR
SATURDAY, // DAY_OF_WEEK
4, // DAY_OF_WEEK_IN
PM, // AM_PM
11, // HOUR
23, // HOUR_OF_DAY
59, // MINUTE
59, // SECOND
999, // MILLISECOND
};
static final int MAX_VALUES[] = {
CE, // ERA
292278994, // YEAR
DECEMBER, // MONTH
53, // WEEK_OF_YEAR
6, // WEEK_OF_MONTH
31, // DAY_OF_MONTH
366, // DAY_OF_YEAR
SATURDAY, // DAY_OF_WEEK
6, // DAY_OF_WEEK_IN
PM, // AM_PM
11, // HOUR
23, // HOUR_OF_DAY
59, // MINUTE
59, // SECOND
999, // MILLISECOND
};
// Proclaim serialization compatibility with JDK 1.1
// Reference to the sun.util.calendar.Gregorian instance (singleton).
// Reference to the JulianCalendar instance (singleton), set as needed. See
// getJulianCalendarSystem().
// JulianCalendar eras. See getJulianCalendarSystem().
// The default value of gregorianCutover.
/////////////////////
// Instance Variables
/////////////////////
/**
* The point at which the Gregorian calendar rules are used, measured in
* milliseconds from the standard epoch. Default is October 15, 1582
* (Gregorian) 00:00:00 UTC or -12219292800000L. For this value, October 4,
* 1582 (Julian) is followed by October 15, 1582 (Gregorian). This
* corresponds to Julian day number 2299161.
* @serial
*/
/**
* The fixed date of the gregorianCutover.
*/
private transient long gregorianCutoverDate =
/**
* The normalized year of the gregorianCutover in Gregorian, with
* 0 representing 1 BCE, -1 representing 2 BCE, etc.
*/
/**
* The normalized year of the gregorianCutover in Julian, with 0
* representing 1 BCE, -1 representing 2 BCE, etc.
*/
/**
* gdate always has a sun.util.calendar.Gregorian.Date instance to
* avoid overhead of creating it. The assumption is that most
* applications will need only Gregorian calendar calculations.
*/
/**
* Reference to either gdate or a JulianCalendar.Date
* instance. After calling complete(), this value is guaranteed to
* be set.
*/
/**
* The CalendarSystem used to calculate the date in cdate. After
* calling complete(), this value is guaranteed to be set and
* consistent with the cdate value.
*/
/**
* Temporary int[2] to get time zone offsets. zoneOffsets[0] gets
* the GMT offset value and zoneOffsets[1] gets the DST saving
* value.
*/
private transient int[] zoneOffsets;
/**
* Temporary storage for saving original fields[] values in
* non-lenient mode.
*/
private transient int[] originalFields;
///////////////
// Constructors
///////////////
/**
* Constructs a default <code>GregorianCalendar</code> using the current time
* in the default time zone with the default locale.
*/
public GregorianCalendar() {
setZoneShared(true);
}
/**
* Constructs a <code>GregorianCalendar</code> based on the current time
* in the given time zone with the default locale.
*
* @param zone the given time zone.
*/
}
/**
* Constructs a <code>GregorianCalendar</code> based on the current time
* in the default time zone with the given locale.
*
* @param aLocale the given locale.
*/
setZoneShared(true);
}
/**
* Constructs a <code>GregorianCalendar</code> based on the current time
* in the given time zone with the given locale.
*
* @param zone the given time zone.
* @param aLocale the given locale.
*/
}
/**
* Constructs a <code>GregorianCalendar</code> with the given date set
* in the default time zone with the default locale.
*
* @param year the value used to set the <code>YEAR</code> calendar field in the calendar.
* @param month the value used to set the <code>MONTH</code> calendar field in the calendar.
* Month value is 0-based. e.g., 0 for January.
* @param dayOfMonth the value used to set the <code>DAY_OF_MONTH</code> calendar field in the calendar.
*/
}
/**
* Constructs a <code>GregorianCalendar</code> with the given date
* and time set for the default time zone with the default locale.
*
* @param year the value used to set the <code>YEAR</code> calendar field in the calendar.
* @param month the value used to set the <code>MONTH</code> calendar field in the calendar.
* Month value is 0-based. e.g., 0 for January.
* @param dayOfMonth the value used to set the <code>DAY_OF_MONTH</code> calendar field in the calendar.
* @param hourOfDay the value used to set the <code>HOUR_OF_DAY</code> calendar field
* in the calendar.
* @param minute the value used to set the <code>MINUTE</code> calendar field
* in the calendar.
*/
int minute) {
}
/**
* Constructs a GregorianCalendar with the given date
* and time set for the default time zone with the default locale.
*
* @param year the value used to set the <code>YEAR</code> calendar field in the calendar.
* @param month the value used to set the <code>MONTH</code> calendar field in the calendar.
* Month value is 0-based. e.g., 0 for January.
* @param dayOfMonth the value used to set the <code>DAY_OF_MONTH</code> calendar field in the calendar.
* @param hourOfDay the value used to set the <code>HOUR_OF_DAY</code> calendar field
* in the calendar.
* @param minute the value used to set the <code>MINUTE</code> calendar field
* in the calendar.
* @param second the value used to set the <code>SECOND</code> calendar field
* in the calendar.
*/
}
/**
* Constructs a <code>GregorianCalendar</code> with the given date
* and time set for the default time zone with the default locale.
*
* @param year the value used to set the <code>YEAR</code> calendar field in the calendar.
* @param month the value used to set the <code>MONTH</code> calendar field in the calendar.
* Month value is 0-based. e.g., 0 for January.
* @param dayOfMonth the value used to set the <code>DAY_OF_MONTH</code> calendar field in the calendar.
* @param hourOfDay the value used to set the <code>HOUR_OF_DAY</code> calendar field
* in the calendar.
* @param minute the value used to set the <code>MINUTE</code> calendar field
* in the calendar.
* @param second the value used to set the <code>SECOND</code> calendar field
* in the calendar.
* @param millis the value used to set the <code>MILLISECOND</code> calendar field
*/
super();
// Set AM_PM and HOUR here to set their stamp values before
// setting HOUR_OF_DAY (6178071).
// If hourOfDay is a valid PM hour, set the correct PM values
// so that it won't throw an exception in case it's set to
// non-lenient later.
} else {
// The default value for AM_PM is AM.
// We don't care any out of range value here for leniency.
}
// The stamp values of AM_PM and HOUR must be COMPUTED. (6440854)
// should be changed to set() when this constructor is made
// public.
}
/////////////////
// Public methods
/////////////////
/**
* Sets the <code>GregorianCalendar</code> change date. This is the point when the switch
* from Julian dates to Gregorian dates occurred. Default is October 15,
* 1582 (Gregorian). Previous to this, dates will be in the Julian calendar.
* <p>
* To obtain a pure Julian calendar, set the change date to
* <code>Date(Long.MAX_VALUE)</code>. To obtain a pure Gregorian calendar,
* set the change date to <code>Date(Long.MIN_VALUE)</code>.
*
* @param date the given Gregorian cutover date.
*/
if (cutoverTime == gregorianCutover) {
return;
}
// Before changing the cutover date, make sure to have the
// time of this calendar.
complete();
}
+ EPOCH_OFFSET;
// To provide the "pure" Julian calendar as advertised.
// Strictly speaking, the last millisecond should be a
// Gregorian date. However, the API doc specifies that setting
// the cutover date to Long.MAX_VALUE will make this calendar
// a pure Julian calendar. (See 4167995)
}
// Set the cutover year (in the Gregorian year numbering)
gregorianCutoverYear = d.getYear();
if (time < gregorianCutover) {
// The field values are no longer valid under the new
// cutover date.
}
}
/**
* Gets the Gregorian Calendar change date. This is the point when the
* switch from Julian dates to Gregorian dates occurred. Default is
* October 15, 1582 (Gregorian). Previous to this, dates will be in the Julian
* calendar.
*
* @return the Gregorian cutover date for this <code>GregorianCalendar</code> object.
*/
return new Date(gregorianCutover);
}
/**
* Determines if the given year is a leap year. Returns <code>true</code> if
* the given year is a leap year. To specify BC year numbers,
* <code>1 - year number</code> must be given. For example, year BC 4 is
* specified as -3.
*
* @param year the given year.
* @return <code>true</code> if the given year is a leap year; <code>false</code> otherwise.
*/
return false;
}
if (year > gregorianCutoverYear) {
}
if (year < gregorianCutoverYearJulian) {
return true; // Julian
}
boolean gregorian;
// If the given year is the Gregorian cutover year, we need to
// determine which calendar system to be applied to February in the year.
} else {
}
}
/**
* Compares this <code>GregorianCalendar</code> to the specified
* <code>Object</code>. The result is <code>true</code> if and
* only if the argument is a <code>GregorianCalendar</code> object
* that represents the same time value (millisecond offset from
* the <a href="Calendar.html#Epoch">Epoch</a>) under the same
* <code>Calendar</code> parameters and Gregorian change date as
* this object.
*
* @param obj the object to compare with.
* @return <code>true</code> if this object is equal to <code>obj</code>;
* <code>false</code> otherwise.
* @see Calendar#compareTo(Calendar)
*/
return obj instanceof GregorianCalendar &&
}
/**
* Generates the hash code for this <code>GregorianCalendar</code> object.
*/
public int hashCode() {
return super.hashCode() ^ (int)gregorianCutoverDate;
}
/**
* 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.
*/
// If amount == 0, do nothing even the given field is out of
// range. This is tested by JCK.
if (amount == 0) {
return; // Do nothing!
}
throw new IllegalArgumentException();
}
// Sync the time and calendar fields.
complete();
if (internalGetEra() == CE) {
if (year > 0) {
} else { // year <= 0
// if year == 0, you get 1 BCE.
}
}
else { // era == BCE
if (year > 0) {
} else { // year <= 0
// if year == 0, you get 1 CE
}
}
int y_amount;
if (month >= 0) {
} else {
}
if (y_amount != 0) {
if (internalGetEra() == CE) {
if (year > 0) {
} else { // year <= 0
// if year == 0, you get 1 BCE
}
}
else { // era == BCE
if (year > 0) {
} else { // year <= 0
// if year == 0, you get 1 CE
}
}
}
if (month >= 0) {
} else {
// month < 0
month %= 12;
if (month < 0) {
month += 12;
}
}
if (era < 0) {
era = 0;
}
if (era > 1) {
era = 1;
}
} else {
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:
break;
case MINUTE:
break;
case SECOND:
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).
break;
}
// The time fields don't require time zone offset change
// adjustment.
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 *= 60;
timeOfDay *= 60;
timeOfDay *= 1000;
fd++;
} else if (timeOfDay < 0) {
fd--;
}
// If the time zone offset has changed, then adjust the difference.
if (zoneOffset != 0) {
long fd2 = getCurrentFixedDate();
// If the adjustment has changed the date, then take
// the previous one.
}
}
}
}
/**
* field without changing larger fields.
* <p>
* <em>Example</em>: Consider a <code>GregorianCalendar</code>
* originally set to December 31, 1999. Calling {@link #roll(int,boolean) roll(Calendar.MONTH, true)}
* sets the calendar to January 31, 1999. The <code>YEAR</code> field is unchanged
* because it is a larger field than <code>MONTH</code>.</p>
*
* @param up indicates if the value of the specified calendar field is to be
* rolled up or rolled down. Use <code>true</code> if rolling up, <code>false</code> otherwise.
* @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.
* @see #add(int,int)
* @see #set(int,int)
*/
}
/**
* Adds a signed amount to the specified calendar field without changing larger fields.
* A negative roll amount means to subtract from field without changing
* larger fields. If the specified amount is 0, this method performs nothing.
*
* <p>This method calls {@link #complete()} before adding the
* amount so that all the calendar fields are normalized. If there
* is any calendar field having an out-of-range value in non-lenient mode, then an
* <code>IllegalArgumentException</code> is thrown.
*
* <p>
* <em>Example</em>: Consider a <code>GregorianCalendar</code>
* originally set to August 31, 1999. Calling <code>roll(Calendar.MONTH,
* 8)</code> sets the calendar to April 30, <strong>1999</strong>. Using a
* <code>GregorianCalendar</code>, the <code>DAY_OF_MONTH</code> field cannot
* be 31 in the month April. <code>DAY_OF_MONTH</code> is set to the closest possible
* value, 30. The <code>YEAR</code> field maintains the value of 1999 because it
* is a larger field than <code>MONTH</code>.
* <p>
* <em>Example</em>: Consider a <code>GregorianCalendar</code>
* originally set to Sunday June 6, 1999. Calling
* <code>roll(Calendar.WEEK_OF_MONTH, -1)</code> sets the calendar to
* Tuesday June 1, 1999, whereas calling
* <code>add(Calendar.WEEK_OF_MONTH, -1)</code> sets the calendar to
* Sunday May 30, 1999. This is because the roll rule imposes an
* additional constraint: The <code>MONTH</code> must not change when the
* <code>WEEK_OF_MONTH</code> is rolled. Taken together with add rule 1,
* the resultant date must be between Tuesday June 1 and Saturday June
* 5. According to add rule 2, the <code>DAY_OF_WEEK</code>, an invariant
* when changing the <code>WEEK_OF_MONTH</code>, is set to Tuesday, the
* closest possible value to Sunday (where Sunday is the first day of the
* week).</p>
*
* @param field the calendar field.
* @param amount the signed amount to add to <code>field</code>.
* @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.
* @see #roll(int,boolean)
* @see #add(int,int)
* @see #set(int,int)
* @since 1.2
*/
// If amount == 0, do nothing even the given field is out of
// range. This is tested by JCK.
if (amount == 0) {
return;
}
throw new IllegalArgumentException();
}
// Sync the time and calendar fields.
complete();
switch (field) {
case AM_PM:
case ERA:
case YEAR:
case MINUTE:
case SECOND:
case MILLISECOND:
// These fields are handled simply, since they have fixed minima
// and maxima. The field DAY_OF_MONTH is almost as simple. Other
// fields are complicated, since the range within they must roll
// varies depending on the date.
break;
case HOUR:
case HOUR_OF_DAY:
{
int h = internalGet(field);
if (nh < 0) {
}
// The day might have changed, which could happen if
// the daylight saving time transition brings it to
// the next day, although it's very unlikely. But we
// have to make sure not to change the larger fields.
}
}
} else {
}
int zoneOffset = d.getZoneOffset();
int saving = d.getDaylightSaving();
return;
}
case MONTH:
// Rolling the month involves both pinning the final value to [0, 11]
// and adjusting the DAY_OF_MONTH if necessary. We only adjust the
// DAY_OF_MONTH if, after updating the MONTH field, it is illegal.
// E.g., <jan31>.roll(MONTH, 1) -> <feb28> or <feb29>.
{
if (mon < 0) {
mon += 12;
}
// Keep the day of month in the range. We don't want to spill over
// into the next month; e.g., we don't want jan31 + 1 mo -> feb31 ->
// mar3.
}
} else {
// We need to take care of different lengths in
// year and month due to the cutover.
if (mon < 0) {
mon += yearLength;
}
}
}
return;
}
case WEEK_OF_YEAR:
{
int y = cdate.getNormalizedYear();
if (!isCutoverYear(y)) {
// If the new value is in between min and max
// (exclusive), then we can use the value.
return;
}
long fd = getCurrentFixedDate();
// Make sure that the min week has the current DAY_OF_WEEK
min++;
}
// Make sure the same thing for the max week
max--;
}
break;
}
// Handle cutover here.
long fd = getCurrentFixedDate();
} else if (y == gregorianCutoverYear) {
} else {
}
// Make sure that the min week has the current DAY_OF_WEEK
min++;
}
// Make sure the same thing for the max week
max--;
}
// value: the new WEEK_OF_YEAR which must be converted
// to month and day of month.
return;
}
case WEEK_OF_MONTH:
{
// dow: relative day of week from first day of week
if (dow < 0) {
dow += 7;
}
long fd = getCurrentFixedDate();
long month1; // fixed date of the first day (usually 1) of the month
int monthLength; // actual month length
if (isCutoverYear) {
} else {
}
// the first day of week of the month.
// if the week has enough days to form a week, the
// week starts from the previous month.
monthDay1st -= 7;
}
// value: the new WEEK_OF_MONTH value
// 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.
}
int dayOfMonth;
if (isCutoverYear) {
// If we are in the cutover year, convert nfd to
// its calendar date and use dayOfMonth.
dayOfMonth = d.getDayOfMonth();
} else {
}
return;
}
case DAY_OF_MONTH:
{
break;
}
// Cutover year handling
long fd = getCurrentFixedDate();
// 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.
return;
}
case DAY_OF_YEAR:
{
break;
}
// Handle cutover here.
long fd = getCurrentFixedDate();
return;
}
case DAY_OF_WEEK:
{
// If the week of year is in the same year, we can
// just change DAY_OF_WEEK.
break;
}
}
// We need to handle it in a different way around year
// boundaries and in the cutover year. Note that
// changing era and year values violates the roll
// rule: not changing larger calendar fields...
amount %= 7;
if (amount == 0) {
return;
}
long fd = getCurrentFixedDate();
fd += 7;
fd -= 7;
}
return;
}
case DAY_OF_WEEK_IN_MONTH:
{
if (x < lastDays) {
max++;
}
break;
}
// Cutover year handling
long fd = getCurrentFixedDate();
int monthLength = actualMonthLength();
if (x < lastDays) {
max++;
}
return;
}
}
}
/**
* Returns the minimum value for the given calendar field of this
* <code>GregorianCalendar</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},
* {@link #getGregorianChange() getGregorianChange} and
* {@link Calendar#getTimeZone() getTimeZone} methods.
*
* @param field the calendar field.
* @return the minimum value for the given calendar field.
* @see #getMaximum(int)
* @see #getGreatestMinimum(int)
* @see #getLeastMaximum(int)
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
return MIN_VALUES[field];
}
/**
* 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},
* {@link #getGregorianChange() getGregorianChange} and
* {@link Calendar#getTimeZone() getTimeZone} methods.
*
* @param field the calendar field.
* @return the maximum value for the given calendar field.
* @see #getMinimum(int)
* @see #getGreatestMinimum(int)
* @see #getLeastMaximum(int)
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
switch (field) {
case MONTH:
case DAY_OF_MONTH:
case DAY_OF_YEAR:
case WEEK_OF_YEAR:
case WEEK_OF_MONTH:
case DAY_OF_WEEK_IN_MONTH:
case YEAR:
{
// On or after Gregorian 200-3-1, Julian and Gregorian
// calendar dates are the same or Gregorian dates are
// larger (i.e., there is a "gap") after 300-3-1.
if (gregorianCutoverYear > 200) {
break;
}
// There might be "overlapping" dates.
gc.setLenient(true);
}
}
return MAX_VALUES[field];
}
/**
* 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},
* {@link #getGregorianChange() getGregorianChange} and
* {@link Calendar#getTimeZone() getTimeZone} methods.
*
* @param field the calendar field.
* @return the highest minimum value for the given calendar field.
* @see #getMinimum(int)
* @see #getMaximum(int)
* @see #getLeastMaximum(int)
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
if (field == DAY_OF_MONTH) {
d = getCalendarDate(mon1);
}
return MIN_VALUES[field];
}
/**
* 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},
* {@link #getGregorianChange() getGregorianChange} and
* {@link Calendar#getTimeZone() getTimeZone} methods.
*
* @param field the calendar field
* @return the lowest maximum value for the given calendar field.
* @see #getMinimum(int)
* @see #getMaximum(int)
* @see #getGreatestMinimum(int)
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
switch (field) {
case MONTH:
case DAY_OF_MONTH:
case DAY_OF_YEAR:
case WEEK_OF_YEAR:
case WEEK_OF_MONTH:
case DAY_OF_WEEK_IN_MONTH:
case YEAR:
{
gc.setLenient(true);
}
}
return LEAST_MAX_VALUES[field];
}
/**
* Returns the minimum value that this calendar field could have,
* taking into consideration the given time value and the current
* values of the
* {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek},
* {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek},
* {@link #getGregorianChange() getGregorianChange} and
* {@link Calendar#getTimeZone() getTimeZone} methods.
*
* <p>For example, if the Gregorian change date is January 10,
* 1970 and the date of this <code>GregorianCalendar</code> is
* January 20, 1970, the actual minimum value of the
* <code>DAY_OF_MONTH</code> field is 10 because the previous date
* of January 10, 1970 is December 27, 1996 (in the Julian
* calendar). Therefore, December 28, 1969 to January 9, 1970
* don't exist.
*
* @param field the calendar field
* @return the minimum of the given field for the time value of
* this <code>GregorianCalendar</code>
* @see #getMinimum(int)
* @see #getMaximum(int)
* @see #getGreatestMinimum(int)
* @see #getLeastMaximum(int)
* @see #getActualMaximum(int)
* @since 1.2
*/
if (field == DAY_OF_MONTH) {
return d.getDayOfMonth();
}
}
return getMinimum(field);
}
/**
* Returns the maximum value that this calendar field could have,
* taking into consideration the given time value and the current
* values of the
* {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek},
* {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek},
* {@link #getGregorianChange() getGregorianChange} and
* {@link Calendar#getTimeZone() getTimeZone} methods.
* For example, if the date of this instance is February 1, 2004,
* the actual maximum value of the <code>DAY_OF_MONTH</code> field
* is 29 because 2004 is a leap year, and if the date of this
* instance is February 1, 2005, it's 28.
*
* <p>This method calculates the maximum value of {@link
* Calendar#WEEK_OF_YEAR WEEK_OF_YEAR} based on the {@link
* Calendar#YEAR YEAR} (calendar year) value, not the <a
* href="#week_year">week year</a>. Call {@link
* #getWeeksInWeekYear()} to get the maximum value of {@code
* WEEK_OF_YEAR} in the week year of this {@code GregorianCalendar}.
*
* @param field the calendar field
* @return the maximum of the given field for the time value of
* this <code>GregorianCalendar</code>
* @see #getMinimum(int)
* @see #getMaximum(int)
* @see #getGreatestMinimum(int)
* @see #getLeastMaximum(int)
* @see #getActualMinimum(int)
* @since 1.2
*/
return getMaximum(field);
}
int value = -1;
switch (field) {
case MONTH:
{
break;
}
// January 1 of the next year may or may not exist.
long nextJan1;
do {
} while (nextJan1 < gregorianCutoverDate);
}
break;
case DAY_OF_MONTH:
{
break;
}
// Handle cutover year.
if (fd >= gregorianCutoverDate) {
break;
}
// Convert the fixed date to its calendar date.
value = d.getDayOfMonth();
}
break;
case DAY_OF_YEAR:
{
break;
}
// Handle cutover year.
long jan1;
} else if (normalizedYear == gregorianCutoverYearJulian) {
} else {
}
// January 1 of the next year may or may not exist.
if (nextJan1 < gregorianCutoverDate) {
}
}
break;
case WEEK_OF_YEAR:
{
// Get the day of week of January 1 of the year
// Normalize the day of week with the firstDayOfWeek value
dayOfWeek -= getFirstDayOfWeek();
if (dayOfWeek < 0) {
dayOfWeek += 7;
}
value = 52;
if ((magic == 6) ||
value++;
}
break;
}
if (gc == this) {
}
}
}
break;
case WEEK_OF_MONTH:
{
dayOfWeek -= getFirstDayOfWeek();
if (dayOfWeek < 0) {
dayOfWeek += 7;
}
value = 3;
if (nDaysFirstWeek >= getMinimalDaysInFirstWeek()) {
value++;
}
if (monthLength > 0) {
value++;
if (monthLength > 7) {
value++;
}
}
break;
}
// Cutover year handling
if (gc == this) {
}
do {
}
break;
case DAY_OF_WEEK_IN_MONTH:
{
// may be in the Gregorian cutover month
d.setDayOfMonth(1);
dow1 = d.getDayOfWeek();
} else {
// Let a cloned GregorianCalendar take care of the cutover cases.
if (gc == this) {
}
}
if (x < 0) {
x += 7;
}
ndays -= x;
}
break;
case YEAR:
/* The year computation is no different, in principle, from the
* others, however, the range of possible maxima is large. In
* addition, the way we know we've exceeded the range is different.
* For these reasons, we use the special case code below to handle
* this field.
*
* The actual maxima for YEAR depend on the type of calendar:
*
* Gregorian = May 17, 292275056 BCE - Aug 17, 292278994 CE
* Julian = Dec 2, 292269055 BCE - Jan 3, 292272993 CE
* Hybrid = Dec 2, 292269055 BCE - Aug 17, 292278994 CE
*
* We know we've exceeded the maximum when either the month, date,
* time, or era changes in response to setting the year. We don't
* check for month, date, and time here because the year and era are
* sufficient to detect an invalid year setting. NOTE: If code is
* added to check the month and date in the future for some reason,
* Feb 29 must be allowed to shift to Mar 1 when setting the year.
*/
{
if (gc == this) {
}
// Calculate the millisecond offset from the beginning
// of the year of this calendar and adjust the max
// year value if we are beyond the limit in the max
// year.
value--;
}
} else {
maxEnd *= 60;
maxEnd += d.getMinutes();
maxEnd *= 60;
maxEnd += d.getSeconds();
maxEnd *= 1000;
if (value <= 0) {
}
value--;
}
}
}
break;
default:
throw new ArrayIndexOutOfBoundsException(field);
}
return value;
}
/**
* Returns the millisecond offset from the beginning of this
* year. This Calendar object must have been normalized.
*/
private final long getYearOffsetInMillis() {
t += internalGet(HOUR_OF_DAY);
t *= 60;
t += internalGet(MINUTE);
t *= 60;
t += internalGet(SECOND);
t *= 1000;
return t + internalGet(MILLISECOND) -
}
{
} else {
}
}
return other;
}
// To share the zone by CalendarDates
}
return zone;
}
super.setTimeZone(zone);
// To share the zone by CalendarDates
}
}
/**
* Returns {@code true} indicating this {@code GregorianCalendar}
* supports week dates.
*
* @return {@code true} (always)
* @see #getWeekYear()
* @see #setWeekDate(int,int,int)
* @see #getWeeksInWeekYear()
* @since 1.7
*/
public final boolean isWeekDateSupported() {
return true;
}
/**
* Returns the <a href="#week_year">week year</a> represented by this
* {@code GregorianCalendar}. The dates in the weeks between 1 and the
* maximum week number of the week year have the same week year value
* that may be one year before or after the {@link Calendar#YEAR YEAR}
* (calendar year) value.
*
* <p>This method calls {@link Calendar#complete()} before
* calculating the week year.
*
* @return the week year represented by this {@code GregorianCalendar}.
* If the {@link Calendar#ERA ERA} value is {@link #BC}, the year is
* represented by 0 or a negative number: BC 1 is 0, BC 2
* is -1, BC 3 is -2, and so on.
* @throws IllegalArgumentException
* if any of the calendar fields is invalid in non-lenient mode.
* @see #isWeekDateSupported()
* @see #getWeeksInWeekYear()
* @see Calendar#getFirstDayOfWeek()
* @see Calendar#getMinimalDaysInFirstWeek()
* @since 1.7
*/
public int getWeekYear() {
if (internalGetEra() == BCE) {
}
// Fast path for the Gregorian calendar years that are never
// affected by the Julian-Gregorian transition
if (weekOfYear >= 52) {
--year;
}
} else {
if (weekOfYear == 1) {
++year;
}
}
return year;
}
// General (slow) path
int minimalDays = getMinimalDaysInFirstWeek();
// Quickly check the possibility of year adjustments before
// cloning this GregorianCalendar.
return year;
}
// Create a clone to work on the calculation
cal.setLenient(true);
// Use GMT so that intermediate date calculations won't
// affect the time of day fields.
// Go to the first day of the year, which is usually January 1.
// Get the first day of the first day-of-week in the year.
if (delta != 0) {
if (delta < 0) {
delta += 7;
}
}
if (dayOfYear < minDayOfYear) {
if (minDayOfYear <= minimalDays) {
--year;
}
} else {
if (del != 0) {
if (del < 0) {
del += 7;
}
}
if (minDayOfYear == 0) {
minDayOfYear = 7;
}
if (minDayOfYear >= minimalDays) {
++year;
}
}
}
return year;
}
/**
* Sets this {@code GregorianCalendar} to the date given by the
* date specifiers - <a href="#week_year">{@code weekYear}</a>,
* {@code weekOfYear}, and {@code dayOfWeek}. {@code weekOfYear}
* follows the <a href="#week_and_year">{@code WEEK_OF_YEAR}
* numbering</a>. The {@code dayOfWeek} value must be one of the
* {@link Calendar#DAY_OF_WEEK DAY_OF_WEEK} values: {@link
* Calendar#SUNDAY SUNDAY} to {@link Calendar#SATURDAY SATURDAY}.
*
* <p>Note that the numeric day-of-week representation differs from
* the ISO 8601 standard, and that the {@code weekOfYear}
* numbering is compatible with the standard when {@code
* getFirstDayOfWeek()} is {@code MONDAY} and {@code
* getMinimalDaysInFirstWeek()} is 4.
*
* <p>Unlike the {@code set} method, all of the calendar fields
* and the instant of time value are calculated upon return.
*
* <p>If {@code weekOfYear} is out of the valid week-of-year
* range in {@code weekYear}, the {@code weekYear}
* and {@code weekOfYear} values are adjusted in lenient
* mode, or an {@code IllegalArgumentException} is thrown in
* non-lenient mode.
*
* @param weekYear the week year
* @param weekOfYear the week number based on {@code weekYear}
* @param dayOfWeek the day of week value: one of the constants
* for the {@link #DAY_OF_WEEK DAY_OF_WEEK} field:
* {@link Calendar#SUNDAY SUNDAY}, ...,
* {@link Calendar#SATURDAY SATURDAY}.
* @exception IllegalArgumentException
* if any of the given date specifiers is invalid,
* or if any of the calendar fields are inconsistent
* with the given date specifiers in non-lenient mode
* @see GregorianCalendar#isWeekDateSupported()
* @see Calendar#getFirstDayOfWeek()
* @see Calendar#getMinimalDaysInFirstWeek()
* @since 1.7
*/
}
// To avoid changing the time of day fields by date
// calculations, use a clone with the GMT time zone.
gc.setLenient(true);
if (days < 0) {
days += 7;
}
if (days != 0) {
} else {
}
if (!isLenient() &&
throw new IllegalArgumentException();
}
// to avoid throwing an IllegalArgumentException in
// non-lenient, set WEEK_OF_YEAR internally
complete();
}
/**
* Returns the number of weeks in the <a href="#week_year">week year</a>
* represented by this {@code GregorianCalendar}.
*
* <p>For example, if this {@code GregorianCalendar}'s date is
* December 31, 2008 with <a href="#iso8601_compatible_setting">the ISO
* 8601 compatible setting</a>, this method will return 53 for the
* period: December 29, 2008 to January 3, 2010 while {@link
* #getActualMaximum(int) getActualMaximum(WEEK_OF_YEAR)} will return
* 52 for the period: December 31, 2007 to December 28, 2008.
*
* @return the number of weeks in the week year.
* @see Calendar#WEEK_OF_YEAR
* @see #getWeekYear()
* @see #getActualMaximum(int)
* @since 1.7
*/
public int getWeeksInWeekYear() {
}
// Use the 2nd week for calculating the max of WEEK_OF_YEAR
if (gc == this) {
}
}
/////////////////////////////
// Time => Fields computation
/////////////////////////////
/**
* The fixed date corresponding to gdate. If the value is
* Long.MIN_VALUE, the fixed date value is unknown. Currently,
* Julian calendar dates are not cached.
*/
/**
* 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.
*
* @see Calendar#complete
*/
protected void computeFields() {
int mask = 0;
if (isPartiallyNormalized()) {
// Determine which calendar fields need to be computed.
mask = getSetStateFields();
// We have to call computTime in case calsys == null in
// order to set calsys and cdate. (6263644)
assert mask == ALL_FIELDS;
}
} else {
mask = ALL_FIELDS;
}
// 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
* the setting state.
* @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
* actually been set.
*/
int zoneOffset = 0;
if (zoneOffsets == null) {
zoneOffsets = new int[2];
}
} else {
}
}
if (tzMask != 0) {
}
}
}
// By computing time and zoneOffset separately, we can take
// the wider range of time+zoneOffset than the previous
// implementation.
++fixedDate;
} else {
while (timeOfDay < 0) {
--fixedDate;
}
}
int year;
if (fixedDate >= gregorianCutoverDate) {
// Handle Gregorian dates.
: "cache control: not normalized";
: "cache control: inconsictency" +
", cachedFixedDate=" + cachedFixedDate +
", computed=" +
gdate) +
", date=" + gdate;
// See if we can use gdate to avoid date calculation.
if (fixedDate != cachedFixedDate) {
}
if (year <= 0) {
}
} else {
// Handle Julian calendar dates.
if (e == jeras[0]) {
}
}
// Always set the ERA and YEAR values.
// Set the basic date fields.
!= 0) {
}
if (timeOfDay != 0) {
r %= ONE_MINUTE;
} else {
}
}
}
if ((fieldMask & (DAY_OF_YEAR_MASK|WEEK_OF_YEAR_MASK|WEEK_OF_MONTH_MASK|DAY_OF_WEEK_IN_MONTH_MASK)) != 0) {
int cutoverGap = 0;
// If we are in the cutover year, we need some special handling.
if (normalizedYear == cutoverYear) {
// Need to take care of the "missing" days.
// We need to find out where we are. The cutover
// gap could even be more than one year. (One
// year difference in ~48667 years.)
if (fixedDate >= gregorianCutoverDate) {
}
}
}
// The spec is to calculate WEEK_OF_YEAR in the
// ISO8601-style. This creates problems, though.
if (weekOfYear == 0) {
// 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
// the Gregorian cutover year, we need to take care of
// it. Usually the previous day of January 1 is
// December 31, which is not always true in
// GregorianCalendar.
--prevJan1;
}
} else if (normalizedYear <= gregorianCutoverYearJulian) {
--prevJan1;
}
} else {
//int prevYear = normalizedYear - 1;
if (prevYear == gregorianCutoverYear) {
if (calForJan1 == jcal) {
1,
null);
} else {
calForJan1 = gcal;
}
} else if (prevYear <= gregorianCutoverYearJulian) {
1,
null);
}
}
} else {
if (normalizedYear > gregorianCutoverYear ||
// Regular years
if (weekOfYear >= 52) {
if (cdate.isLeapYear()) {
nextJan1++;
}
// The first days forms a week in which the date is included.
weekOfYear = 1;
}
}
} else {
// In case the gap is more than one year.
}
if (nextYear == gregorianCutoverYear) {
}
long nextJan1;
if (nextYear > gregorianCutoverYear
|| nextYear == gregorianCutoverYearJulian) {
1,
null);
} else {
calForJan1 = gcal;
}
// The first days forms a week in which the date is included.
weekOfYear = 1;
}
}
}
}
return mask;
}
/**
* 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 `gcal' since Julian and Gregorian are the
// same thing for this calculation.
assert ndays <= 7;
if (ndays >= getMinimalDaysInFirstWeek()) {
fixedDay1st -= 7;
}
if (normalizedDayOfPeriod >= 0) {
}
}
/**
* Converts calendar field values to the time value (millisecond
* offset from the <a href="Calendar.html#Epoch">Epoch</a>).
*
* @exception IllegalArgumentException if any calendar fields are invalid.
*/
protected void computeTime() {
// 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.
if (!isLenient()) {
if (originalFields == null) {
originalFields = new int[FIELD_COUNT];
}
if (isExternallySet(field)) {
// Quick validation for any out of range values
}
}
}
}
// Let the super class determine which calendar fields to be
// used to calculate the time.
int fieldMask = selectFields();
// The year defaults to the epoch start. We don't check
// fieldMask for YEAR because YEAR is a mandatory field to
// determine the date.
int era = internalGetEra();
// Even in lenient mode we disallow ERA values other than CE & BCE.
// (The same normalization rule as add()/roll() could be
// applied here in lenient mode. But this checking is kept
// unchanged for compatibility as of 1.5.)
throw new IllegalArgumentException("Invalid era");
}
// If year is 0 or negative, we need to set the ERA value later.
}
// Calculate the time of day. We rely on the convention that
// an UNSET field has 0.
long timeOfDay = 0;
} else {
// The default value of AM_PM is 0 which designates AM.
}
}
timeOfDay *= 60;
timeOfDay *= 60;
timeOfDay *= 1000;
// Convert the time of day to the number of days and the
// millisecond offset from midnight.
while (timeOfDay < 0) {
--fixedDate;
}
// Calculate the fixed date since January 1, 1 (Gregorian).
if (gfd >= gregorianCutoverDate) {
break calculateFixedDate;
}
if (jfd < gregorianCutoverDate) {
break calculateFixedDate;
}
} else {
}
// Now we have to determine which calendar date it is.
// If the date is relative from the beginning of the year
// in the Julian calendar, then use jfd;
break calculateFixedDate;
} else if (year == gregorianCutoverYear) {
break calculateFixedDate;
}
}
if (gfd >= gregorianCutoverDate) {
if (jfd >= gregorianCutoverDate) {
} else {
// The date is in an "overlapping" period. No way
// to disambiguate it. Determine it using the
// previous date calculation.
} else {
}
}
} else {
if (jfd < gregorianCutoverDate) {
} else {
// The date is in a "missing" period.
if (!isLenient()) {
throw new IllegalArgumentException("the specified date doesn't exist");
}
// Take the Julian date for compatibility, which
// will produce a Gregorian date.
}
}
}
// 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.
if (zoneOffsets == null) {
zoneOffsets = new int[2];
}
} else {
}
}
if (tzMask != 0) {
}
}
}
// Adjust the time zone offset values to get the UTC time.
// Set this calendar's time in milliseconds
if (!isLenient()) {
if (!isExternallySet(field)) {
continue;
}
// 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
* @return the fixed date
* @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
month %= 12;
int[] rem = new int[1];
}
}
// 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. 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 1st.
if (isSet(DAY_OF_MONTH)) {
// To avoid underflow with DAY_OF_MONTH-1, add
// DAY_OF_MONTH, then subtract 1.
fixedDate--;
}
} else {
// If we have enough days in the first week, then
// move to the previous week.
firstDayOfWeek -= 7;
}
}
// In lenient mode, we treat days of the previous
// months as a part of the specified
// WEEK_OF_MONTH. See 4633646.
} else {
int dayOfWeek;
} else {
}
// We are basing this on the day-of-week-in-month. The only
// trickiness occurs if the day-of-week-in-month is
// negative.
int dowim;
} else {
dowim = 1;
}
if (dowim >= 0) {
} else {
// 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.
}
}
}
} else {
// January 1 of the year doesn't exist. Use
// gregorianCutoverDate as the first day of the
// year.
}
// We are on the first day of the year.
// Add the offset, then subtract 1. (Make sure to avoid underflow.)
fixedDate--;
} else {
// If we have enough days in the first week, then move
// to the previous week.
firstDayOfWeek -= 7;
}
if (dayOfWeek != getFirstDayOfWeek()) {
}
}
}
}
return fixedDate;
}
/**
* 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.
*/
if (isFullyNormalized()) {
gc = this;
} else {
// Create a clone and normalize the calendar fields
gc.setLenient(true);
}
return gc;
}
/**
* Returns the Julian calendar system instance (singleton). 'jcal'
* and 'jeras' are set upon the return.
*/
}
return jcal;
}
/**
* Returns the calendar system for dates before the cutover date
* in the cutover year. If the cutover date is January 1, the
* method returns Gregorian. Otherwise, Julian.
*/
return gcal;
}
return getJulianCalendarSystem();
}
/**
* Determines if the specified year (normalized) is the Gregorian
* cutover year. This object must have been normalized.
*/
return normalizedYear == cutoverYear;
}
/**
* 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 (Gregorian
* or Julian).
* @param fixedDate the fixed date representation of the date
*/
if (fixedDate >= gregorianCutoverDate) {
// Dates before the cutover date don't exist
// in the same (Gregorian) year. So, no
// January 1 exists in the year. Use the
// cutover date as the first day of the year.
return gregorianCutoverDate;
}
}
// January 1 of the normalized year should exist.
}
/**
* 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 has to be in the cut-over year (Gregorian
* or Julian).
* @param fixedDate the fixed date representation of the date
*/
// The cutover happened on January 1.
}
long fixedDateMonth1;
// The cutover happened sometime during the year.
// The cutover happened in the month.
// The "gap" fits in the same month.
1,
null);
} else {
// Use the cutover date as the first day of the month.
}
} else {
// The cutover happened before the month.
}
return fixedDateMonth1;
}
/**
* Returns a CalendarDate produced from the specified fixed date.
*
* @param fd the fixed date
*/
return d;
}
/**
* Returns the Gregorian cutover date as a BaseCalendar.Date. The
* date is a Gregorian date.
*/
return getCalendarDate(gregorianCutoverDate);
}
/**
* Returns the day before the Gregorian cutover date as a
* BaseCalendar.Date. The date is a Julian date.
*/
}
/**
* Returns the length of the specified month in the specified
* year. The year number must be normalized.
*
* @see #isLeapYear(int)
*/
}
/**
* Returns the length of the specified month in the year provided
* by internalGet(YEAR).
*
* @see #isLeapYear(int)
*/
if (internalGetEra() == BCE) {
}
}
private final int actualMonthLength() {
}
if (next1 < gregorianCutoverDate) {
}
}
}
/**
* Returns the length (in days) of the specified year. The year
* must be normalized.
*/
}
/**
* Returns the length (in days) of the year provided by
* internalGet(YEAR).
*/
private final int yearLength() {
if (internalGetEra() == BCE) {
}
return yearLength(year);
}
/**
* 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.
*/
private final void pinDayOfMonth() {
int monthLen;
} else {
}
}
}
/**
* Returns the fixed date value of this object. The time value and
* calendar fields must be in synch.
*/
private final long getCurrentFixedDate() {
}
/**
* Returns the new value after 'roll'ing the specified value and amount.
*/
if (n > max) {
n -= range;
} else if (n < min) {
n += range;
}
return n;
}
/**
* Returns the ERA. We need a special method for this because the
* default ERA is CE, but a zero (unset) ERA is BCE.
*/
private final int internalGetEra() {
}
/**
* Updates internal state.
*/
throws IOException, ClassNotFoundException {
}
}
}