|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ahc.util.DateDay
This class represents a date, i.e. a combination of day, month and year.
It fills a gap in the JDK libraries: java.util.Date is a point in time including hours, minutes, secondes etc., and it does a reasonably good job of it. A point in time is prone to time zone conversions etc. so that its representation depends on a time zone / locale setting.
Dates are different. If some one's birthday is Sept 5 1974, then that is it, and we usually do not want the birthday to be displayed differently for different time zones. In a business setting it is also quite commonly necessary to do date arithmetic: one week later, one month previously etc. The common approach of treating a day as 24 * 60 * 60 * 1000 milliseconds and adding / subtracting these is not only cumbersome but also a violation of the Date contract (there is such a thing as leap seconds...) Doing this sort of thing cleanly requires the use of GregorianCalendar which is complex, cumbersome and expensive to use.
To cut a long story short, this class fills the gap by providing a small, inexpensive class for date representation and arithmetic. The class is immutable, and all modifying methods return new instances and leave the original instance unmodified.
Method Summary | |
boolean |
after(DateDay other)
|
java.util.Date |
asDate()
converts to a java.util.Date based on the default TimeZone |
java.util.Date |
asDate(java.util.TimeZone timeZone)
converts to a java.util.Date based on a specific TimeZone |
boolean |
before(DateDay other)
|
int |
compareTo(java.lang.Object o)
implements java.util.Comparable. |
static DateDay |
create(java.util.Date date)
returns a DateDay instance based on a java.util.Date and the default TimeZone |
static DateDay |
create(java.util.Date date,
java.util.TimeZone timezone)
returns a DateDay instance based on the full java.util representation, i.e. a Date and a TimeZone |
static DateDay |
create(int day,
int month,
int year)
returns a DateDay instance based on day, month and year |
DateDay |
decDay()
returns the previous date |
DateDay |
decDay(int num)
returns the equivalent of num calls to decDay |
DateDay |
decMonth(boolean roundLater)
The opposite of incMonth(boolean) |
DateDay |
decMonth(int num,
boolean roundLater)
The opposite of incMonth (int, boolean) |
DateDay |
decYear(boolean roundLater)
The opposite of incYear(boolean) |
DateDay |
decYear(int num,
boolean roundLater)
The opposite of incYear(int, boolean) |
boolean |
equals(java.lang.Object o)
|
int |
getDay()
|
int |
getMonth()
|
int |
getYear()
|
int |
hashCode()
|
DateDay |
incDay()
returns the next date |
DateDay |
incDay(int num)
returns the equivalent of num calls to indDay() |
DateDay |
incMonth(boolean roundLater)
returns the same day of the next month. |
DateDay |
incMonth(int num,
boolean roundLater)
returns the same day num months later. |
DateDay |
incYear(boolean roundLater)
returns the same date of the next year. |
DateDay |
incYear(int num,
boolean roundLater)
returns the same date num years later. |
static boolean |
isLeapYear(int year)
|
static int |
numDays(int month,
int year)
|
DateDay |
setDay(int day)
|
DateDay |
setMonth(int month)
|
DateDay |
setYear(int year)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
public static DateDay create(int day, int month, int year)
public static DateDay create(java.util.Date date, java.util.TimeZone timezone)
public static DateDay create(java.util.Date date)
public int getDay()
public int getMonth()
public int getYear()
public DateDay setDay(int day)
public DateDay setMonth(int month)
public DateDay setYear(int year)
public java.util.Date asDate()
public java.util.Date asDate(java.util.TimeZone timeZone)
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
public boolean before(DateDay other)
public boolean after(DateDay other)
public static boolean isLeapYear(int year)
public static int numDays(int month, int year)
public DateDay incDay()
public DateDay incDay(int num)
public DateDay decDay()
public DateDay decDay(int num)
public DateDay incMonth(boolean roundLater)
public DateDay incMonth(int num, boolean roundLater)
This is not equivalent to num calls to incMonth(boolean)!
public DateDay decMonth(boolean roundLater)
public DateDay decMonth(int num, boolean roundLater)
public DateDay incYear(boolean roundLater)
public DateDay incYear(int num, boolean roundLater)
This is not equivalent to several subsequent calls of incYear (boolean)!
public DateDay decYear(boolean roundLater)
public DateDay decYear(int num, boolean roundLater)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |