org.jasig.schedassist.model
Class CommonDateOperations

java.lang.Object
  extended by org.jasig.schedassist.model.CommonDateOperations

public final class CommonDateOperations
extends Object

Date and Calendar operations common across this application.

Version:
$Id: CommonDateOperations.java 2511 2010-09-08 15:45:37Z npblair $
Author:
Nicholas Blair, nblair@doit.wisc.edu

Field Summary
protected static String DATE_FORMAT
           
protected static String DATE_TIME_FORMAT
           
 
Constructor Summary
CommonDateOperations()
           
 
Method Summary
static long approximateDifference(Date start, Date end)
          Returns the approximate difference in DAYS between start and end.
static Date beginningOfDay(Date date)
          Return a new Date object that represents the beginning of the same day as the argument, e.g.
static Date calculateSundayPrior(Date date)
          Returns the Sunday prior to the date argument elements of the returned array, respectively.
static Date endOfDay(Date date)
          Return a new Date object that represents the end of the same day as the argument, e.g.
static boolean equalsOrAfter(Date date1, Date date2)
          Returns true if the specified dates are equal OR if date1 is after date2.
static boolean equalsOrBefore(Date date1, Date date2)
          Returns true if the specified dates are equal OR if date1 is before date2.
static SimpleDateFormat getDateFormat()
           
static SimpleDateFormat getDateTimeFormat()
           
static int numberOfDaysUntilSunday(Date date)
          Helper method to calculate the first week's end date.
static Date parseDatePhrase(String datePhrase)
          Convert a String in the common date format for this application into a Date.
static Date parseDateTimePhrase(String timePhrase)
          Convert a String in the common date/time format for this application into a Date.
protected static Calendar zeroOutTimeFields(Calendar calendar)
          Simple method that sets Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, and Calendar.MILLISECOND to 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_TIME_FORMAT

protected static final String DATE_TIME_FORMAT
See Also:
Constant Field Values

DATE_FORMAT

protected static final String DATE_FORMAT
See Also:
Constant Field Values
Constructor Detail

CommonDateOperations

public CommonDateOperations()
Method Detail

getDateTimeFormat

public static SimpleDateFormat getDateTimeFormat()
Returns:
a new instance of SimpleDateFormat that uses this application's common Date/Time format ("yyyyMMdd-HHmm").

getDateFormat

public static SimpleDateFormat getDateFormat()
Returns:
a new instance of SimpleDateFormat that uses this application's common Date format ("yyyyMMdd").

calculateSundayPrior

public static Date calculateSundayPrior(Date date)
Returns the Sunday prior to the date argument elements of the returned array, respectively.

Parameters:
date -
Returns:
the sunday prior to the date argument

parseDateTimePhrase

public static Date parseDateTimePhrase(String timePhrase)
                                throws InputFormatException
Convert a String in the common date/time format for this application into a Date.

Parameters:
timePhrase - format: "yyyyMMdd-HHmm"
Returns:
the corresponding date
Throws:
InputFormatException

parseDatePhrase

public static Date parseDatePhrase(String datePhrase)
                            throws InputFormatException
Convert a String in the common date format for this application into a Date.

Parameters:
datePhrase - format: "yyyyMMdd"
Returns:
the corresponding date
Throws:
InputFormatException

equalsOrAfter

public static boolean equalsOrAfter(Date date1,
                                    Date date2)
Returns true if the specified dates are equal OR if date1 is after date2.

Parameters:
date1 -
date2 -
Returns:
true if date1 is equal to or after date2
See Also:
DateUtils.isSameInstant(Date, Date), Date.after(Date)

equalsOrBefore

public static boolean equalsOrBefore(Date date1,
                                     Date date2)
Returns true if the specified dates are equal OR if date1 is before date2.

Parameters:
date1 -
date2 -
Returns:
true if date1 is equal to or before date2
See Also:
DateUtils.isSameInstant(Date, Date), Date.before(Date)

approximateDifference

public static long approximateDifference(Date start,
                                         Date end)
Returns the approximate difference in DAYS between start and end.

Parameters:
start -
end -
Returns:
the approximate number of days between the 2 dates

numberOfDaysUntilSunday

public static int numberOfDaysUntilSunday(Date date)
Helper method to calculate the first week's end date.

Parameters:
date -
Returns:
the number of days from date until the following Sunday

zeroOutTimeFields

protected static Calendar zeroOutTimeFields(Calendar calendar)
Simple method that sets Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, and Calendar.MILLISECOND to 0.

Parameters:
calendar -
Returns:
a calendar truncated to the beginning of the same day

beginningOfDay

public static Date beginningOfDay(Date date)
Return a new Date object that represents the beginning of the same day as the argument, e.g. 00:00:00.000

Parameters:
date -
Returns:
a new Date object that represents the beginning of the same day as the argument

endOfDay

public static Date endOfDay(Date date)
Return a new Date object that represents the end of the same day as the argument, e.g. 23:59:59.999

Parameters:
date -
Returns:
a new Date object that represents the end of the same day as the argument


Copyright © 2012 Jasig. All Rights Reserved.