APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.util.calendar

public abstract sealed Class CalendarSystem

extends Object
permits AbstractCalendar
Class Inheritance
Known Direct Subclasses
sun.util.calendar.AbstractCalendar
Imports
java.util.TimeZone, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

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.

CalendarDate

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.

Calendar names

Each calendar system has a unique name to be identified. The Java runtime in this release supports the following calendar systems.
 Name          Calendar System
 ---------------------------------------
 gregorian     Gregorian Calendar
 julian        Julian Calendar
 japanese      Japanese Imperial Calendar
Author
Masayoshi Okutsu
Since
1.5
See Also
CalendarDate

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static ConcurrentMap<String, CalendarSystem>
private static volatile boolean
private static final String[]
private static ConcurrentMap<String, String>
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static CalendarSystem

Returns:

the CalendarSystem specified by calendarName, or null if there is no CalendarSystem associated with the given calendar name.
forName
(String
the calendar name
calendarName
)

Returns a CalendarSystem specified by the calendar name.

public abstract CalendarDate
public abstract CalendarDate

Returns:

a CalendarDate instance that contains the calculated calendar field values.
getCalendarDate
(long
the offset value in milliseconds from January 1, 1970 00:00:00 UTC (Gregorian).
millis
)

Calculates calendar fields from the specified number of milliseconds since the Epoch, January 1, 1970 00:00:00 UTC (Gregorian).

public abstract CalendarDate
getCalendarDate(long millis, CalendarDate date)

public abstract CalendarDate
getCalendarDate(long millis, TimeZone zone)

public abstract Era

Returns:

the Era 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.
getEra
(String
the name of the era
eraName
)

Returns the Era designated by the era name that has to be known to this calendar system.

public abstract Era[]

Returns:

an array of valid Eras, or null if no era is applicable to this calendar system.
getEras
()

Returns valid Eras of this calendar system.

public static Gregorian

Returns:

the Gregorian instance
getGregorianCalendar
()

Returns the singleton instance of the Gregorian calendar system.

public abstract int

Returns:

the number of days in the month
getMonthLength
(CalendarDate
the date from which the month value is obtained
date
)

Returns the length in days of the month specified by the calendar date.

public abstract String
getName()

Returns the name of this calendar system.

public abstract CalendarDate

Returns:

the date of the nth dayOfWeek after or before the specified CalendarDate
getNthDayOfWeek
(int
specifies the n-th one. A positive number specifies on or after the date. A non-positive number specifies on or before the date.
nth
,
int
the day of week
dayOfWeek
,
CalendarDate
the date
date
)

Returns a CalendarDate of the n-th day of week which is on, after or before the specified date.

public abstract long

Returns:

the number of milliseconds since the Epoch.
getTime
(CalendarDate
the CalendarDate from which the time value is calculated
date
)

Returns the number of milliseconds since the Epoch, January 1, 1970 00:00:00 UTC (Gregorian), represented by the specified CalendarDate.

public abstract int
getYearLength(CalendarDate date)

Returns the length in days of the specified year by date.

private static void
public abstract CalendarDate

Returns:

a CalendarDate instance that contains the initial calendar field values.
newCalendarDate
()

Constructs a CalendarDate that is specific to this calendar system.

public abstract CalendarDate
public abstract boolean

Returns:

true if all fields have been normalized; false otherwise.
normalize
(CalendarDate
the calendar date to be validated
date
)

Normalizes calendar fields in the specified date.

public abstract CalendarDate
setTimeOfDay(CalendarDate date, int timeOfDay)

public abstract boolean

Returns:

true if all the calendar fields are consistent, otherwise, false is returned.
validate
(CalendarDate
the CalendarDate to be validated
date
)

Checks whether the calendar fields specified by date represents a valid date and time in this calendar system.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

calendarsback to summary
private static ConcurrentMap<String, CalendarSystem> calendars
initializedback to summary
private static volatile boolean initialized
namePairsback to summary
private static final String[] namePairs
namesback to summary
private static ConcurrentMap<String, String> names
PACKAGE_NAMEback to summary
private static final String PACKAGE_NAME

Constructor Detail

CalendarSystemback to summary
public CalendarSystem()

Method Detail

forNameback to summary
public static CalendarSystem forName(String calendarName)

Returns a CalendarSystem specified by the calendar name. The calendar name has to be one of the supported calendar names.

Parameters
calendarName:String

the calendar name

Returns:CalendarSystem

the CalendarSystem specified by calendarName, or null if there is no CalendarSystem associated with the given calendar name.

getCalendarDateback to summary
public abstract CalendarDate getCalendarDate()
getCalendarDateback to summary
public 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). This method doesn't check overflow or underflow when adjusting the millisecond value (representing UTC) with the time zone offsets (i.e., the GMT offset and amount of daylight saving).

Parameters
millis:long

the offset value in milliseconds from January 1, 1970 00:00:00 UTC (Gregorian).

Returns:CalendarDate

a CalendarDate instance that contains the calculated calendar field values.

getCalendarDateback to summary
public abstract CalendarDate getCalendarDate(long millis, CalendarDate date)
getCalendarDateback to summary
public abstract CalendarDate getCalendarDate(long millis, TimeZone zone)
getEraback to summary
public abstract Era getEra(String eraName)

Returns the 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.

Parameters
eraName:String

the name of the era

Returns:Era

the Era 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.

getErasback to summary
public abstract Era[] getEras()

Returns valid 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.

Returns:Era[]

an array of valid Eras, or null if no era is applicable to this calendar system.

getGregorianCalendarback to summary
public static Gregorian getGregorianCalendar()

Returns the singleton instance of the Gregorian calendar system.

Returns:Gregorian

the Gregorian instance

getMonthLengthback to summary
public abstract int getMonthLength(CalendarDate date)

Returns the length in days of the month specified by the calendar date. This method does not perform the normalization with the specified calendar date. The CalendarDate must be normalized to get a correct value.

Parameters
date:CalendarDate

the date from which the month value is obtained

Returns:int

the number of days in the month

Exceptions
IllegalArgumentException:
if the specified calendar date doesn't have a valid month value in this calendar system.
getNameback to summary
public abstract String getName()

Returns the name of this calendar system.

getNthDayOfWeekback to summary
public 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. 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.
Parameters
nth:int

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:int

the day of week

date:CalendarDate

the date

Returns:CalendarDate

the date of the nth dayOfWeek after or before the specified CalendarDate

getTimeback to summary
public 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.

Parameters
date:CalendarDate

the CalendarDate from which the time value is calculated

Returns:long

the number of milliseconds since the Epoch.

getYearLengthback to summary
public abstract int getYearLength(CalendarDate date)

Returns the length in days of the specified year by date. This method does not perform the normalization with the specified CalendarDate. The CalendarDate must be normalized to get a correct value.

initNamesback to summary
private static void initNames()
newCalendarDateback to summary
public abstract CalendarDate newCalendarDate()

Constructs a CalendarDate that is specific to this calendar system. All calendar fields have their initial values. The default time zone is set to the instance.

Returns:CalendarDate

a CalendarDate instance that contains the initial calendar field values.

newCalendarDateback to summary
public abstract CalendarDate newCalendarDate(TimeZone zone)
normalizeback to summary
public abstract boolean normalize(CalendarDate date)

Normalizes calendar fields in the specified date. Also all undefined fields are set to correct values. The actual normalization process is calendar system dependent.

Parameters
date:CalendarDate

the calendar date to be validated

Returns:boolean

true if all fields have been normalized; false otherwise.

Exceptions
NullPointerException:
if the specified date is null
setTimeOfDayback to summary
public abstract CalendarDate setTimeOfDay(CalendarDate date, int timeOfDay)
validateback to summary
public abstract boolean validate(CalendarDate date)

Checks whether the calendar fields specified by date represents a valid date and time in this calendar system. If the given date is valid, date is marked as normalized.

Parameters
date:CalendarDate

the CalendarDate to be validated

Returns:boolean

true if all the calendar fields are consistent, otherwise, false is returned.

Exceptions
NullPointerException:
if the specified date is null
sun.util.calendar back to summary

private final Class CalendarSystem.GregorianHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final Gregorian

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GREGORIAN_INSTANCEback to summary
private static final Gregorian GREGORIAN_INSTANCE

Constructor Detail

GregorianHolderback to summary
private GregorianHolder()