|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.swingx.calendar.CalendarUtils
public class CalendarUtils
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 |
DECADE
|
static int |
ONE_DAY
|
static int |
ONE_HOUR
|
static int |
ONE_MINUTE
|
static int |
THREE_HOURS
|
static int |
YEAR_IN_DECADE
|
Constructor Summary | |
---|---|
CalendarUtils()
|
Method Summary | |
---|---|
static void |
add(Calendar calendar,
int field,
int amount)
Increments the calendar field of the given calendar by amount. |
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 int |
get(Calendar calendar,
int field)
Gets the calendar field of the given calendar by amount. |
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 |
isFlushed(Calendar calendar)
Returns a boolean to indicate whether the given calendar is flushed. |
static boolean |
isSame(Calendar today,
Date now,
int field)
Returns a boolean indicating whether the given Date is in the same period as the Date in the calendar, as defined by the calendar field. |
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 |
isStartOf(Calendar calendar,
int field)
Returns a boolean indicating if the calendar is set to the start of a period as defined by the given field. |
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 |
isStartOfDecade(Calendar calendar)
Returns a boolean indicating if the given calendar represents the start of a decade (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 boolean |
isStartOfYear(Calendar calendar)
Returns a boolean indicating if the given calendar represents the start of a year (in the calendar's time zone). |
static void |
set(Calendar calendar,
int field,
int value)
Sets the calendar field of the given calendar by amount. |
static void |
startOf(Calendar calendar,
int field)
Adjusts the given calendar to the start of the period as indicated by the given field. |
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 |
startOfDecade(Calendar calendar)
Adjusts the given Calendar to the start of the decade. |
static Date |
startOfDecade(Calendar calendar,
Date date)
Adjusts the given Calendar to the start of the decade as defined by 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. |
static void |
startOfYear(Calendar calendar)
Adjusts the given Calendar to the start of the year. |
static Date |
startOfYear(Calendar calendar,
Date date)
Adjusts the given Calendar to the start of the year as defined by the given date. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ONE_MINUTE
public static final int ONE_HOUR
public static final int THREE_HOURS
public static final int ONE_DAY
public static final int DECADE
public static final int YEAR_IN_DECADE
Constructor Detail |
---|
public CalendarUtils()
Method Detail |
---|
public static void add(Calendar calendar, int field, int amount)
calendar
- field
- the field to increment, allowed are all fields known to
Calendar plus DECADE.amount
-
IllegalArgumentException
public static int get(Calendar calendar, int field)
calendar
- field
- the field to get, allowed are all fields known to
Calendar plus DECADE.
IllegalArgumentException
public static void set(Calendar calendar, int field, int value)
NOTE: the custom field implementations are very naive (JSR-310 will do better) - for decade: value must be positive, value must be a multiple of 10 and is interpreted as the first-year-of-the-decade - for year-in-decade: value is added/substracted to/from the start-of-decade of the date of the given calendar
calendar
- field
- the field to increment, allowed are all fields known to
Calendar plus DECADE.value
- the decade to set, must be a
IllegalArgumentException
- if the field is unsupported or the value is
not dividable by 10 or negative.public static Date getEndOfDST(Calendar calendar)
calendar
- the calendar to adjust
public static Date getStartOfDST(Calendar calendar)
Note: the start of the day of the first day in DST is ill-defined!
calendar
- the calendar to adjust
public static boolean isStartOfDay(Calendar calendar)
calendar
- the calendar to check.
public static boolean isEndOfDay(Calendar calendar)
calendar
- the calendar to check.
public static boolean isStartOfMonth(Calendar calendar)
calendar
- the calendar to check.
public static boolean isEndOfMonth(Calendar calendar)
calendar
- the calendar to check.
public static boolean isStartOfWeek(Calendar calendar)
calendar
- the calendar to check.
public static boolean isEndOfWeek(Calendar calendar)
calendar
- the calendar to check.
public static void startOfWeek(Calendar calendar)
calendar
- the calendar to adjust.public static void endOfWeek(Calendar calendar)
calendar
- the calendar to adjust.public static Date endOfWeek(Calendar calendar, Date date)
calendar
- calendar to adjust.date
- the Date to use.
public static Date startOfWeek(Calendar calendar, Date date)
calendar
- calendar to adjust.date
- the Date to use.
public static void startOfDecade(Calendar calendar)
calendar
- the calendar to adjust.public static Date startOfDecade(Calendar calendar, Date date)
calendar
- calendar to adjust.date
- the Date to use.
public static boolean isStartOfDecade(Calendar calendar)
calendar
- the calendar to check.
public static void startOfYear(Calendar calendar)
calendar
- the calendar to adjust.public static Date startOfYear(Calendar calendar, Date date)
calendar
- calendar to adjust.date
- the Date to use.
public static boolean isStartOfYear(Calendar calendar)
calendar
- the calendar to check.
public static void startOfMonth(Calendar calendar)
calendar
- calendar to adjust.public static void endOfMonth(Calendar calendar)
calendar
- calendar to adjust.public static Date startOfDay(Calendar calendar, Date date)
calendar
- calendar to adjust.date
- the Date to use.
public static Date endOfDay(Calendar calendar, Date date)
calendar
- calendar to adjust.date
- the Date to use.
public static void startOfDay(Calendar calendar)
calendar
- calendar to adjust.public static void endOfDay(Calendar calendar)
calendar
- calendar to adjust.public static void startOf(Calendar calendar, int field)
calendar
- field
- the period to adjust, allowed are Calendar.DAY_OF_MONTH, -.MONTH,
-.WEEK and YEAR and CalendarUtils.DECADE.public static boolean isStartOf(Calendar calendar, int field)
calendar
- field
- the period to adjust, allowed are Calendar.DAY_OF_MONTH, -.MONTH,
-.WEEK and YEAR and CalendarUtils.DECADE.
IllegalArgumentException
- if the field is not supported.public static boolean areEqual(Date current, Date date)
current
- one of the dates to comparedate
- the otherr of the dates to compare
public static boolean isSameDay(Calendar today, Date now)
today
- the Calendar representing a date, must not be null.now
- the date to compare to, must not be null
public static boolean isSame(Calendar today, Date now, int field)
today
- the Calendar representing a date, must not be null.now
- the date to compare to, must not be null
public static boolean isFlushed(Calendar calendar)
The only way to guarantee a flushed state is to let client code call getTime or getTimeInMillis. See Despairing in Calendar
Note: this if for testing only and not entirely safe!
calendar
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |