org.jdesktop.swingx.calendar
Class CalendarUtils

java.lang.Object
  extended by org.jdesktop.swingx.calendar.CalendarUtils

public class CalendarUtils
extends Object

Calendar manipulation. PENDING: replace by something tested - as is c&p'ed dateUtils to work on a calendar instead of using long


Field Summary
static int ONE_DAY
           
static int ONE_HOUR
           
static int ONE_MINUTE
           
static int THREE_HOURS
           
 
Constructor Summary
CalendarUtils()
           
 
Method Summary
static boolean areEqual(Date current, Date date)
          Checks the given dates for being equal.
static void endOfDay(Calendar calendar)
          Adjust the given calendar to the last millisecond of the specified date.
static Date endOfDay(Calendar calendar, Date date)
          Adjust the given calendar to the last millisecond of the given date.
static void endOfMonth(Calendar calendar)
          Adjusts the calendar to the end of the current month.
static void endOfWeek(Calendar calendar)
          Adjusts the calendar to the end of the current week.
static Date endOfWeek(Calendar calendar, Date date)
          Adjusts the calendar to the end of the current week.
static Date getEndOfDST(Calendar calendar)
          Adjusts the Calendar to the end of the day of the last day in DST in the current year or unchanged if not using DST.
static Date getStartOfDST(Calendar calendar)
          Adjusts the Calendar to the end of the day of the first day in DST in the current year or unchanged if not using DST.
static boolean isEndOfDay(Calendar calendar)
          Returns a boolean indicating if the given calendar represents the end of a day (in the calendar's time zone).
static boolean isEndOfMonth(Calendar calendar)
          Returns a boolean indicating if the given calendar represents the end of a month (in the calendar's time zone).
static boolean isEndOfWeek(Calendar calendar)
          Returns a boolean indicating if the given calendar represents the end of a week (in the calendar's time zone).
static boolean isSameDay(Calendar today, Date now)
          Returns a boolean indicating whether the given Date is the same day as the day in the calendar.
static boolean isStartOfDay(Calendar calendar)
          Returns a boolean indicating if the given calendar represents the start of a day (in the calendar's time zone).
static boolean isStartOfMonth(Calendar calendar)
          Returns a boolean indicating if the given calendar represents the start of a month (in the calendar's time zone).
static boolean isStartOfWeek(Calendar calendar)
          Returns a boolean indicating if the given calendar represents the start of a month (in the calendar's time zone).
static void startOfDay(Calendar calendar)
          Adjust the given calendar to the first millisecond of the current day.
static Date startOfDay(Calendar calendar, Date date)
          Adjust the given calendar to the first millisecond of the given date.
static void startOfMonth(Calendar calendar)
          Adjusts the calendar to the start of the current month.
static void startOfWeek(Calendar calendar)
          Adjusts the calendar to the start of the current week.
static Date startOfWeek(Calendar calendar, Date date)
          Adjusts the calendar to the start of the current week.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_MINUTE

public static final int ONE_MINUTE
See Also:
Constant Field Values

ONE_HOUR

public static final int ONE_HOUR
See Also:
Constant Field Values

THREE_HOURS

public static final int THREE_HOURS
See Also:
Constant Field Values

ONE_DAY

public static final int ONE_DAY
See Also:
Constant Field Values
Constructor Detail

CalendarUtils

public CalendarUtils()
Method Detail

getEndOfDST

public static Date getEndOfDST(Calendar calendar)
Adjusts the Calendar to the end of the day of the last day in DST in the current year or unchanged if not using DST. Returns the calendar's date or null, if not using DST.

Parameters:
calendar - the calendar to adjust
Returns:
the end of day of the last day in DST, or null if not using DST.

getStartOfDST

public static Date getStartOfDST(Calendar calendar)
Adjusts the Calendar to the end of the day of the first day in DST in the current year or unchanged if not using DST. Returns the calendar's date or null, if not using DST.

Note: the start of the day of the first day in DST is ill-defined!

Parameters:
calendar - the calendar to adjust
Returns:
the start of day of the first day in DST, or null if not using DST.

isStartOfDay

public static boolean isStartOfDay(Calendar calendar)
Returns a boolean indicating if the given calendar represents the start of a day (in the calendar's time zone). The calendar is unchanged.

Parameters:
calendar - the calendar to check.
Returns:
true if the calendar's time is the start of the day, false otherwise.

isEndOfDay

public static boolean isEndOfDay(Calendar calendar)
Returns a boolean indicating if the given calendar represents the end of a day (in the calendar's time zone). The calendar is unchanged.

Parameters:
calendar - the calendar to check.
Returns:
true if the calendar's time is the end of the day, false otherwise.

isStartOfMonth

public static boolean isStartOfMonth(Calendar calendar)
Returns a boolean indicating if the given calendar represents the start of a month (in the calendar's time zone). Returns true, if the time is the start of the first day of the month, false otherwise. The calendar is unchanged.

Parameters:
calendar - the calendar to check.
Returns:
true if the calendar's time is the start of the first day of the month, false otherwise.

isEndOfMonth

public static boolean isEndOfMonth(Calendar calendar)
Returns a boolean indicating if the given calendar represents the end of a month (in the calendar's time zone). Returns true, if the time is the end of the last day of the month, false otherwise. The calendar is unchanged.

Parameters:
calendar - the calendar to check.
Returns:
true if the calendar's time is the end of the last day of the month, false otherwise.

isStartOfWeek

public static boolean isStartOfWeek(Calendar calendar)
Returns a boolean indicating if the given calendar represents the start of a month (in the calendar's time zone). Returns true, if the time is the start of the first day of the month, false otherwise. The calendar is unchanged.

Parameters:
calendar - the calendar to check.
Returns:
true if the calendar's time is the start of the first day of the month, false otherwise.

isEndOfWeek

public static boolean isEndOfWeek(Calendar calendar)
Returns a boolean indicating if the given calendar represents the end of a week (in the calendar's time zone). Returns true, if the time is the end of the last day of the week, false otherwise. The calendar is unchanged.

Parameters:
calendar - the calendar to check.
Returns:
true if the calendar's time is the end of the last day of the week, false otherwise.

startOfWeek

public static void startOfWeek(Calendar calendar)
Adjusts the calendar to the start of the current week. That is, first day of the week with all time fields cleared.

Parameters:
calendar - the calendar to adjust.

endOfWeek

public static void endOfWeek(Calendar calendar)
Adjusts the calendar to the end of the current week. That is, last day of the week with all time fields at max.

Parameters:
calendar - the calendar to adjust.

endOfWeek

public static Date endOfWeek(Calendar calendar,
                             Date date)
Adjusts the calendar to the end of the current week. That is, last day of the week with all time fields at max. The Date of the adjusted Calendar is returned.

Parameters:
calendar - calendar to adjust.
date - the Date to use.
Returns:
the end of the week of the given date

startOfWeek

public static Date startOfWeek(Calendar calendar,
                               Date date)
Adjusts the calendar to the start of the current week. That is, last day of the week with all time fields at max. The Date of the adjusted Calendar is returned.

Parameters:
calendar - calendar to adjust.
date - the Date to use.
Returns:
the start of the week of the given date

startOfMonth

public static void startOfMonth(Calendar calendar)
Adjusts the calendar to the start of the current month. That is, first day of the month with all time fields cleared.

Parameters:
calendar -

endOfMonth

public static void endOfMonth(Calendar calendar)
Adjusts the calendar to the end of the current month. That is the last day of the month with all time-fields at max.

Parameters:
calendar -

startOfDay

public static Date startOfDay(Calendar calendar,
                              Date date)
Adjust the given calendar to the first millisecond of the given date. that is all time fields cleared. The Date of the adjusted Calendar is returned.

Parameters:
calendar - calendar to adjust.
date - the Date to use.
Returns:
the start of the day of the given date

endOfDay

public static Date endOfDay(Calendar calendar,
                            Date date)
Adjust the given calendar to the last millisecond of the given date. that is all time fields cleared. The Date of the adjusted Calendar is returned.

Parameters:
calendar - calendar to adjust.
date - the Date to use.
Returns:
the end of the day of the given date

startOfDay

public static void startOfDay(Calendar calendar)
Adjust the given calendar to the first millisecond of the current day. that is all time fields cleared.

Parameters:
calendar - calendar to adjust.

endOfDay

public static void endOfDay(Calendar calendar)
Adjust the given calendar to the last millisecond of the specified date.

Parameters:
calendar - calendar to adjust.

areEqual

public static boolean areEqual(Date current,
                               Date date)
Checks the given dates for being equal.

Parameters:
current - one of the dates to compare
date - the otherr of the dates to compare
Returns:
true if the two given dates both are null or both are not null and equal, false otherwise.

isSameDay

public static boolean isSameDay(Calendar today,
                                Date now)
Returns a boolean indicating whether the given Date is the same day as the day in the calendar. Calendar and date are unchanged by the check.

Parameters:
today - the Calendar representing a date, must not be null.
now - the date to compare to, must not be null
Returns:
true if the calendar and date represent the same day in the given calendar.