Android Utililty Methods Calendar Compare

List of utility methods to do Calendar Compare

Description

The list of methods to do Calendar Compare are organized into topic(s).

Method

intcompare(Calendar c1, Calendar c2, int what)
compare
int number = 0;
switch (what) {
case Calendar.YEAR:
    number = c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR);
    break;
case Calendar.MONTH:
    int years = compare(c1, c2, Calendar.YEAR);
    number = 12 * years
...
intcompareCurrentDate(String currentDate)
compare Current Date
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date objDate = df.parse(currentDate);
return compareDate(objDate, nowAsDate(), Calendar.DATE);
booleanisAfterRollingTime(Calendar date)
Check if current time is after 19h30
Calendar today = getCalendar();
today.setTime(date.getTime());
Calendar endRollingTime = getCalendar(today.get(Calendar.YEAR),
        today.get(Calendar.MONTH),
        today.get(Calendar.DAY_OF_MONTH), HOUR_END_ROLLING,
        MINUTE_END_ROLLING);
if (DEBUG)
    Log.d(TAG, "now=" + date.getTime());
...
booleanisAfterRollingTimeOut(Calendar date)
Check if current time is after 19h45
Calendar today = getCalendar();
today.setTime(date.getTime());
Calendar endRollingTime = getCalendar(today.get(Calendar.YEAR),
        today.get(Calendar.MONTH),
        today.get(Calendar.DAY_OF_MONTH), HOUR_ROLLING_TIMEOUT,
        MINUTE_ROLLING_TIMEOUT);
if (DEBUG)
    Log.d(TAG, "now=" + date.getTime());
...
booleanisBeforeRollingEndTime(Calendar date)
Check if current time is before 19h30
Calendar today = getCalendar();
today.setTime(date.getTime());
Calendar endRollingTime = getCalendar(today.get(Calendar.YEAR),
        today.get(Calendar.MONTH),
        today.get(Calendar.DAY_OF_MONTH), HOUR_END_ROLLING,
        MINUTE_END_ROLLING);
if (DEBUG)
    Log.d(TAG, "now=" + date.getTime());
...
booleanisBeforeRollingTime(Calendar date)
Check if current time is before 19h15
Calendar today = getCalendar();
today.setTime(date.getTime());
Calendar startRollingTime = getCalendar(today.get(Calendar.YEAR),
        today.get(Calendar.MONTH),
        today.get(Calendar.DAY_OF_MONTH), HOUR_START_ROLLING,
        MINUTE_START_ROLLING);
if (DEBUG)
    Log.d(TAG, "now=" + date.getTime());
...
booleanisSameDay(Calendar calSource, Calendar calDesti)
is Same Day
if (calSource == null || calDesti == null) {
    throw new IllegalArgumentException("The date must not be null");
return calSource.get(Calendar.ERA) == calDesti.get(Calendar.ERA)
        && calSource.get(Calendar.YEAR) == calDesti
                .get(Calendar.YEAR)
        && calSource.get(Calendar.DAY_OF_YEAR) == calDesti
                .get(Calendar.DAY_OF_YEAR);
...
booleanisSameInstant(Calendar cal1, Calendar cal2)
is Same Instant
if (cal1 == null || cal2 == null) {
    throw new IllegalArgumentException("The date must not be null");
return cal1.getTime().getTime() == cal2.getTime().getTime();
booleanisSameLocalTime(Calendar calSource, Calendar calDesti)
is Same Local Time
return calSource.equals(calDesti);
intcompare(Calendar d1, Calendar d2)
compare
int result = 0;
if (d1 == null && d2 == null)
    return result;
if (d1 == null)
    return -1;
if (d2 == null)
    return 1;
if (d1.after(d2))
...