|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.jaret.util.misc.PropertyObservableBase de.jaret.util.date.JaretDate
public class JaretDate
A wrapper for java.util.Date
and java.util.Calendar
to ease the use of date and time.
There are some convenience methods for quick textual output. They are located in a delegate that supports i8n. Use
setLocale
to set the locale of the delegate. The delegate is static and any change will affect the
output of all JaretDates!
A good practice is to use an immutable type for representing dates. The JaretDate is not immutable! This is nice in a lot of ways but it requires some caution when copying instances. Recommended is to use it like an immuntable type most of the times (use the copy() method).
Field Summary | |
---|---|
static long |
MILLIS_PER_HOUR
number of milliseconds in one hour. |
static long |
MILLIS_PER_MINUTE
number of milliseconds in one minute. |
static long |
MILLIS_PER_SECOND
number of milliseconds in one second. |
Fields inherited from class de.jaret.util.misc.PropertyObservableBase |
---|
_propertyChangeSupport |
Constructor Summary | |
---|---|
JaretDate()
Constructs a JaretDate with the current date and time. |
|
JaretDate(Date date)
Constructs a JaretDate using a clone of the given Date. |
|
JaretDate(int day,
int month,
int year,
int hours,
int minutes,
int seconds)
Constructs a JaretDate setting it to a given date and time. |
|
JaretDate(JaretDate jdate)
Constructs a new JaretDate object with the same time as the given jaretDate. |
|
JaretDate(long milliseconds)
Constructs a JaretDate using the given millesecond value. |
|
JaretDate(String millisecondsString)
Constructs a JaretDate by milliseconds given in a String. |
Method Summary | |
---|---|
JaretDate |
advanceDays(double days)
Adds a number of days to the date. |
JaretDate |
advanceDays(int days)
Advance by a certain number of days. |
JaretDate |
advanceHours(double hours)
|
JaretDate |
advanceMillis(long millis)
|
JaretDate |
advanceMinutes(double minutes)
|
JaretDate |
advanceMonths(int months)
Advance by a certain number of months. |
JaretDate |
advanceSeconds(double seconds)
|
JaretDate |
advanceYears(int years)
Advance by a certain number of years. |
JaretDate |
backDays(double days)
|
JaretDate |
backHours(double hours)
|
JaretDate |
backMinutes(double minutes)
|
JaretDate |
backSeconds(double seconds)
|
void |
clearTime()
Clear time fields to reduce the jaretdate to a clean date. |
int |
compareDateTo(JaretDate date)
Compare the date (day) of this and the given date. |
long |
compareTimeTo(JaretDate date)
Compares only the time of day of the date with the given day. |
int |
compareTo(JaretDate date)
Compare this to another JaretDate. |
JaretDate |
copy()
Produce a new JaretDate with the time of this date. |
long |
diffMilliSeconds(JaretDate date)
Substracts the the given date from this date and returns the difference in milliseconds. |
double |
diffMinutes(JaretDate date)
Substracts the the given date from this date and returns the difference in minutes. |
int |
diffSeconds(JaretDate date)
Substracts the the given date from this date and returns the difference in seconds (long). |
long |
diffSecondsL(JaretDate date)
Substracts the the given date from this date and returns the difference in seconds. |
boolean |
equals(Object o)
Two JaretDates are equal if the encapsulated Date is equal. |
protected Calendar |
getCalendar()
Supply a configured (set to the current time) Calendar for internal use. |
Date |
getDate()
Returns the encapsulated java.util.Date. |
int |
getDay()
|
int |
getDayOfWeek()
Get the day of the week as constant defined in java.util.Calendar. |
String |
getDayOfWeekString()
Retrieve localized name of the current day of the week. |
int |
getDayOfYear()
|
static JaretDate |
getFirstDayOfAWeek(int week,
int year)
Retrieve a jaret date for the first day in a given week. |
int |
getHours()
|
JaretDateFormatter |
getJaretDateFormatter()
Retrieve the configured JaretDateFormatter. |
int |
getMillis()
|
long |
getMillisInDay()
Calculate the Milliseconds from 0:00 ignoring the millisecond field. |
int |
getMinutes()
|
int |
getMonth()
Retrive the month (1 based). |
String |
getMonthString()
Retrieve a string for the month of the date (full length). |
int |
getSeconds()
|
String |
getShortDayOfWeekString()
|
String |
getShortMonthString()
Retrieve short string for the month. |
int |
getWeekOfYear()
|
int |
getYear()
Retrieve the year of the date. |
int |
hashCode()
Hashcode is the Hash of the encapsulted Date. |
boolean |
isWeekendDay()
|
JaretDate |
setDate(int day,
int month,
int year)
Set the date. |
JaretDate |
setDate(JaretDate date)
Set the date. |
boolean |
setDateByText(String text)
Sets the date by a parseble String. |
void |
setDateTime(int day,
int month,
int year,
int hours,
int minutes,
int seconds)
Sets the date and time of the JaretDate by values. |
void |
setDateTime(int day,
int month,
int year,
int hours,
int minutes,
int seconds,
int milliseconds)
Sets the date and time of the JaretDate by values. |
void |
setDay(int day)
Set the day of month. |
void |
setHours(int hours)
Set the hour in day field of the date. |
static void |
setJaretDateFormatter(JaretDateFormatter jaretDateFormatter)
Sets the JaretDateFormatter to be used for parsing and formatting. |
void |
setLocale(Locale locale)
Set the locale of the JaretDateFormatter. |
void |
setMilliseconds(int milliseconds)
Set the milliseconds. |
void |
setMinutes(int minutes)
Set the minutes in the date. |
void |
setMonth(int month)
Set the month of the year. |
void |
setSeconds(int seconds)
Set the seconds. |
JaretDate |
setTime(int hours,
int minutes,
int seconds)
Set the time. |
JaretDate |
setTime(int hours,
int minutes,
int seconds,
int milliseconds)
Set the time. |
void |
setToNow()
Sets the date to the current system time. |
String |
toDisplayString()
Convenient way for a quick textual output of the timestamp. |
String |
toDisplayStringDate()
Convenient way for quick textual output of the date (day) only. |
String |
toDisplayStringTime()
|
String |
toDisplayStringTime(boolean seconds)
Convenient way for quick textual represenation (time). |
String |
toString()
The standard toString behaviour is the value of the date in milliseconds. |
Methods inherited from class de.jaret.util.misc.PropertyObservableBase |
---|
addPropertyChangeListener, firePropertyChange, isRealModification, removePropertyChangeListener |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long MILLIS_PER_HOUR
public static final long MILLIS_PER_MINUTE
public static final long MILLIS_PER_SECOND
Constructor Detail |
---|
public JaretDate()
public JaretDate(Date date)
date
- initial date to setpublic JaretDate(String millisecondsString)
millisecondsString
- as Stringpublic JaretDate(long milliseconds)
milliseconds
- as longpublic JaretDate(JaretDate jdate)
jdate
- JaretDate to copypublic JaretDate(int day, int month, int year, int hours, int minutes, int seconds)
day
- day of monthmonth
- month of yearyear
- yearhours
- hours in dayminutes
- minutes in hourseconds
- seconds in minuteMethod Detail |
---|
public JaretDateFormatter getJaretDateFormatter()
public static void setJaretDateFormatter(JaretDateFormatter jaretDateFormatter)
jaretDateFormatter
- the new Formatter to be used.public void setLocale(Locale locale)
locale
- Locale to be usedpublic void setDateTime(int day, int month, int year, int hours, int minutes, int seconds, int milliseconds)
day
- day of monthmonth
- month of yearyear
- yearhours
- hours in dayminutes
- minutes in hourseconds
- seconds in minutemilliseconds
- milliseconds in secondpublic void setDateTime(int day, int month, int year, int hours, int minutes, int seconds)
day
- day of monthmonth
- month of yearyear
- yearhours
- hours in dayminutes
- minutes in hourseconds
- seconds in minutepublic JaretDate setTime(int hours, int minutes, int seconds, int milliseconds)
hours
- hour valueminutes
- minute valueseconds
- seconds valuemilliseconds
- millisecond value
public JaretDate setTime(int hours, int minutes, int seconds)
hours
- hour valueminutes
- minute valueseconds
- seconds value
public JaretDate setDate(int day, int month, int year)
day
- day of monthmonth
- monthyear
- year
public JaretDate setDate(JaretDate date)
date
- JaretDate to copy the date from
public void setMonth(int month)
month
- month of the year (1=januarypublic void setDay(int day)
day
- day of monthpublic void setHours(int hours)
hours
- hour value to setpublic void setMinutes(int minutes)
minutes
- minute valuepublic void setSeconds(int seconds)
seconds
- second valuepublic void setMilliseconds(int milliseconds)
milliseconds
- millisecond valuepublic boolean setDateByText(String text)
false
and
the date will not be changed. The parsing will be delegated to the JaretDateFormatter.
text
- string to be parsed as date
protected Calendar getCalendar()
public long getMillisInDay()
public Date getDate()
public String toDisplayString()
public String toDisplayStringDate()
public String toDisplayStringTime(boolean seconds)
seconds
- if true, seconds will be included in the format hh:mm:ss
public String toDisplayStringTime()
public String toString()
toString
in class Object
public void setToNow()
public double diffMinutes(JaretDate date)
date
- the Date to be substracted
public int diffSeconds(JaretDate date)
date
- the Date to be substracted
public long diffSecondsL(JaretDate date)
date
- the Date to be substracted
public long diffMilliSeconds(JaretDate date)
date
- the Date to be substracted
public JaretDate advanceMonths(int months)
months
- number of months
public JaretDate advanceYears(int years)
years
- number of years to advance
public JaretDate advanceDays(int days)
days
- number of days to advance
public JaretDate advanceDays(double days)
days
- number of days to add
public JaretDate backDays(double days)
public JaretDate advanceHours(double hours)
public JaretDate backHours(double hours)
public JaretDate advanceMinutes(double minutes)
public JaretDate backMinutes(double minutes)
public JaretDate advanceSeconds(double seconds)
public JaretDate advanceMillis(long millis)
public JaretDate backSeconds(double seconds)
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(JaretDate date)
compareTo
in interface Comparable<JaretDate>
date
- JaretDate to compare to
public long compareTimeTo(JaretDate date)
date
- the date to compare to
public int compareDateTo(JaretDate date)
date
- date to compare to
public JaretDate copy()
public int getMonth()
public String getMonthString()
public String getShortMonthString()
public int getWeekOfYear()
public String getDayOfWeekString()
public String getShortDayOfWeekString()
public int getDayOfWeek()
public boolean isWeekendDay()
public int getDay()
public int getHours()
public int getMinutes()
public int getSeconds()
public int getMillis()
public int getDayOfYear()
public int getYear()
public void clearTime()
public static JaretDate getFirstDayOfAWeek(int week, int year)
week
- weekyear
- year
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |