jgnash.util
Class DateUtils

java.lang.Object
  extended by jgnash.util.DateUtils

public class DateUtils
extends java.lang.Object

Static methods to make working with dates a bit easier

Version:
$Id$
Author:
Craig Cavanaugh, Vincent Frison

Field Summary
private static java.lang.ref.WeakReference<java.util.Calendar> wC
          WeakReference to the reusable Calendar instance
private static java.lang.ref.WeakReference<java.util.Calendar> wGc
          WeakReference to the reusable GregorianCalendar instance
 
Constructor Summary
private DateUtils()
           
 
Method Summary
static boolean after(java.util.Date d1, java.util.Date d2)
          Determines is Date d1 occurs after Date d2.
static boolean after(java.util.Date d1, java.util.Date d2, boolean inclusive)
          Determines if Date d1 occurs after Date d2.
static boolean before(java.util.Date d1, java.util.Date d2)
          Determines if Date d1 occurs before Date d2.
static boolean before(java.util.Date d1, java.util.Date d2, boolean inclusive)
          Determines if Date d1 occurs before Date d2.
static java.util.Date firstDayOfMonth(java.util.Date date)
          Returns a leveled date representing the first day of the month based on a specified date.
private static java.util.Calendar getCal()
           
private static java.util.GregorianCalendar getGCal()
           
private static java.util.Date[] getQuarterBounds(java.util.Date date)
          Returns an array of quarter bound dates of the year based on a specified date.
static int getQuarterNumber(java.util.Date date)
          Returns the number of the quarter (i.e.
static java.text.DateFormat getShortDateFormat()
          Generates a customized DateFormat with constant width for all dates.
static java.util.Date lastDayOfMonth(java.util.Date date)
          Returns a leveled date representing the last day of the month based on a specified date.
static java.util.Date lastDayOfMonth(int month, int year)
          Returns a leveled date representing the last day of the month
static java.util.Date lastDayOfQuarter(java.util.Date bdate)
          Returns a leveled date representing the last day of the quarter based on a specified date.
static java.util.Date lastDayOfYear(java.util.Date date)
          Returns a leveled date representing the last day of the year based on a specified date.
static java.util.List<java.util.Date> lastDaysOfMonth(java.util.Date startDate, java.util.Date endDate)
          Generates an array of dates ending on the last day of every month between the start and stop dates.
static java.util.Date[] lastDaysOfMonth(int year)
          Generates an array of dates ending on the last day of every month in the specified year
static java.util.Date levelDate(java.util.Date date)
          Levels the date so that only the day, month, and year are significant.
static java.util.Date nextDay(java.util.Date date)
           
static java.util.Date nextMonth(java.util.Date date)
           
static java.util.Date nextWeek(java.util.Date date)
          Returns a date one week later than the provided date
static java.util.Date nextYear(java.util.Date date)
          Returns a date one year later than the provided date
static java.util.Date previousDay(java.util.Date date)
           
static java.util.Date previousMonth(java.util.Date date)
           
static java.util.Date previousYear(java.util.Date date)
          Returns a date one year earlier than the provided date
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wGc

private static java.lang.ref.WeakReference<java.util.Calendar> wGc
WeakReference to the reusable GregorianCalendar instance


wC

private static java.lang.ref.WeakReference<java.util.Calendar> wC
WeakReference to the reusable Calendar instance

Constructor Detail

DateUtils

private DateUtils()
Method Detail

getShortDateFormat

public static java.text.DateFormat getShortDateFormat()
Generates a customized DateFormat with constant width for all dates.

Returns:
a short DateFormat

levelDate

public static java.util.Date levelDate(java.util.Date date)
Levels the date so that only the day, month, and year are significant. This is synchronized so that the reusable calendar instance does not get get out of sync if multiple threads try to use it.


before

public static boolean before(java.util.Date d1,
                             java.util.Date d2,
                             boolean inclusive)
Determines if Date d1 occurs before Date d2. The dates are leveled prior to evaluation


before

public static boolean before(java.util.Date d1,
                             java.util.Date d2)
Determines if Date d1 occurs before Date d2. The specified dates are inclusive

Parameters:
d1 - date 1
d2 - date 2
Returns:
true if d1 is before d2 or the same date

after

public static boolean after(java.util.Date d1,
                            java.util.Date d2,
                            boolean inclusive)
Determines if Date d1 occurs after Date d2. The dates are leveled prior to evaluation


after

public static boolean after(java.util.Date d1,
                            java.util.Date d2)
Determines is Date d1 occurs after Date d2. The specified dates are inclusive.

Parameters:
d1 - date 1
d2 - date 2
Returns:
true if d1 is after d2

lastDayOfMonth

public static java.util.Date lastDayOfMonth(int month,
                                            int year)
Returns a leveled date representing the last day of the month

Parameters:
month - The month (index starts at 0)
year - The year (index starts at 1)
Returns:
The last day of the month and year specified

lastDayOfMonth

public static java.util.Date lastDayOfMonth(java.util.Date date)
Returns a leveled date representing the last day of the month based on a specified date.

Parameters:
date - the base date to work from
Returns:
The last day of the month and year specified

firstDayOfMonth

public static java.util.Date firstDayOfMonth(java.util.Date date)
Returns a leveled date representing the first day of the month based on a specified date. (Should always be one?)

Parameters:
date - the base date to work from
Returns:
The last day of the month and year specified

lastDaysOfMonth

public static java.util.Date[] lastDaysOfMonth(int year)
Generates an array of dates ending on the last day of every month in the specified year

Parameters:
year - The year to generate the array for
Returns:
The array of dates

lastDaysOfMonth

public static java.util.List<java.util.Date> lastDaysOfMonth(java.util.Date startDate,
                                                             java.util.Date endDate)
Generates an array of dates ending on the last day of every month between the start and stop dates.

Parameters:
startDate - The date to start at
endDate - The data to stop at
Returns:
The array of dates

lastDayOfQuarter

public static java.util.Date lastDayOfQuarter(java.util.Date bdate)
Returns a leveled date representing the last day of the quarter based on a specified date.

Parameters:
bdate - the base date to work from
Returns:
The last day of the quarter specified

lastDayOfYear

public static java.util.Date lastDayOfYear(java.util.Date date)
Returns a leveled date representing the last day of the year based on a specified date.

Parameters:
date - the base date to work from
Returns:
The last day of the year specified

getQuarterBounds

private static java.util.Date[] getQuarterBounds(java.util.Date date)
Returns an array of quarter bound dates of the year based on a specified date. The order is q1s, q1e, q2s, q2e, q3s, q3e, q4s, q4e.

Parameters:
date - the base date to work from
Returns:
The array of quarter bound dates

getQuarterNumber

public static int getQuarterNumber(java.util.Date date)
Returns the number of the quarter (i.e. 1, 2, 3 or 4) based on a specified date.

Parameters:
date - the base date to work from
Returns:
The number of the quarter specified

getGCal

private static java.util.GregorianCalendar getGCal()
Returns:
an instance of a GregorianCalendar

getCal

private static java.util.Calendar getCal()
Returns:
an instance of a Calendar

nextDay

public static java.util.Date nextDay(java.util.Date date)

nextMonth

public static java.util.Date nextMonth(java.util.Date date)

previousMonth

public static java.util.Date previousMonth(java.util.Date date)

previousDay

public static java.util.Date previousDay(java.util.Date date)

nextWeek

public static java.util.Date nextWeek(java.util.Date date)
Returns a date one week later than the provided date


nextYear

public static java.util.Date nextYear(java.util.Date date)
Returns a date one year later than the provided date


previousYear

public static java.util.Date previousYear(java.util.Date date)
Returns a date one year earlier than the provided date