|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.osesb.utilities.language.CalendarDate
public final class CalendarDate
This class represents a date in the Gregorian calendar (for example, December
20, 1998). It is designed to be a simpler, immutable version of
java.util.GregorianCalendar.
Don't confuse this class with java.util.Date! They
represent two separate things:
CalendarDate represents a 'date in the calendar' (e.g.
"John Smith's birthday") while
java.util.Date represent an 'instant in time' (e.g. "When
order 23711 was received"). A better name for this class would have been
'DateTime'.
java.util.TimeZone when converting between instances of
CalendarDate and Date.)
This class is thread-safe and immutable.
Date,
GregorianCalendar,
Serialized Form| Field Summary | |
|---|---|
static int |
APRIL
The value returned by getMonth() representing April |
static int |
AUGUST
The value returned by getMonth() representing August |
static int |
DECEMBER
The value returned by getMonth() representing December |
static CalendarDate |
EARLIEST
The earliest date that can be represented by this class (Januray 1, 1600 A.D.) |
static int |
FEBRUARY
The value returned by getMonth() representing February |
static int |
FRIDAY
The value returned by getDayOfWeek() representing Friday |
static int |
JANUARY
The value returned by getMonth() representing January |
static int |
JULY
The value returned by getMonth() representing July |
static int |
JUNE
The value returned by getMonth() representing June |
static CalendarDate |
LATEST
The latest date that can be represented by this class (December 31, 2999 A.D.) |
static int |
MARCH
The value returned by getMonth() representing March |
static int |
MAY
The value returned by getMonth() representing May |
static int |
MONDAY
The value returned by getDayOfWeek() representing Monday |
static int |
NOVEMBER
The value returned by getMonth() representing November |
static int |
OCTOBER
The value returned by getMonth() representing October |
static int |
SATURDAY
The value returned by getDayOfWeek() representing Saturday |
static int |
SEPTEMBER
The value returned by getMonth() representing September |
static int |
SUNDAY
The value returned by getDayOfWeek() representing Sunday |
protected java.lang.String |
thisClassName
The full name of this class. |
static int |
THURSDAY
The value returned by getDayOfWeek() representing Thursday |
static int |
TUESDAY
The value returned by getDayOfWeek() representing Tuesday |
static int |
WEDNESDAY
The value returned by getDayOfWeek() representing Wednesday |
| Constructor Summary | |
|---|---|
CalendarDate()
Creates a CalendarDate representing the current date in the default timezone. |
|
CalendarDate(java.util.Date instantInTime)
Creates a CalendarDate representing the date in the default timezone at the given instant in time. |
|
CalendarDate(int year,
int month,
int dayOfMonth)
Creates a date represented by the given year, month and day. |
|
CalendarDate(java.util.TimeZone tzone)
Creates a CalendarDate representing the current date in the given timezone. |
|
CalendarDate(java.util.TimeZone tzone,
java.util.Date instantInTime)
Creates a CalendarDate representing the date in the given timezone at the given instant in time. |
|
| Method Summary | |
|---|---|
CalendarDate |
addDays(int numDays)
Returns a new date which is this date offset by numDays. |
CalendarDate |
addMonths(int numMonths)
Returns a new date which is this date offset by numMonths. |
CalendarDate |
addYears(int numYears)
Returns a new date which is this date offset by numYears. |
int |
compareTo(java.lang.Object other)
If the given object is a CalendarDate: returns less than 0 if this date is before the given date returns 0 if this date is equal to the given date returns more than 0 if this date is after the given date |
int |
daysUntil(CalendarDate otherDay)
Returns the number of days until the given date |
boolean |
equals(java.lang.Object other)
Returns true if the given object is a CalendarDate representing the same date as this object. |
int |
getDayOfMonth()
The day of the month |
int |
getDayOfWeek()
The day of the week for this date |
int |
getMonth()
The month of this date |
CalendarDate |
getNextDay(int dayOfTheWeek)
Returns a CalendarDate that represents the first day after this CalendarDate that matches the specified dayOfTheWeek. |
int |
getYear()
The year of this date |
int |
hashCode()
|
boolean |
isAfter(CalendarDate other)
Returns true if this date is after the given date. |
boolean |
isAfterOrEqualTo(CalendarDate other)
Returns true if this date is after the given date. |
boolean |
isBefore(CalendarDate other)
Returns true if this date is before the given date |
boolean |
isBeforeOrEqualTo(CalendarDate other)
Returns true if this date is before or equal to the given date. |
boolean |
isBetweenExclusive(CalendarDate startDate,
CalendarDate endDate)
Returns true if this date is between the given dates, NOT including the startDate and endDate.. |
boolean |
isBetweenInclusive(CalendarDate startDate,
CalendarDate endDate)
Returns true if this date is between the given dates, including the startDate and endDate. |
static boolean |
isLeapYear(int year)
Returns true if the year is a leap year in the Gregorian calendar |
static void |
main(java.lang.String[] args)
main() For testing. |
int |
monthsUntil(CalendarDate otherDay)
Returns the number of month changes until the given day. |
java.util.Date |
toDate()
Returns the instant in time when this day begins in the default timeZone. |
java.util.Date |
toDate(java.util.TimeZone timezone)
Returns the instant in time when this day begins in the given timezone. |
java.util.Date |
toDate(java.util.TimeZone timezone,
int hour,
int min,
int sec)
Returns the instant in time when the given time of day is reached in the given timezone. |
java.lang.String |
toString()
Returns a string form of this date in the form "2004-9-23" |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int SUNDAY
public static final int MONDAY
public static final int TUESDAY
public static final int WEDNESDAY
public static final int THURSDAY
public static final int FRIDAY
public static final int SATURDAY
public static final int JANUARY
public static final int FEBRUARY
public static final int MARCH
public static final int APRIL
public static final int MAY
public static final int JUNE
public static final int JULY
public static final int AUGUST
public static final int SEPTEMBER
public static final int OCTOBER
public static final int NOVEMBER
public static final int DECEMBER
public static final CalendarDate EARLIEST
Note: this date may change to before 1600 in later releases of CalendarDate.
public static final CalendarDate LATEST
protected java.lang.String thisClassName
| Constructor Detail |
|---|
public CalendarDate(int year,
int month,
int dayOfMonth)
year - The year of the date to createmonth - The month of the date to create (1 = January, 12 = December)dayOfMonth - The day of the month of the date to create.
java.lang.IllegalArgumentException - if the year, month and dayOfMonth
combination are not valid in a Gregorian calendar.
public CalendarDate(java.util.TimeZone tzone,
java.util.Date instantInTime)
Think carefully about what timezone to use! Often you will
want to use the timezone of the 'user' - which is not always represented
by TimeZone.getDefault()
tzone - The timezone to be consideredinstantInTime - The instant in time to be consideredpublic CalendarDate()
public CalendarDate(java.util.Date instantInTime)
instantInTime - The instant in time to be consideredpublic CalendarDate(java.util.TimeZone tzone)
CalendarDate(tzone, new Date())
tzone - The timezone to be considered| Method Detail |
|---|
public int getDayOfMonth()
public int getDayOfWeek()
public int getMonth()
public int getYear()
public CalendarDate addDays(int numDays)
numDays - the number of days to be added to this date
(can be negative)
java.lang.IllegalArgumentException - if the resulting day would be before
EARLIEST or after LATEST. That is,
if numDays < this.daysUntil(EARLIEST)
or numDays > this.daysUntil(LATEST)public CalendarDate addMonths(int numMonths)
numMonths - the number of months to be added to this date
(can be negative)
java.lang.IllegalArgumentException - if the resulting day would be before
EARLIEST or after LATEST.public CalendarDate addYears(int numYears)
numYears - the number of years to be added to this date
(can be negative)
java.lang.IllegalArgumentException - if the resulting day would be before
EARLIEST or after LATEST.public int daysUntil(CalendarDate otherDay)
otherDay - The date to compare to
public int monthsUntil(CalendarDate otherDay)
otherDay - The date to compare to
public static boolean isLeapYear(int year)
year - The year to consider
year is a leap year
public int compareTo(java.lang.Object other)
throws java.lang.ClassCastException
compareTo in interface java.lang.Comparableother - the date to compare this one to
java.lang.ClassCastException - if other is not an instance of
CalendarDateComparable.compareTo(java.lang.Object)public boolean isBefore(CalendarDate other)
other - The date to consider.
public boolean isBeforeOrEqualTo(CalendarDate other)
other - The date to consider
public boolean isAfter(CalendarDate other)
other - The date to consider
public boolean isAfterOrEqualTo(CalendarDate other)
other - The date to consider
public boolean isBetweenInclusive(CalendarDate startDate,
CalendarDate endDate)
startDate - The start of the date range.endDate - The end of the date range.
public boolean isBetweenExclusive(CalendarDate startDate,
CalendarDate endDate)
startDate - The start of the date range.endDate - The end of the date range.
public CalendarDate getNextDay(int dayOfTheWeek)
dayOfTheWeek - Calendar.SUNDAY, Calendar.TUESDAY,...
public boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - The date to test against
otherpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Date toDate()
public java.util.Date toDate(java.util.TimeZone timezone)
timezone - The timezone to consider
public java.util.Date toDate(java.util.TimeZone timezone,
int hour,
int min,
int sec)
timezone - The timezone to for which the date applieshour - The hour of the day in range 0 - 23min - The minute of the day in range 0 - 59sec - The second of the day in range 0 - 60 (60 is for leap-seconds)
java.lang.IllegalArgumentException - if the bounds of the abovepublic static void main(java.lang.String[] args)
args - commandline arguments
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||