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

StringgetDateDelta(int delta, String dateFormat)
Returns date delta from current time with `dateFormat`
Calendar current = Calendar.getInstance();
current.add(Calendar.DATE, delta);
return formatDate(current.getTime(), dateFormat);
booleanisDateInInterval(Calendar date, int interval, TimeUnit type)
Check if a given date lies in a given interval from today's date.
Calendar diff = Calendar.getInstance();
long today = Calendar.getInstance().getTimeInMillis();
diff.setTimeInMillis(TimeUnit.MILLISECONDS.convert(interval, type));
return (date.getTimeInMillis() - today < diff.getTimeInMillis());
booleanisCurrentTimeInRange(Calendar now, Calendar start, Calendar end)
is Current Time In Range
if (DEBUG)
    Log.d(TAG, "start.before(now)=" + start.before(now));
if (DEBUG)
    Log.d(TAG, "end.after(now)=" + end.after(now));
return start.before(now) && end.after(now);
booleanisFiveMinutesOlder(Calendar updatedAt)
is Five Minutes Older
Calendar rightnow = Calendar.getInstance();
rightnow.add(Calendar.MINUTE, 5);
int compare = updatedAt.compareTo(rightnow);
Log.d(TAG, "compare: " + compare);
return compare < 0;
booleanisPast(String end)
is Past
String[] splitEndStr = end.split(":");
int hrEnd = Integer.parseInt(splitEndStr[0]);
int minEnd = Integer.parseInt(splitEndStr[1]);
Calendar endCal = Calendar.getInstance();
endCal.set(Calendar.HOUR_OF_DAY, hrEnd);
endCal.set(Calendar.MINUTE, minEnd);
Calendar currentCal = Calendar.getInstance();
if (endCal.before(currentCal)) {
...
booleanisOverCurrentDate(int day, int month, int year, int maxDay, int maxMonth, int maxYear)
is Over Current Date
if (year > maxYear)
    return true;
else if (month > maxMonth && year == maxYear)
    return true;
else if (day > maxDay && month == maxMonth && year == maxYear)
    return true;
else
    return false;
...
booleanisUpdateTimeRecently(Calendar currentTime, Calendar updateTime)
is Update Time Recently
for (int i = 0; i < INTERVAL_MINUTE_TO_UPDATE; i++) {
    updateTime.add(Calendar.MINUTE, 1);
if (currentTime.compareTo(updateTime) == 1) {
    return false;
return true;