com.prozima.time
Class TimeUtilities

java.lang.Object
  extended by com.prozima.time.TimeUtilities

public final class TimeUtilities
extends java.lang.Object

Provides static methods which are helpful when operating on Date, Calendar, DayAndYear and TimePeriod classes.


Constructor Summary
TimeUtilities()
           
 
Method Summary
static long calculateDiffInMins(java.util.Date inDateA, java.util.Date inDateB)
          Calculate the difference between two times in minutes.
static void cancelTestTime()
          Cancel current time testing mode.
static TimeConstants.DayOfWeek convertDayOfWeek(int inCalendarDay)
          Converts the day of the week in JDK Calendar format to the Enumerator TimeConstants.DayOfWeek.
static int convertToCalendarInt(TimeConstants.DayOfWeek inDayOfWeek)
          Converts the day of the week in DayOfWeek enum format to an integer constant defined by the Calendar class.
static java.util.Date createDate(int inYear, int inDayOfYear, int inHourOfDay, int inMinutes, int inSeconds)
          Create a Date by specifying the date and time as parameters.
static java.util.Date createDate(int inYear, int inMonth, int inDayOfMonth, int inHourOfDay, int inMinutes, int inSeconds)
          Create a Date by specifying the date and time as parameters.
static TimeConstants.DayOfWeek extractDayOfWeek(java.util.Date inDate)
          Calculate the day of the week for a specific date and time.
static java.util.Date getCurrentTime()
          Query the current time.
static void setTestTime(int inYear, int inMonth, int inDayOfMonth, int inHourOfDay, int inMinutes, int inSeconds)
          Toggle TimeUtilities into testing mode by setting the current time which is always returned by calls to getCurrentTime().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeUtilities

public TimeUtilities()
Method Detail

calculateDiffInMins

public static final long calculateDiffInMins(java.util.Date inDateA,
                                             java.util.Date inDateB)
Calculate the difference between two times in minutes.

Parameters:
inDateA - First date and time being compared.
inDateB - Second date and time to be compared.
Returns:
Difference between the two times in minutes. Difference returned is always positive i.e. absolute difference.

cancelTestTime

public static final void cancelTestTime()
Cancel current time testing mode. All calls to getCurrentTime() will return the actual current time.


convertDayOfWeek

public static final TimeConstants.DayOfWeek convertDayOfWeek(int inCalendarDay)
Converts the day of the week in JDK Calendar format to the Enumerator TimeConstants.DayOfWeek.

Parameters:
inCalendarDay - Day of week in Calendar.DAY_OF_WEEK format.
Returns:
DayofWeek enumerator.

convertToCalendarInt

public static final int convertToCalendarInt(TimeConstants.DayOfWeek inDayOfWeek)
Converts the day of the week in DayOfWeek enum format to an integer constant defined by the Calendar class.

Parameters:
inDayOfWeek - DayOfWeek enumerator.
Returns:
Constant representing the day of the week in Calendar.DAY_OF_WEEK format.

createDate

public static final java.util.Date createDate(int inYear,
                                              int inDayOfYear,
                                              int inHourOfDay,
                                              int inMinutes,
                                              int inSeconds)
Create a Date by specifying the date and time as parameters. Milliseconds are not explicitly set as they are always implicitly set to zero.

Parameters:
inYear - Year. Same constraints as Calendar.YEAR.
inDayOfYear - Day of the year. Same constraints as Calendar.DAY_OF_YEAR.
inHourOfDay - Hour of the day. Same constraints as Calendar.HOUR_OF_DAY.
inMinutes - Minutes. Same constraints as Calendar.MINUTE.
inSeconds - Seconds. Same constraints as Calendar.SECOND.
Returns:
Date as specified by parameters.

createDate

public static final java.util.Date createDate(int inYear,
                                              int inMonth,
                                              int inDayOfMonth,
                                              int inHourOfDay,
                                              int inMinutes,
                                              int inSeconds)
Create a Date by specifying the date and time as parameters. Milliseconds are not explicitly set as they are always implicitly set to zero.

Parameters:
inYear - Year. Same constraints as Calendar.YEAR.
inMonth - Month. Same constraints as Calendar.MONTH.
inDayOfMonth - Day of the month. Same constraints as Calendar.DAY_OF_MONTH.
inHourOfDay - Hour of the day. Same constraints as Calendar.HOUR_OF_DAY.
inMinutes - Minutes. Same constraints as Calendar.MINUTE.
inSeconds - Seconds. Same constraints as Calendar.SECOND.
Returns:
Date as specified by parameters.

extractDayOfWeek

public static TimeConstants.DayOfWeek extractDayOfWeek(java.util.Date inDate)
Calculate the day of the week for a specific date and time.

Parameters:
inDate - Date being queried.
Returns:
DayOfWeek. null is never returned as all dates should have a day.

getCurrentTime

public static final java.util.Date getCurrentTime()
Query the current time. If setTestTime(int, int, int, int, int, int) has been called then this method will always return the same value. In normal mode, it returns a newly created Date.

Returns:
Current date and time. Never returns null.

setTestTime

public static final void setTestTime(int inYear,
                                     int inMonth,
                                     int inDayOfMonth,
                                     int inHourOfDay,
                                     int inMinutes,
                                     int inSeconds)
Toggle TimeUtilities into testing mode by setting the current time which is always returned by calls to getCurrentTime(). Testing mode can be cancelled by a call to cancelTestTime(). Milliseconds are not explicitly set as they are always implicitly set to zero.

Parameters:
inYear - Year. Same constraints as Calendar.
inMonth - Month. Same constraints as Calendar.
inDayOfMonth - Day of the month. Same constraints as Calendar.
inHourOfDay - Hour of the day. Same constraints as Calendar.
inMinutes - Minutes. Same constraints as Calendar.
inSeconds - Seconds. Same constraints as Calendar.