|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.clazzes.util.datetime.CalendarHelper
public abstract class CalendarHelper
Static helper functions for calendar objects, which overcome the most painful omissions in the Calendar API.
Field Summary | |
---|---|
static java.util.Comparator<java.util.Calendar> |
DATE_ONLY_COMPARATOR
A comparator instance which compares calendar by their date information only. |
Constructor Summary | |
---|---|
CalendarHelper()
|
Method Summary | |
---|---|
static java.util.Calendar |
cloneToFirstDayOfWeek(java.util.Calendar c)
This function returns a copy of the given calendar, which lies on the first day of the week, where the first day of the week is determined by Calendar.getFirstDayOfWeek() ,
which reflects the locale-specific settings of the given calendar. |
static java.util.Calendar |
cloneToFirstDayOfWeek(java.util.Calendar c,
int firstDayOfWeek)
This function returns a copy of the given calendar, which lies on the first day of the week. |
static int |
daysBetween(java.util.Calendar c1,
java.util.Calendar c2)
Calculate the number of days between the two given dates. |
static int |
monthsBetween(java.util.Calendar c1,
java.util.Calendar c2)
Calculate the number of months between the two given dates. |
static void |
moveToFirstDayOfWeek(java.util.Calendar c)
This function move the given calendar to first day of the week, where the first day of the week is determined by Calendar.getFirstDayOfWeek() ,
which reflects the locale-specific settings of the given calendar. |
static void |
moveToFirstDayOfWeek(java.util.Calendar c,
int firstDayOfWeek)
|
static int |
weeksBetween(java.util.Calendar c1,
java.util.Calendar c2,
int firstDayOfWeek)
Calculate the number of weeks between the two given dates. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.util.Comparator<java.util.Calendar> DATE_ONLY_COMPARATOR
Constructor Detail |
---|
public CalendarHelper()
Method Detail |
---|
public static int daysBetween(java.util.Calendar c1, java.util.Calendar c2)
c1
- The start date.c2
- The end date.
c1
and c2
.public static int weeksBetween(java.util.Calendar c1, java.util.Calendar c2, int firstDayOfWeek)
d1
with d1.get(Calendar.DAY_OF_WEEK) == firstDayInWeek
equal to or before the dates c1
and the last day d2
with d2.get(Calendar.DAY_OF_WEEK) == firstDayInWeek
equal to or before the dates c1
.
The number of weeks is then given by
daysBetween(d1,d2)/7
.
c1
- The start date.c2
- The end date.firstDayOfWeek
- The first day of the week as one of the constants
Calendar.SUNDAY
, ..., Calendar.SATURDAY
..
c1
and c2
.public static void moveToFirstDayOfWeek(java.util.Calendar c, int firstDayOfWeek)
c
- The calendar to move to the first day of week.firstDayOfWeek
- The first day in the week as one of the constants
Calendar.SUNDAY
, ..., Calendar.SATURDAY
.public static void moveToFirstDayOfWeek(java.util.Calendar c)
Calendar.getFirstDayOfWeek()
,
which reflects the locale-specific settings of the given calendar.
c
- The calendar to move to the first day of week.public static java.util.Calendar cloneToFirstDayOfWeek(java.util.Calendar c, int firstDayOfWeek)
c
- The input calendar, which is not modified.firstDayOfWeek
- The first day in the week as one of the constants
Calendar.SUNDAY
, ..., Calendar.SATURDAY
.
r
of c
with
r.get(Calendar.DAY_OF_WEEK)==firstDayInWeek
.public static java.util.Calendar cloneToFirstDayOfWeek(java.util.Calendar c)
Calendar.getFirstDayOfWeek()
,
which reflects the locale-specific settings of the given calendar.
c
- The input calendar, which is not modified.
r
of c
with
r.get(Calendar.DAY_OF_WEEK)==firstDayInWeek
.public static int monthsBetween(java.util.Calendar c1, java.util.Calendar c2)
Calendar.MONTH
and Calendar.YEAR
fields.
c1
- The start date.c2
- The end date.
c1
and c2
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |