public abstract class CalendarSystem
extends java.lang.Object
CalendarSystem is an abstract class that defines the
programming interface to deal with calendar date and time.
CalendarSystem instances are singletons. For
example, there exists only one Gregorian calendar instance in the
Java runtime environment. A singleton instance can be obtained
calling one of the static factory methods.
For the methods in a CalendarSystem that manipulate
a CalendarDate, CalendarDates that have
been created by the CalendarSystem must be
specified. Otherwise, the methods throw an exception. This is
because, for example, a Chinese calendar date can't be understood
by the Hebrew calendar system.
Name Calendar System --------------------------------------- gregorian Gregorian Calendar julian Julian Calendar japanese Japanese Imperial Calendar
CalendarDate| Constructor and Description |
|---|
CalendarSystem() |
| Modifier and Type | Method and Description |
|---|---|
static CalendarSystem |
forName(java.lang.String calendarName)
Returns a
CalendarSystem specified by the calendar
name. |
abstract CalendarDate |
getCalendarDate() |
abstract CalendarDate |
getCalendarDate(long millis)
Calculates calendar fields from the specified number of
milliseconds since the Epoch, January 1, 1970 00:00:00 UTC
(Gregorian).
|
abstract CalendarDate |
getCalendarDate(long millis,
CalendarDate date) |
abstract CalendarDate |
getCalendarDate(long millis,
java.util.TimeZone zone) |
abstract Era |
getEra(java.lang.String eraName)
Returns the
Era designated by the era name that
has to be known to this calendar system. |
abstract Era[] |
getEras()
Returns valid
Eras of this calendar system. |
static Gregorian |
getGregorianCalendar()
Returns the singleton instance of the
Gregorian
calendar system. |
abstract int |
getMonthLength(CalendarDate date)
Returns the length in days of the month specified by the calendar
date.
|
abstract java.lang.String |
getName()
Returns the name of this calendar system.
|
abstract CalendarDate |
getNthDayOfWeek(int nth,
int dayOfWeek,
CalendarDate date)
Returns a
CalendarDate of the n-th day of week
which is on, after or before the specified date. |
abstract long |
getTime(CalendarDate date)
Returns the number of milliseconds since the Epoch, January 1,
1970 00:00:00 UTC (Gregorian), represented by the specified
CalendarDate. |
abstract int |
getWeekLength()
Returns the length in days of a week in this calendar
system.
|
abstract int |
getYearLength(CalendarDate date)
Returns the length in days of the specified year by
date. |
abstract int |
getYearLengthInMonths(CalendarDate date)
Returns the number of months of the specified year.
|
abstract CalendarDate |
newCalendarDate()
Constructs a
CalendarDate that is specific to this
calendar system. |
abstract CalendarDate |
newCalendarDate(java.util.TimeZone zone) |
abstract boolean |
normalize(CalendarDate date)
Normalizes calendar fields in the specified
date. |
abstract void |
setEra(CalendarDate date,
java.lang.String eraName) |
abstract CalendarDate |
setTimeOfDay(CalendarDate date,
int timeOfDay) |
abstract boolean |
validate(CalendarDate date)
Checks whether the calendar fields specified by
date
represents a valid date and time in this calendar system. |
public static Gregorian getGregorianCalendar()
Gregorian
calendar system.Gregorian instancepublic static CalendarSystem forName(java.lang.String calendarName)
CalendarSystem specified by the calendar
name. The calendar name has to be one of the supported calendar
names.calendarName - the calendar nameCalendarSystem specified by
calendarName, or null if there is no
CalendarSystem associated with the given calendar name.public abstract java.lang.String getName()
public abstract CalendarDate getCalendarDate()
public abstract CalendarDate getCalendarDate(long millis)
millis - the offset value in milliseconds from January 1,
1970 00:00:00 UTC (Gregorian).CalendarDate instance that contains the
calculated calendar field values.public abstract CalendarDate getCalendarDate(long millis, CalendarDate date)
public abstract CalendarDate getCalendarDate(long millis, java.util.TimeZone zone)
public abstract CalendarDate newCalendarDate()
CalendarDate that is specific to this
calendar system. All calendar fields have their initial
values. The default time zone is
set to the instance.CalendarDate instance that contains the initial
calendar field values.public abstract CalendarDate newCalendarDate(java.util.TimeZone zone)
public abstract long getTime(CalendarDate date)
CalendarDate.date - the CalendarDate from which the time
value is calculatedpublic abstract int getYearLength(CalendarDate date)
date. This method does not perform the
normalization with the specified CalendarDate. The
CalendarDate must be normalized to get a correct
value.public abstract int getYearLengthInMonths(CalendarDate date)
CalendarDate. The CalendarDate must
be normalized to get a correct value.public abstract int getMonthLength(CalendarDate date)
CalendarDate must
be normalized to get a correct value.date - the date from which the month value is obtainedjava.lang.IllegalArgumentException - if the specified calendar date
doesn't have a valid month value in this calendar system.public abstract int getWeekLength()
public abstract Era getEra(java.lang.String eraName)
Era designated by the era name that
has to be known to this calendar system. If no Era is
applicable to this calendar system, null is returned.eraName - the name of the eraEra designated by
eraName, or null if no Era is
applicable to this calendar system or the specified era name is
not known to this calendar system.public abstract Era[] getEras()
Eras of this calendar system. The
return value is sorted in the descendant order. (i.e., the first
element of the returned array is the oldest era.) If no era is
applicable to this calendar system, null is returned.Eras, or
null if no era is applicable to this calendar
system.public abstract void setEra(CalendarDate date, java.lang.String eraName)
java.lang.IllegalArgumentException - if the specified era name is
unknown to this calendar system.Erapublic abstract CalendarDate getNthDayOfWeek(int nth, int dayOfWeek, CalendarDate date)
CalendarDate of the n-th day of week
which is on, after or before the specified date. For example, the
first Sunday in April 2002 (Gregorian) can be obtained as
below:
Gregorian cal = CalendarSystem.getGregorianCalendar();
CalendarDate date = cal.newCalendarDate();
date.setDate(2004, cal.APRIL, 1);
CalendarDate firstSun = cal.getNthDayOfWeek(1, cal.SUNDAY, date);
// firstSun represents April 4, 2004.
This method returns a new CalendarDate instance
and doesn't modify the original date.nth - specifies the n-th one. A positive number specifies
on or after the date. A non-positive number
specifies on or before the date.dayOfWeek - the day of weekdate - the datedayOfWeek after
or before the specified CalendarDatepublic abstract CalendarDate setTimeOfDay(CalendarDate date, int timeOfDay)
public abstract boolean validate(CalendarDate date)
date
represents a valid date and time in this calendar system. If the
given date is valid, date is marked as normalized.date - the CalendarDate to be validatedtrue if all the calendar fields are consistent,
otherwise, false is returned.java.lang.NullPointerException - if the specified
date is nullpublic abstract boolean normalize(CalendarDate date)
date. Also all undefined fields are set to correct values. The actual
normalization process is calendar system dependent.date - the calendar date to be validatedtrue if all fields have been normalized;
false otherwise.java.lang.NullPointerException - if the specified
date is null