/** * Checks whether the given date is included in this period. When the useTime flag is true, the * time of the parameter (date) and the time of the begin and end dates of the period are taken * into account to compute the result. When the useTime flag is false, the dates are truncated to * compute the result. */ public boolean includes(final Calendar date) { if (date == null) { return false; } else if (begin == null && end == null) { return true; } else { if (useTime) { if (begin == null) { return !date.after(end); } else if (end == null) { return !date.before(begin); } else { return !date.before(begin) && !date.after(end); } } else { final Calendar tDate = DateUtils.truncate(date, Calendar.DATE); Calendar tBegin = begin; Calendar tEnd = end; if (begin != null) { tBegin = DateUtils.truncate(begin, Calendar.DATE); } if (end != null) { // If not using time, we'll asume the end of the interval is // the instant before the next day. tEnd = DateHelper.truncateNextDay(end); } if (tBegin == null) { // it's included if the date is an instant before the next day. return tDate.before(tEnd); } else if (tEnd == null) { // it's included if the date is not before the begin return !tDate.before(tBegin); } else { return !tDate.before(tBegin) && tDate.before(tEnd); } } } }