Java Utililty Methods Day End

List of utility methods to do Day End

Description

The list of methods to do Day End are organized into topic(s).

Method

booleanisSameDay(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;
booleanisTodayWithinPeriod(Date periodStart, Date periodEnd)
is Today Within Period
return isDateWithinPeriod(new Date(), periodStart, periodEnd);
booleanisValidSendDate(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);
booleanisWorkingDay(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;
...
DatepostponeWorkingDay(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();
...
CalendarpreviousWorkingDay(final Calendar calendar, final Long[] holidays)
previous Working Day
calendar.add(DAY, -1);
while (!isWorkingDay(calendar.getTimeInMillis(), holidays)) {
    calendar.add(DAY, -1);
return calendar;
intsecondsBetween(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);
...
LongsecondsToEndOfDay(Date aDate)
seconds To End Of Day
Date midnight = endOfDay(aDate);
return timeDifferenceInSeconds(aDate, midnight);
LongsecondsToEndOfDay(Date aDate)
Compute the seconds from a date to the end of day.
Date midnight = endOfDay(aDate);
return timeDifferenceInSeconds(aDate, midnight);
DatesetEndDay(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();