org.lateralnz.common.util
Class DateUtils

java.lang.Object
  extended by org.lateralnz.common.util.DateUtils
All Implemented Interfaces:
Constants

public final class DateUtils
extends java.lang.Object
implements Constants

date formatting utilities


Field Summary
static java.util.Date BEGINNING_OF_TIME
          a constant representing the beginning of time (or 01/01/0001)
static java.lang.String DAY_DATE_FORMAT
          a constant format string for the day
static java.util.Date END_OF_TIME
          a constant representing the end of time (or 31/12/9999)
static java.lang.String FRI
          a constant representing "Fri"
static java.lang.String MON
          a constant representing "Mon"
static java.lang.String MONTH_DATE_FORMAT
          a constant format string for the month
static long ONE_DAY_IN_MILLISECONDS
          a constant for the number of milliseconds in a day
static java.lang.String REVERSE_DATE_FORMAT
          a constant format string for the reverse data (yyyyMMdd)
static java.lang.String REVERSE_DATE_TIME_FORMAT
          a constant format string for the date and tim (yyyyMMddhhmmss)
static java.lang.String SAT
          a constant representing "Sat"
static java.lang.String SUN
          a constant representing "Sun"
static java.lang.String THURS
          a constant representing "Thurs"
static java.lang.String TUES
          a constant representing "Tues"
static java.lang.String WED
          a constant representing "Wed"
static java.lang.String YEAR_DATE_FORMAT
          a constant format string for the year
 
Fields inherited from interface org.lateralnz.common.util.Constants
AMPERSAND, AND, APPLICATION_X_WWW_FORM_URLENCODED, ASTERISK, AT, BACK_SLASH, CHAR_LEFT_CHEV, CHAR_RIGHT_CHEV, COLON, COMMA, CRLF, DASH, DELETE, DOLLAR, DOT, DOT_CLASS, DOT_JAVA, EIGHT, EMPTY, EQUALS, FALSE, FILE_SEPARATOR, FIVE, FORWARD_SLASH, FOUR, FULLSTOP, HASH, HAT, INSERT, LEFT_BRACE, LEFT_BRACKET, LEFT_CHEV, MAX_LEN_APPCODE, MAX_LEN_APPGROUP, MAX_LEN_MSGCODE, MAX_LEN_MSGTEXT, MINUS_ONE, N, NEWLINE, NINE, NO, NULL_STRING, OFF, ON, ONE, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_WEEK, PATH_SEPARATOR, PERCENT, PIPE, PLUS, QUESTION_MARK, QUOTE, REQUIRED, REQUIRES_NEW, RETURN, RIGHT_BRACE, RIGHT_BRACKET, RIGHT_CHEV, SELECT, SEMICOLON, SEVEN, SINGLE_QUOTE, SIX, SPACE, SQ_LEFT_BRACKET, SQ_RIGHT_BRACKET, SUPPORTS, TEXT_HTML, TEXT_PLAIN, TEXT_XML, THREE, TRUE, TWO, UNDERSCORE, UPDATE, UTF_8, Y, YES, ZERO
 
Method Summary
static java.util.Date add(java.util.Date date, int field, int amount)
          add a value to a particular field (ie.
static java.util.Date addDays(java.util.Date date, int days)
          add a number of days to a date (basically a wrapper call to "add")
static java.util.Date applyTime(java.util.Date d, java.lang.String time)
          apply a string time value to a date object
static java.lang.String formatDate(java.lang.String callerClassName, java.util.Date d, java.util.Locale locale, java.lang.String pattern)
          converts a date object into a string representation using a cached simpledateformat
static java.lang.String formatDate(java.lang.String callerClassName, java.util.Date d, java.lang.String pattern)
          converts a date object into a string representation using a cached simpledateformat
static java.lang.String getCurrentMonthAsString()
          Get a string representation of the month+year of current date.
static java.util.List getDateRangeList(java.util.Date start, java.util.Date end)
          get a list of date objects starting from 'start' and finishing -before- 'end'.
static int getDaysBetween(java.util.Date d1, java.util.Date d2)
           
static java.lang.String getShortDay(java.util.Date date)
          get a string representation of the day of the week the specified date represents
static java.lang.String getShortDay(int dayOfWeek)
          get a string representation of a day of week (eg.
static java.util.Date getStartOfWeek(java.util.Date d)
          get the first day of the week based upon the specified date (looks backwards from the date specified until it finds the monday)
static boolean isEqualUsingPattern(java.lang.String callerClassName, java.util.Date d1, java.util.Date d2, java.util.Locale locale, java.lang.String pattern)
          returns true if two dates are equal using a particular date pattern
static boolean isEqualUsingPattern(java.lang.String callerClassName, java.util.Date d1, java.util.Date d2, java.lang.String pattern)
          returns true if two dates are equal using a particular date pattern
static java.util.Date parseDate(java.lang.String callerClassName, java.lang.String s, java.util.Locale locale, java.lang.String pattern)
          turns a string representation of a date into a date object using a cached format
static java.util.Date parseDate(java.lang.String callerClassName, java.lang.String s, java.lang.String pattern)
          turns a string representation of a date into a date object using a cached format
static java.util.Date setTime(java.lang.String callerClassName, java.util.Date d, java.lang.String time, java.lang.String timeformat)
          takes a date object and sets a time value against it
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MON

public static final java.lang.String MON
a constant representing "Mon"

See Also:
Constant Field Values

TUES

public static final java.lang.String TUES
a constant representing "Tues"

See Also:
Constant Field Values

WED

public static final java.lang.String WED
a constant representing "Wed"

See Also:
Constant Field Values

THURS

public static final java.lang.String THURS
a constant representing "Thurs"

See Also:
Constant Field Values

FRI

public static final java.lang.String FRI
a constant representing "Fri"

See Also:
Constant Field Values

SAT

public static final java.lang.String SAT
a constant representing "Sat"

See Also:
Constant Field Values

SUN

public static final java.lang.String SUN
a constant representing "Sun"

See Also:
Constant Field Values

DAY_DATE_FORMAT

public static final java.lang.String DAY_DATE_FORMAT
a constant format string for the day

See Also:
Constant Field Values

MONTH_DATE_FORMAT

public static final java.lang.String MONTH_DATE_FORMAT
a constant format string for the month

See Also:
Constant Field Values

YEAR_DATE_FORMAT

public static final java.lang.String YEAR_DATE_FORMAT
a constant format string for the year

See Also:
Constant Field Values

REVERSE_DATE_FORMAT

public static final java.lang.String REVERSE_DATE_FORMAT
a constant format string for the reverse data (yyyyMMdd)

See Also:
Constant Field Values

REVERSE_DATE_TIME_FORMAT

public static final java.lang.String REVERSE_DATE_TIME_FORMAT
a constant format string for the date and tim (yyyyMMddhhmmss)

See Also:
Constant Field Values

ONE_DAY_IN_MILLISECONDS

public static final long ONE_DAY_IN_MILLISECONDS
a constant for the number of milliseconds in a day

See Also:
Constant Field Values

BEGINNING_OF_TIME

public static java.util.Date BEGINNING_OF_TIME
a constant representing the beginning of time (or 01/01/0001)


END_OF_TIME

public static java.util.Date END_OF_TIME
a constant representing the end of time (or 31/12/9999)

Method Detail

add

public static final java.util.Date add(java.util.Date date,
                                       int field,
                                       int amount)
add a value to a particular field (ie. day, month, year) of a date. Note: if you want to subtract, then add -1, -2, etc

Parameters:
date - the date object to add to
field - the field of the date (see Calendar for fields)
amount - the amount to add (or subtract if a negative number)
Returns:
a new date object

addDays

public static final java.util.Date addDays(java.util.Date date,
                                           int days)
add a number of days to a date (basically a wrapper call to "add")


applyTime

public static final java.util.Date applyTime(java.util.Date d,
                                             java.lang.String time)
apply a string time value to a date object

Parameters:
d - the date object to apply time to
time - the time to apply as one of "hh", "hhmm" or "hhmmss"

getCurrentMonthAsString

public static final java.lang.String getCurrentMonthAsString()
Get a string representation of the month+year of current date. For instance, if it's "15/07/2003", this method returns "072003".


getDateRangeList

public static final java.util.List getDateRangeList(java.util.Date start,
                                                    java.util.Date end)
get a list of date objects starting from 'start' and finishing -before- 'end'. Note: start must be after end

Parameters:
start - the date to start with
end - the date to end with

getDaysBetween

public static final int getDaysBetween(java.util.Date d1,
                                       java.util.Date d2)

getShortDay

public static final java.lang.String getShortDay(int dayOfWeek)
get a string representation of a day of week (eg. "Mon", "Tues", etc)

Returns:
a string representation of the day

getShortDay

public static final java.lang.String getShortDay(java.util.Date date)
get a string representation of the day of the week the specified date represents

Parameters:
date - the date object to use

getStartOfWeek

public static final java.util.Date getStartOfWeek(java.util.Date d)
get the first day of the week based upon the specified date (looks backwards from the date specified until it finds the monday)


formatDate

public static final java.lang.String formatDate(java.lang.String callerClassName,
                                                java.util.Date d,
                                                java.lang.String pattern)
converts a date object into a string representation using a cached simpledateformat

Parameters:
callerClassName - the class of the object calling this method (used for caching)
d - the date to convert
pattern - the date format to use

formatDate

public static final java.lang.String formatDate(java.lang.String callerClassName,
                                                java.util.Date d,
                                                java.util.Locale locale,
                                                java.lang.String pattern)
converts a date object into a string representation using a cached simpledateformat

Parameters:
callerClassName - the class of the object calling this method (used for caching)
d - the date to convert
locale - the locale to use in conversion
pattern - the date format to use

parseDate

public static final java.util.Date parseDate(java.lang.String callerClassName,
                                             java.lang.String s,
                                             java.lang.String pattern)
                                      throws java.text.ParseException
turns a string representation of a date into a date object using a cached format

Parameters:
callerClassName - the class of the object calling this method (used for caching)
s - the string date to convert
pattern - the date format to use
Throws:
java.text.ParseException

parseDate

public static final java.util.Date parseDate(java.lang.String callerClassName,
                                             java.lang.String s,
                                             java.util.Locale locale,
                                             java.lang.String pattern)
                                      throws java.text.ParseException
turns a string representation of a date into a date object using a cached format

Parameters:
callerClassName - the class of the object calling this method (used for caching)
s - the string date to convert
locale - the locale to use in conversion
pattern - the date format to use
Throws:
java.text.ParseException

isEqualUsingPattern

public static final boolean isEqualUsingPattern(java.lang.String callerClassName,
                                                java.util.Date d1,
                                                java.util.Date d2,
                                                java.lang.String pattern)
                                         throws java.text.ParseException
returns true if two dates are equal using a particular date pattern

Parameters:
callerClassName - the class of the object calling this method (used for caching)
d1 - the first date
d2 - the second date
pattern - the date format to compare the two date objects by
Throws:
java.text.ParseException

isEqualUsingPattern

public static final boolean isEqualUsingPattern(java.lang.String callerClassName,
                                                java.util.Date d1,
                                                java.util.Date d2,
                                                java.util.Locale locale,
                                                java.lang.String pattern)
                                         throws java.text.ParseException
returns true if two dates are equal using a particular date pattern

Parameters:
callerClassName - the class of the object calling this method (used for caching)
d1 - the first date
d2 - the second date
locale - the locale to use when comparing the dates
pattern - the date format to compare the two date objects by
Throws:
java.text.ParseException

setTime

public static final java.util.Date setTime(java.lang.String callerClassName,
                                           java.util.Date d,
                                           java.lang.String time,
                                           java.lang.String timeformat)
                                    throws java.text.ParseException
takes a date object and sets a time value against it

Parameters:
callerClassName - the class of the object calling this method (used for caching)
d - the date object to use
time - the string representation of the time to set on the date object
timeformat - the format of the time
Throws:
java.text.ParseException