/*
* 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.
*/
/**
* The <code>BaseCalendar</code> provides basic calendar calculation
* functions to support the Julian, Gregorian, and Gregorian-based
* calendar systems.
*
* @author Masayoshi Okutsu
* @since 1.5
*/
// day of week constants
// The base Gregorian year of FIXED_DATES[]
// Pre-calculated fixed dates of January 1 from BASE_YEAR
// (Gregorian). This table covers all the years that can be
// supported by the POSIX time_t (32-bit) after the Epoch. Note
// that the data type is int[].
private static final int[] FIXED_DATES = {
719163, // 1970
719528, // 1971
719893, // 1972
720259, // 1973
720624, // 1974
720989, // 1975
721354, // 1976
721720, // 1977
722085, // 1978
722450, // 1979
722815, // 1980
723181, // 1981
723546, // 1982
723911, // 1983
724276, // 1984
724642, // 1985
725007, // 1986
725372, // 1987
725737, // 1988
726103, // 1989
726468, // 1990
726833, // 1991
727198, // 1992
727564, // 1993
727929, // 1994
728294, // 1995
728659, // 1996
729025, // 1997
729390, // 1998
729755, // 1999
730120, // 2000
730486, // 2001
730851, // 2002
731216, // 2003
731581, // 2004
731947, // 2005
732312, // 2006
732677, // 2007
733042, // 2008
733408, // 2009
733773, // 2010
734138, // 2011
734503, // 2012
734869, // 2013
735234, // 2014
735599, // 2015
735964, // 2016
736330, // 2017
736695, // 2018
737060, // 2019
737425, // 2020
737791, // 2021
738156, // 2022
738521, // 2023
738886, // 2024
739252, // 2025
739617, // 2026
739982, // 2027
740347, // 2028
740713, // 2029
741078, // 2030
741443, // 2031
741808, // 2032
742174, // 2033
742539, // 2034
742904, // 2035
743269, // 2036
743635, // 2037
744000, // 2038
744365, // 2039
};
protected Date() {
super();
}
super(zone);
}
return this;
}
public abstract int getNormalizedYear();
// Cache for the fixed date of January 1 and year length of the
// cachedYear. A simple benchmark showed 7% performance
// improvement with >90% cache hit. The initial values are for Gregorian.
return year == cachedYear;
}
return (fixedDate >= cachedFixedDateJan1 &&
}
protected int getCachedYear() {
return cachedYear;
}
protected long getCachedJan1() {
return cachedFixedDateJan1;
}
cachedYear = year;
}
}
if (bdate.isNormalized()) {
return true;
}
return false;
}
int d = bdate.getDayOfMonth();
return false;
}
return false;
}
if (!validateTime(date)) {
return false;
}
bdate.setNormalized(true);
return true;
}
if (date.isNormalized()) {
return true;
}
// If the date has a time zone, then we need to recalculate
// the calendar fields. Let getTime() do it.
return true;
}
int y = bdate.getNormalizedYear();
int ml = getMonthLength(y, m);
if (!(d > 0 && d <= ml)) {
if (d <= 0 && d > -28) {
ml = getMonthLength(y, --m);
d += ml;
bdate.setDayOfMonth((int) d);
if (m == 0) {
m = DECEMBER;
}
d -= ml;
++m;
bdate.setDayOfMonth((int)d);
if (m > DECEMBER) {
m = JANUARY;
}
} else {
}
} else {
}
bdate.setNormalized(true);
return true;
}
if (month <= 0) {
}
}
/**
* Returns 366 if the specified date is in a leap year, or 365
* otherwise This method does not perform the normalization with
* the specified <code>CalendarDate</code>. The
* <code>CalendarDate</code> must be normalized to get a correct
* value.
*
* @param a <code>CalendarDate</code>
* @return a year length in days
* @throws ClassCastException if the specified date is not a
* {@link BaseCalendar.Date}
*/
}
return 12;
}
static final int[] DAYS_IN_MONTH
// 12 1 2 3 4 5 6 7 8 9 10 11 12
= { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static final int[] ACCUMULATED_DAYS_IN_MONTH
// 12/1 1/1 2/1 3/1 4/1 5/1 6/1 7/1 8/1 9/1 10/1 11/1 12/1
= { -30, 0, 31, 59, 90,120,151,181,212,243, 273, 304, 334};
static final int[] ACCUMULATED_DAYS_IN_MONTH_LEAP
// 12/1 1/1 2/1 3/1 4/1 5/1 6/1 7/1 8/1 9/1 10/1 11/1 12/1
= { -30, 0, 31, 59+1, 90+1,120+1,151+1,181+1,212+1,243+1, 273+1, 304+1, 334+1};
}
}
// accepts 0 (December in the previous year) to 12.
days++;
}
return days;
}
date.getDayOfMonth());
}
return (long) dayOfMonth
+ (isLeapYear(year) ?
}
// protected
if (!date.isNormalized()) {
}
}
// public for java.util.GregorianCalendar
// Look up the one year cache
if (isJan1) {
return cache.getCachedJan1();
}
}
// Look up the pre-calculated fixed date table
long jan1 = FIXED_DATES[n];
}
}
long days = dayOfMonth;
if (prevyear >= 0) {
+ (prevyear / 4)
- (prevyear / 100)
+ (prevyear / 400)
} else {
}
}
// If it's January 1, update the cache.
}
return days;
}
/**
* Calculates calendar fields and store them in the specified
* <code>CalendarDate</code>.
*/
// should be 'protected'
long fixedDate) {
int year;
long jan1;
boolean isLeap;
} else {
// Looking up FIXED_DATES[] here didn't improve performance
// much. So we calculate year and jan1. getFixedDate()
// will look up FIXED_DATES[] actually.
// Update the cache data
}
if (isLeap) {
++mar1;
}
}
if (month > 0) {
month /= 367;
} else {
}
++month1;
}
gdate.setNormalized(true);
}
/**
* Returns the day of week of the given Gregorian date.
*/
return getDayOfWeekFromFixedDate(fixedDate);
}
// The fixed day 1 (January 1, 1 Gregorian) is Monday.
if (fixedDate >= 0) {
}
}
return getGregorianYearFromFixedDate(fixedDate);
}
/**
* Returns the Gregorian year number of the given fixed date.
*/
long d0;
int year;
if (fixedDate > 0) {
} else {
}
++year;
}
return year;
}
/**
* @return true if the specified year is a Gregorian leap year, or
* false otherwise.
* @see BaseCalendar#isGregorianLeapYear
*/
}
}
}