|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.sandev.basics.util.DateUtil
public class DateUtil
Common date manipulation utilities.
| Constructor Summary | |
|---|---|
DateUtil()
|
|
| Method Summary | |
|---|---|
static java.util.Date |
dateFromShortRead(java.lang.String datestr)
Inverse of getShortReadDate. |
static java.lang.String |
debug(java.util.Calendar cal)
Utility method for dumping out a calendar as a debug string. |
static java.lang.String |
getBasicTime(java.util.Calendar cal)
Return the hours and minutes for the given calendar. |
static java.lang.String |
getDateTimeAsTextNumber(java.util.Calendar cal)
Given a calendar, return a text numeric representation of the date and time. |
static java.lang.String |
getDateTimeAsTextNumber(java.util.Date date)
Get the given date as a text number using the default Calendar. |
static java.lang.String |
getDateTimeAsTextNumberUTC(java.util.Date date)
Calls the standard getDateTimeAsTextNumber with a UTC calendar. |
static java.util.Date |
getDateTimeFromTextNumber(java.lang.String text,
java.util.Calendar cal)
Read the given text numeric representation and of the date and time and return the corresponding date. |
static java.util.Date |
getNowUTC()
Returns the current UTC time as a Date. |
static java.lang.String |
getQueryValue(java.util.Calendar cal)
Return the query string format for this date value. |
static java.lang.String |
getQueryValue(java.util.Date date)
Convenience wrapper that gets a new Calendar instance for the given date before calling through to the calendar version of the same method. |
static java.lang.String |
getShortFileDate(java.util.Calendar cal)
Return a short date identifier useful for naming a file. |
static java.lang.String |
getShortFileDate(java.util.Date date)
Convenience wrapper which gets a new Calendar instance for the given date before calling through to the calendar version of the same method. |
static java.lang.String |
getShortReadDate(java.util.Calendar cal)
Return a short day-month-year representation that can be used as a prefix string when chronological ordering does not have to be the same as alphabetic ordering. |
static java.lang.String |
getShortReadDate(java.util.Date date)
Convenience wrapper which gets a new Calendar instance for the given date before calling through to the calendar version of the same method. |
static java.lang.String |
getShortReadDateTime(java.util.Date date)
Convenience wrapper that gets a new Calendar instance for the given date before calling through to the calendar based method. |
static java.lang.String |
getShortReadDateTimeUTC(java.util.Date date)
Convenience wrapper that gets a new Calendar instance for the given date before calling through to the calendar based method. |
static java.util.Calendar |
getUTCCalendar()
Return a Calendar instance set for UTC. |
static java.lang.String |
getUTCQueryValue(java.util.Date date)
Convenience wrapper that gets a new UTC Calendar instance of the given date before calling through. |
static java.util.Calendar |
initUTCCalendar(java.util.Date date)
Initialize a calendar instance to the given UTC date and return it. |
static void |
roundToThresholdHour(java.util.Calendar cal,
int hour)
Round to the next occurrence of the threshold hour. |
static void |
roundUpHourPeriod(java.util.Calendar cal,
int hourPeriod)
Round up to the nearest hour interval defined by the given period hours. |
static void |
roundUpMillis(java.util.Calendar cal)
Round up the given calendar to the nearest second. |
static void |
roundUpMinutePeriod(java.util.Calendar cal,
int minutePeriod)
Round up to the nearest minute interval defined by the given period minutes. |
static void |
roundUpMinutes(java.util.Calendar cal)
Round up the given calendar to the nearest hour. |
static void |
roundUpSeconds(java.util.Calendar cal)
Round up the given calendar to the nearest minute. |
static boolean |
sameLongValue(java.util.Date date1,
java.util.Date date2)
Return true if the two dates represent the same instant in time as calculated to the nearest millisecond, false otherwise. |
static java.util.Date |
utc2WallClock(java.util.Date utcDate,
int offset)
Return a date that displays as the wall clock time for the given UTC date and offset. |
static java.lang.String |
utcstr(java.util.Date date)
Return a string representation of the given UTC datetime. |
static java.util.Date |
wallClock2UTC(java.util.Date wcDate,
int offset)
Return the original UTC date from the given wall clock display date and the user offset. |
static boolean |
within(java.util.Date date,
int seconds)
Return true if the given date is within the given number of seconds from our current time, false otherwise. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DateUtil()
| Method Detail |
|---|
public static java.lang.String getShortReadDate(java.util.Date date)
public static java.lang.String getShortReadDate(java.util.Calendar cal)
public static java.util.Date dateFromShortRead(java.lang.String datestr)
public static java.lang.String getBasicTime(java.util.Calendar cal)
public static java.lang.String getShortReadDateTime(java.util.Date date)
public static java.lang.String getShortFileDate(java.util.Date date)
public static java.lang.String getShortFileDate(java.util.Calendar cal)
public static java.lang.String getDateTimeAsTextNumber(java.util.Date date)
public static java.lang.String getDateTimeAsTextNumber(java.util.Calendar cal)
public static java.util.Date getDateTimeFromTextNumber(java.lang.String text,
java.util.Calendar cal)
public static java.lang.String getQueryValue(java.util.Date date)
public static java.lang.String getQueryValue(java.util.Calendar cal)
public static boolean within(java.util.Date date,
int seconds)
public static boolean sameLongValue(java.util.Date date1,
java.util.Date date2)
Why not just use java.util.Date.equals? Basically because it doesn't always work. In a WhereWhen message with a field called "start" we added the following instrumentation to the "start" comparison in the generated isEquivalent method:
System.out.println("WhereWhen.isEquivalent: start is different");
System.out.println(" start: " + start);
System.out.println("msg.getStart(): " + msg.getStart());
System.out.println(" start.getTime(): " + start.getTime());
System.out.println("msg.getStart().getTime(): " + msg.getStart().getTime());
which produced the following output:
WhereWhen.isEquivalent: start is different
start: 2006-07-27 14:30:00.0
msg.getStart(): Thu Jul 27 14:30:00 EDT 2006
start.getTime(): 1154025000000
msg.getStart().getTime(): 1154025000000
As you can see, the milliseconds are the same even though Date.equals
said they were not the same. The default output formatting is a
giveaway that the actual Date objects were different, and Date.equals
returns false, but the milliseconds are the same. We need a real
millisecond comparison without any nonsense, which is what this
method does.
public static java.lang.String debug(java.util.Calendar cal)
public static java.util.Date getNowUTC()
public static java.util.Calendar getUTCCalendar()
public static java.util.Calendar initUTCCalendar(java.util.Date date)
public static java.lang.String getUTCQueryValue(java.util.Date date)
public static java.lang.String utcstr(java.util.Date date)
Returns the string "null" if given a null date, just to make debugging use a bit friendlier.
public static java.lang.String getDateTimeAsTextNumberUTC(java.util.Date date)
public static java.lang.String getShortReadDateTimeUTC(java.util.Date date)
public static java.util.Date utc2WallClock(java.util.Date utcDate,
int offset)
public static java.util.Date wallClock2UTC(java.util.Date wcDate,
int offset)
There is a slight chance that we may have passed a DST boundary from the time when we displayed the given date to the time when we are translating it back, but that's pretty unlikely and there's not much we can do about it.
public static void roundUpMillis(java.util.Calendar cal)
public static void roundUpSeconds(java.util.Calendar cal)
public static void roundUpMinutes(java.util.Calendar cal)
public static void roundUpMinutePeriod(java.util.Calendar cal,
int minutePeriod)
public static void roundUpHourPeriod(java.util.Calendar cal,
int hourPeriod)
public static void roundToThresholdHour(java.util.Calendar cal,
int hour)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||