Save This Page
Home » openjdk-7 » sun » util » calendar » [javadoc | source]
sun.util.calendar
abstract public class: CalendarSystem [javadoc | source]
java.lang.Object
   sun.util.calendar.CalendarSystem

Direct Known Subclasses:
    JulianCalendar, BaseCalendar, Gregorian, LocalGregorianCalendar, AbstractCalendar

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
Method from sun.util.calendar.CalendarSystem Summary:
forName,   getCalendarDate,   getCalendarDate,   getCalendarDate,   getCalendarDate,   getEra,   getEras,   getGregorianCalendar,   getMonthLength,   getName,   getNthDayOfWeek,   getTime,   getWeekLength,   getYearLength,   getYearLengthInMonths,   newCalendarDate,   newCalendarDate,   normalize,   setEra,   setTimeOfDay,   validate
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from sun.util.calendar.CalendarSystem Detail:
 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.
 abstract public CalendarDate getCalendarDate()
 abstract public 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).
 abstract public CalendarDate getCalendarDate(long millis,
    CalendarDate date)
 abstract public CalendarDate getCalendarDate(long millis,
    TimeZone zone)
 abstract public 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.
 abstract public 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.
 public static Gregorian getGregorianCalendar() 
    Returns the singleton instance of the Gregorian calendar system.
 abstract public 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.
 abstract public String getName()
    Returns the name of this calendar system.
 abstract public 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.
 abstract public 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 public int getWeekLength()
    Returns the length in days of a week in this calendar system. If this calendar system has multiple radix weeks, this method returns only one of them.
 abstract public 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.
 abstract public int getYearLengthInMonths(CalendarDate date)
    Returns the number of months of the specified year. This method does not perform the normalization with the specified CalendarDate. The CalendarDate must be normalized to get a correct value.
 abstract public 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.
 abstract public CalendarDate newCalendarDate(TimeZone zone)
 abstract public 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.
 abstract public  void setEra(CalendarDate date,
    String eraName)
 abstract public CalendarDate setTimeOfDay(CalendarDate date,
    int timeOfDay)
 abstract public 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.