Example usage for org.joda.time DateMidnight plusDays

List of usage examples for org.joda.time DateMidnight plusDays

Introduction

In this page you can find the example usage for org.joda.time DateMidnight plusDays.

Prototype

public DateMidnight plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:org.key2gym.business.services.AttendancesServiceBean.java

License:Apache License

@Override
public List<AttendanceDTO> findAttendancesByDate(DateMidnight date) throws SecurityViolationException {

    /*//  w w  w  . j  av a 2s  .  co m
     * Arguments validation.
     */
    if (date == null) {
        throw new NullPointerException("The date is null."); //NOI18N
    }

    if (!date.equals(DateMidnight.now()) && !callerHasRole(SecurityRoles.MANAGER)) {
        throw new SecurityException(getString("Security.Access.Denied"));
    }

    List<Attendance> attendances = getEntityManager()
            .createNamedQuery("Attendance.findByDatetimeBeginRangeOrderByDateTimeBeginDesc") //NOI18N
            .setParameter("low", date.toDate()) //NOI18N
            .setParameter("high", date.plusDays(1).toDate()) //NOI18N
            .getResultList();
    List<AttendanceDTO> result = new LinkedList<AttendanceDTO>();

    for (Attendance attendance : attendances) {
        result.add(wrapAttendance(attendance));
    }

    return result;
}

From source file:org.key2gym.business.services.OrdersServiceBean.java

License:Apache License

/**
 * Checks whether the provided date is today.
 *
 * @param date the date to check/*ww  w .ja va  2s . co m*/
 * @return true, if the date's time is past the today's midnight.
 */
public boolean isToday(Date date) {
    DateMidnight today = new DateMidnight();
    DateMidnight tomorrow = today.plusDays(1);
    return today.getMillis() <= date.getTime() && tomorrow.getMillis() > date.getTime();
}

From source file:org.kuali.student.enrollment.class2.acal.service.impl.AcademicCalendarViewHelperServiceImpl.java

License:Educational Community License

/**
 * Calculate and returns the valid number of final exam period days based on the excludeSaturday/excludeSunday setting.
 * Also, overlapping non-instructional holidays will be subtracted as well.
 *
 * @param examPeriodWrapper exam period wrapper
 * @param holidayInfos list of holidayinfos of the academic calendar
 *//*w w w  .  j  a  va2s  .  c  o  m*/
protected int getDaysForExamPeriod(ExamPeriodWrapper examPeriodWrapper, List<HolidayInfo> holidayInfos,
        ContextInfo contextInfo) throws Exception {
    //trap null parameters
    if (examPeriodWrapper == null) {
        throw new Exception("Exam Period wrapper is null");
    }

    int examPeriodDays = 0;
    boolean excludeSaturday = examPeriodWrapper.isExcludeSaturday();
    boolean excludeSunday = examPeriodWrapper.isExcludeSunday();

    DateMidnight currentDateExamPeriod = new DateMidnight(examPeriodWrapper.getStartDate().getTime());
    DateMidnight endDateExamPeriod = new DateMidnight(examPeriodWrapper.getEndDate().getTime());

    // go from start to end and count exam period days
    while (currentDateExamPeriod.compareTo(endDateExamPeriod) <= 0) {
        // if it is Saturday or Sunday and the exam period set exclude Saturday or Sunday attr
        // do not count that day
        if (!(((currentDateExamPeriod.getDayOfWeek() == DateTimeConstants.SATURDAY) && excludeSaturday)
                || ((currentDateExamPeriod.getDayOfWeek() == DateTimeConstants.SUNDAY) && excludeSunday))) {
            ++examPeriodDays;
        }

        currentDateExamPeriod = currentDateExamPeriod.plusDays(1);
    }

    //if there is a holiday calendar for the academic calendar where the exam period is in,
    //check if there are holidays overlapping with the exam period
    if (holidayInfos != null && !holidayInfos.isEmpty()) {
        List<DateMidnight> holidayDatesToSubtract = new ArrayList<DateMidnight>();
        for (HolidayInfo holidayInfo : holidayInfos) {
            Boolean isInstDay = holidayInfo.getIsInstructionalDay();
            Boolean isDateRange = holidayInfo.getIsDateRange();
            Date holStartDate = holidayInfo.getStartDate();
            Date holEndDate = holidayInfo.getEndDate();

            // If's it's not a range then the start and end dates are the same
            if (!isDateRange) {
                holEndDate = holStartDate;
            }

            // if holiday is an instructional day, it doesn't need to be subtracted from the exam period
            if (!isInstDay) {
                DateMidnight currentDate = new DateMidnight(holStartDate.getTime());
                DateMidnight stopDate = new DateMidnight(holEndDate.getTime());
                while (currentDate.compareTo(stopDate) <= 0) {
                    if (doDatesOverlap(examPeriodWrapper.getStartDate(), examPeriodWrapper.getEndDate(),
                            currentDate.toDate(), currentDate.toDate())) {
                        //if holiday is on Saturday or Sunday and excludeSaturday/excludeSunday is set,
                        //the holiday doesn't need to be subtracted again because the Saturday/Sunday has already been excluded
                        if (!(((currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) && excludeSaturday)
                                || ((currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY)
                                        && excludeSunday))) {
                            if (!holidayDatesToSubtract.contains(currentDate)) {
                                holidayDatesToSubtract.add(currentDate);
                                --examPeriodDays;
                            }
                        }
                    }
                    currentDate = currentDate.plusDays(1);
                }
            }
        }
    }

    return examPeriodDays;
}

From source file:org.projectforge.web.calendar.HolidayEventsProvider.java

License:Open Source License

/**
 * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime)
 *///from   w  w w . j a  v a2 s . c  o  m
@Override
protected void buildEvents(final DateTime start, final DateTime end) {
    DateMidnight day = new DateMidnight(start);
    int idCounter = 0;
    int paranoiaCounter = 0;
    do {
        if (++paranoiaCounter > 1000) {
            log.error(
                    "Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents.");
            break;
        }
        final DayHolder dh = new DayHolder(day.toDate());
        String backgroundColor, color, textColor;
        if (dh.isHoliday() == true) {
            if (dh.isWorkingDay() == true) {
                backgroundColor = "#FFF0F0";
                color = "#EEEEEE";
                textColor = "#222222";
            } else {
                backgroundColor = "#f9dfde";
                color = "#EEEEEE";
                textColor = "#FF2222";
            }
        } else {
            day = day.plusDays(1);
            continue;
        }

        final Event event = new Event().setAllDay(true);
        final String id = "h-" + (++idCounter);
        event.setId(id);
        event.setStart(day.toDateTime());
        String title;
        final String holidayInfo = dh.getHolidayInfo();
        if (holidayInfo != null && holidayInfo.startsWith("calendar.holiday.") == true) {
            title = getString(holidayInfo);
        } else {
            title = holidayInfo;
        }
        event.setTitle(title);
        event.setBackgroundColor(backgroundColor);
        event.setColor(color);
        event.setTextColor(textColor);
        events.put(id, event);
        day = day.plusDays(1);
    } while (day.isAfter(end) == false);
}

From source file:se.streamsource.streamflow.client.ui.workspace.table.PerspectivePeriodModel.java

License:Apache License

private String getSearchPeriod(Date fromDate, int direction, String periodName, String datePattern,
        String separator) {/*from   w w w. j av a 2 s .  c  om*/
    DateMidnight from = new DateMidnight(fromDate);
    DateMidnight to = null;
    DateTimeFormatter format = DateTimeFormat.forPattern(datePattern);

    switch (Period.valueOf(periodName)) {
    case one_day:
        return format.print(from);

    case three_days:
        to = (direction == 1) ? from.plusDays(2) : from.minusDays(2);
        break;

    case one_week:
        to = (direction == 1) ? from.plusWeeks(1).minusDays(1) : from.minusWeeks(1).plusDays(1);
        break;

    case two_weeks:
        to = (direction == 1) ? from.plusWeeks(2).minusDays(1) : from.minusWeeks(2).plusDays(1);
        break;

    case one_month:
        to = (direction == 1) ? from.plusMonths(1).minusDays(1) : from.minusMonths(1).plusDays(1);
        break;

    case six_months:
        to = (direction == 1) ? from.plusMonths(6).minusDays(1) : from.minusMonths(6).plusDays(1);
        break;

    case one_year:
        to = (direction == 1) ? from.plusYears(1).minusDays(1) : from.minusYears(1).plusDays(1);
        break;

    }
    return (direction == 1) ? format.print(from) + separator + format.print(to)
            : format.print(to) + separator + format.print(from);

}