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

public abstract sealed Class CalendarDate

extends Object
implements Cloneable
permits Date
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
sun.util.calendar.BaseCalendar.Date
Imports
java.lang.Cloneable, java.util.TimeZone

The CalendarDate class represents a specific instant in time by calendar date and time fields that are multiple cycles in different time unites. The semantics of each calendar field is given by a concrete calendar system rather than this CalendarDate class that holds calendar field values without interpreting them. Therefore, this class can be used to represent an amount of time, such as 2 years and 3 months.

A CalendarDate instance can be created by calling the newCalendarDate or getCalendarDate methods in CalendarSystem. A CalendarSystem instance is obtained by calling one of the factory methods in CalendarSystem. Manipulations of calendar dates must be handled by the calendar system by which CalendarDate instances have been created.

Some calendar fields can be modified through method calls. Any modification of a calendar field brings the state of a CalendarDate to not normalized. The normalization must be performed to make all the calendar fields consistent with a calendar system.

The protected methods are intended to be used for implementing a concrete calendar system, not for general use as an API.

Author
Masayoshi Okutsu
Since
1.5
See Also
CalendarSystem

Field Summary

Modifier and TypeField and Description
private int
private int
private int
private Era
public static final int
private long
private int
private boolean
private int
private int
private int
private boolean
private int
public static final long
private int
private TimeZone
private int

Constructor Summary

AccessConstructor and Description
protected
protected

Method Summary

Modifier and TypeMethod and Description
public CalendarDate
addHours(int n)

public CalendarDate
addMonth(int n)

public CalendarDate
addYear(int n)

public Object

Returns:

a copy of this CalendarDate
clone
()

Overrides java.lang.Object.clone.

Returns a copy of this CalendarDate.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
public int
public int

Returns:

day of week or FIELD_UNDEFINED
getDayOfWeek
()

Returns the day of week value.

public Era
public int
public int
public int
public int
public int
public long
public int
public TimeZone
public int
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
public boolean

Returns:

true if this CalendarDate is normalized and the year of this CalendarDate is a leap year, or false otherwise.
isLeapYear
()

Returns whether the year represented by this CalendarDate is a leap year.

public boolean
public boolean
isSameDate(CalendarDate date)

Returns whether the specified date is the same date of this CalendarDate.

public CalendarDate
setDate(int year, int month, int dayOfMonth)

protected void
setDaylightSaving(int daylightSaving)

public CalendarDate
setDayOfMonth(int date)

protected void
setDayOfWeek(int dayOfWeek)

public CalendarDate
setEra(Era era)

Sets the era of the date to the specified era.

public CalendarDate
setHours(int hours)

pack-priv void
setLeapYear(boolean leapYear)

public CalendarDate
setMillis(int millis)

public CalendarDate
setMinutes(int minutes)

public CalendarDate
setMonth(int month)

protected void
setNormalized(boolean normalized)

public CalendarDate
setSeconds(int seconds)

public CalendarDate
setTimeOfDay(int hours, int minutes, int seconds, int millis)

protected void
setTimeOfDay(long fraction)

public CalendarDate
setYear(int year)

public CalendarDate
setZone(TimeZone zoneinfo)

protected void
setZoneOffset(int offset)

public String
toString()

Overrides java.lang.Object.toString.

Converts calendar date values to a String in the following format.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

daylightSavingback to summary
private int daylightSaving
dayOfMonthback to summary
private int dayOfMonth
dayOfWeekback to summary
private int dayOfWeek
eraback to summary
private Era era
FIELD_UNDEFINEDback to summary
public static final int FIELD_UNDEFINED
fractionback to summary
private long fraction
hoursback to summary
private int hours
leapYearback to summary
private boolean leapYear
millisback to summary
private int millis
minutesback to summary
private int minutes
monthback to summary
private int month
normalizedback to summary
private boolean normalized
secondsback to summary
private int seconds
TIME_UNDEFINEDback to summary
public static final long TIME_UNDEFINED
yearback to summary
private int year
zoneinfoback to summary
private TimeZone zoneinfo
zoneOffsetback to summary
private int zoneOffset

Constructor Detail

CalendarDateback to summary
protected CalendarDate()
CalendarDateback to summary
protected CalendarDate(TimeZone zone)

Method Detail

addHoursback to summary
public CalendarDate addHours(int n)
addMonthback to summary
public CalendarDate addMonth(int n)
addYearback to summary
public CalendarDate addYear(int n)
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Returns a copy of this CalendarDate. The TimeZone object, if any, is not cloned.

Returns:Object

a copy of this CalendarDate

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

getDaylightSavingback to summary
public int getDaylightSaving()
getDayOfMonthback to summary
public int getDayOfMonth()
getDayOfWeekback to summary
public int getDayOfWeek()

Returns the day of week value. If this CalendarDate is not normalized, FIELD_UNDEFINED is returned.

Returns:int

day of week or FIELD_UNDEFINED

getEraback to summary
public Era getEra()
getHoursback to summary
public int getHours()
getMillisback to summary
public int getMillis()
getMinutesback to summary
public int getMinutes()
getMonthback to summary
public int getMonth()
getSecondsback to summary
public int getSeconds()
getTimeOfDayback to summary
public long getTimeOfDay()
getYearback to summary
public int getYear()
getZoneback to summary
public TimeZone getZone()
getZoneOffsetback to summary
public int getZoneOffset()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isDaylightTimeback to summary
public boolean isDaylightTime()
isLeapYearback to summary
public boolean isLeapYear()

Returns whether the year represented by this CalendarDate is a leap year. If leap years are not applicable to the calendar system, this method always returns false.

If this CalendarDate hasn't been normalized, false is returned. The normalization must be performed to retrieve the correct leap year information.

Returns:boolean

true if this CalendarDate is normalized and the year of this CalendarDate is a leap year, or false otherwise.

See Also
CalendarUtils#isGregorianLeapYear
isNormalizedback to summary
public boolean isNormalized()
isSameDateback to summary
public boolean isSameDate(CalendarDate date)

Returns whether the specified date is the same date of this CalendarDate. The time of the day fields are ignored for the comparison.

setDateback to summary
public CalendarDate setDate(int year, int month, int dayOfMonth)
setDaylightSavingback to summary
protected void setDaylightSaving(int daylightSaving)
setDayOfMonthback to summary
public CalendarDate setDayOfMonth(int date)
setDayOfWeekback to summary
protected void setDayOfWeek(int dayOfWeek)
setEraback to summary
public CalendarDate setEra(Era era)

Sets the era of the date to the specified era. The default implementation of this method accepts any Era value, including null.

Exceptions
NullPointerException:
if the calendar system for this CalendarDate requires eras and the specified era is null.
IllegalArgumentException:
if the specified era is unknown to the calendar system for this CalendarDate.
setHoursback to summary
public CalendarDate setHours(int hours)
setLeapYearback to summary
pack-priv void setLeapYear(boolean leapYear)
setMillisback to summary
public CalendarDate setMillis(int millis)
setMinutesback to summary
public CalendarDate setMinutes(int minutes)
setMonthback to summary
public CalendarDate setMonth(int month)
setNormalizedback to summary
protected void setNormalized(boolean normalized)
setSecondsback to summary
public CalendarDate setSeconds(int seconds)
setTimeOfDayback to summary
public CalendarDate setTimeOfDay(int hours, int minutes, int seconds, int millis)
setTimeOfDayback to summary
protected void setTimeOfDay(long fraction)
setYearback to summary
public CalendarDate setYear(int year)
setZoneback to summary
public CalendarDate setZone(TimeZone zoneinfo)
setZoneOffsetback to summary
protected void setZoneOffset(int offset)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Converts calendar date values to a String in the following format.

    yyyy-MM-dd'T'HH:mm:ss.SSSz
Annotations
@Override
See Also
java.text.SimpleDateFormat