org.oddjob.schedules
Class CalendarUtils

java.lang.Object
  extended by org.oddjob.schedules.CalendarUtils

public class CalendarUtils
extends Object


Constructor Summary
CalendarUtils(Calendar baseCalendar)
          Constructor base on an existing calendar.
CalendarUtils(Date inDate, TimeZone timeZone)
          Constructor.
 
Method Summary
 Calendar dayOfMonth(DayOfMonth dayOfMonth)
          Utility function to get a calendar which represents the day of the month in which the reference date is.
 Calendar dayOfWeek(DayOfWeek dayOfWeek)
          Utility function to get a calendar which represents the day of the week from the reference date.
 Calendar dayOfWeekInMonth(DayOfWeek dayOfWeek, WeekOfMonth week)
           
 Calendar dayOfYear(int dayOfMonth, int month)
          Calendar for the day of year.
 Calendar endOfDay()
          Calculate start of the day after.
 Calendar endOfMonth()
          Calculate the date at the end of the month for the given date.
static Calendar endOfWeek(Date inDate, TimeZone timeZone)
          Calculate the start of the week for the given date.
 Calendar endOfWeekOfMonth(WeekOfMonth week)
           
static Calendar endOfYear(Date referenceDate, TimeZone timeZone)
          Calcuate the date at the end of the year from the given date.
 Calendar forDate(Date date)
          Return a new calendar with the base calendar time zone but a different date.
static Calendar monthOfYear(Date referenceDate, int month, TimeZone timeZone)
          Utility function to get the start of the month as a Calendar.
static void setEndOfDay(Calendar calendar)
          Set the calendar to the end of day.
static void setEndOfMonth(Calendar calendar)
          Set the calendar to the end of the month.
 Calendar startOfDay()
          Calculate the start of day date time (i.e.
 Calendar startOfMonth()
          Calculate the date at the start of the month for the given date.
static Calendar startOfWeek(Date inDate, TimeZone timeZone)
          Calculate the start of the week for the given date.
 Calendar startOfWeekOfMonth(WeekOfMonth week)
           
static Calendar startOfYear(Date referenceDate, TimeZone timeZone)
          Calculate the date at the start of the year for the given date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CalendarUtils

public CalendarUtils(Date inDate,
                     TimeZone timeZone)
Constructor.

Parameters:
inDate - The date to base functionality on.
timeZone - The timezone for the calendar

CalendarUtils

public CalendarUtils(Calendar baseCalendar)
Constructor base on an existing calendar.

Parameters:
baseCalendar -
Method Detail

forDate

public Calendar forDate(Date date)
Return a new calendar with the base calendar time zone but a different date.

Parameters:
date - The date.
Returns:
The new calendar.

startOfDay

public Calendar startOfDay()
Calculate the start of day date time (i.e. at 00:00) for a given date.

Returns:
The Calendar at the start of the day.

endOfDay

public Calendar endOfDay()
Calculate start of the day after.

Returns:
The Calendar at the start of the next day.

setEndOfDay

public static void setEndOfDay(Calendar calendar)
Set the calendar to the end of day.

Parameters:
calendar - The calendar that will be set.

setEndOfMonth

public static void setEndOfMonth(Calendar calendar)
Set the calendar to the end of the month.

Parameters:
calendar - The calendar that will be set.

startOfMonth

public Calendar startOfMonth()
Calculate the date at the start of the month for the given date.

Returns:
The date at the start of the month.

endOfMonth

public Calendar endOfMonth()
Calculate the date at the end of the month for the given date.

Returns:
The calendar at the end of the month.

dayOfMonth

public Calendar dayOfMonth(DayOfMonth dayOfMonth)
Utility function to get a calendar which represents the day of the month in which the reference date is.

Parameters:
day - The day.
Returns:
The Calendar.

startOfWeekOfMonth

public Calendar startOfWeekOfMonth(WeekOfMonth week)

endOfWeekOfMonth

public Calendar endOfWeekOfMonth(WeekOfMonth week)

dayOfWeekInMonth

public Calendar dayOfWeekInMonth(DayOfWeek dayOfWeek,
                                 WeekOfMonth week)

startOfWeek

public static Calendar startOfWeek(Date inDate,
                                   TimeZone timeZone)
Calculate the start of the week for the given date.

Parameters:
inDate - The given date.
Returns:
The date at the start of the month.

endOfWeek

public static Calendar endOfWeek(Date inDate,
                                 TimeZone timeZone)
Calculate the start of the week for the given date.

Parameters:
inDate - The given date.
Returns:
The date at the start of the month.

dayOfWeek

public Calendar dayOfWeek(DayOfWeek dayOfWeek)
Utility function to get a calendar which represents the day of the week from the reference date.

Parameters:
day - The day.

startOfYear

public static Calendar startOfYear(Date referenceDate,
                                   TimeZone timeZone)
Calculate the date at the start of the year for the given date.

Parameters:
referenceDate - The given date.
Returns:
The calendar at the start of the year.

endOfYear

public static Calendar endOfYear(Date referenceDate,
                                 TimeZone timeZone)
Calcuate the date at the end of the year from the given date.

Parameters:
referenceDate - The given date.
Returns:
The calendar at the end of the year.

dayOfYear

public Calendar dayOfYear(int dayOfMonth,
                          int month)
Calendar for the day of year.

Parameters:
referenceDate - The date to take year from.
dayOfYear - The day of the year.
Returns:
The calendar.

monthOfYear

public static Calendar monthOfYear(Date referenceDate,
                                   int month,
                                   TimeZone timeZone)
Utility function to get the start of the month as a Calendar.

Parameters:
referenceDate - The whole date.
month - The month to calculate the start of. 1 is January, 12 is December.
Returns:
The start of the month.