List of utility methods to do Day End
boolean | isSameDay(final Calendar calendar1, final Calendar calendar2) Test if 2 calendar are in the same day boolean res = false; if (calendar1.getTimeZone() == calendar2.getTimeZone() && calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR) && calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) { res = true; return res; |
boolean | isTodayWithinPeriod(Date periodStart, Date periodEnd) is Today Within Period return isDateWithinPeriod(new Date(), periodStart, periodEnd); |
boolean | isValidSendDate(Date sendDate) is Valid Send Date GregorianCalendar now = new GregorianCalendar(); GregorianCalendar sendDateCalendar = new GregorianCalendar(); sendDateCalendar.setTime(sendDate); now.add(Calendar.MINUTE, -5); return now.before(sendDateCalendar); |
boolean | isWorkingDay(final Calendar calendar, final Long[] holidays) is Working Day if (null != holidays) { final Calendar holiday = Calendar.getInstance(); for (final long d : holidays) { holiday.setTimeInMillis(d); if (holiday.get(Calendar.YEAR) == calendar.get(Calendar.YEAR) && holiday.get(Calendar.MONTH) == calendar.get(Calendar.MONTH) && holiday.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH)) { return false; ... |
Date | postponeWorkingDay(final Calendar calendar, final int measureUnit, final int amount, final Long[] holidays) postpone Working Day Date result = calendar.getTime(); for (int i = 0; i < amount; i++) { postpone(calendar, measureUnit, 1); if (!isWorkingDay(calendar, holidays)) { nextWorkingDay(calendar, holidays); return calendar.getTime(); ... |
Calendar | previousWorkingDay(final Calendar calendar, final Long[] holidays) previous Working Day calendar.add(DAY, -1); while (!isWorkingDay(calendar.getTimeInMillis(), holidays)) { calendar.add(DAY, -1); return calendar; |
int | secondsBetween(Date start, Date end, boolean assumeSameDate, boolean assumeSameHour) seconds Between Calendar sDate = Calendar.getInstance(_locale);
Calendar eDate = Calendar.getInstance(_locale);
sDate.setTime(start);
eDate.setTime(end);
if (assumeSameDate) {
eDate.set(Calendar.YEAR, 2000);
sDate.set(Calendar.YEAR, 2000);
eDate.set(Calendar.DAY_OF_YEAR, 1);
...
|
Long | secondsToEndOfDay(Date aDate) seconds To End Of Day Date midnight = endOfDay(aDate);
return timeDifferenceInSeconds(aDate, midnight);
|
Long | secondsToEndOfDay(Date aDate) Compute the seconds from a date to the end of day. Date midnight = endOfDay(aDate);
return timeDifferenceInSeconds(aDate, midnight);
|
Date | setEndDay(Date date) set End Day Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
|