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