Example usage for org.apache.commons.lang3.time DateUtils addDays

List of usage examples for org.apache.commons.lang3.time DateUtils addDays

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils addDays.

Prototype

public static Date addDays(final Date date, final int amount) 

Source Link

Document

Adds a number of days to a date returning a new object.

Usage

From source file:org.kuali.kra.committee.service.CommitteeScheduleServiceImplTest.java

/**
 * This method test's advance submission days for added event.
 * @throws Exception/* ww  w . ja va 2  s . c o  m*/
 */
@Test
public void testAddScheduleAdvancedSubmissionDays() throws Exception {
    prerequisite();

    scheduleData.setRecurrenceType(StyleKey.NEVER.toString());
    scheduleData.setTime(new Time12HrFmt(TIME12HR_11_59, MERIDIEM.PM));

    context.checking(new Expectations() {
        {
            Date dt = scheduleData.getScheduleStartDate();
            List<Date> dates = new LinkedList<Date>();
            dates.add(new Date());
            Time24HrFmt time = new Time24HrFmt(TIME24HR_23_59);
            one(scheduleService).getScheduledDates(dt, dt, time, null);
            will(returnValue(dates));
        }
    });

    test(1);
    java.sql.Date testDate = committee.getCommitteeSchedules().get(0).getProtocolSubDeadline();
    java.sql.Date expectedDate = new java.sql.Date(
            DateUtils.addDays(new Date(), -committee.getAdvancedSubmissionDaysRequired()).getTime());
    assertEquals(expectedDate.toString(), testDate.toString());
}

From source file:org.kuali.kra.committee.service.CommitteeScheduleServiceImplTest.java

/**
 * This method for duplicate dates./*  www  .  j  a va2s  .  c  o  m*/
 * @throws Exception
 */
@Test
public void testAddScheduleDuplicateDates() throws Exception {
    prerequisite();

    scheduleData.setRecurrenceType(StyleKey.DAILY.toString());
    scheduleData.setDailySchedule(new DailyScheduleDetails());
    scheduleData.getDailySchedule().setScheduleEndDate(getDate(2));
    context.checking(new Expectations() {
        {
            Date dt = scheduleData.getScheduleStartDate();
            Date endDt = scheduleData.getDailySchedule().getScheduleEndDate();
            List<Date> dates = new LinkedList<Date>();
            dates.add(new Date());
            dates.add(new Date());
            dates.add(DateUtils.addDays(new Date(), 2));
            Time24HrFmt time = new Time24HrFmt(TIME24HR_0_1);
            int day = scheduleData.getDailySchedule().getDay();
            one(scheduleService).getIntervalInDaysScheduledDates(dt, endDt, time, day);
            will(returnValue(dates));
        }
    });
    scheduleData.getDailySchedule().setDayOption(DailyScheduleDetails.optionValues.XDAY.toString());

    test(2);
    assertEquals(1, scheduleData.getDatesInConflict().size());
}

From source file:org.kuali.kra.committee.service.CommitteeScheduleServiceImplTest.java

/**
 * Private helper method to set prerequiste's for daily options.
 * @throws ParseException/*from   w w w .j  a v a  2s.  c o  m*/
 */
private void dailyPrerequisite() throws ParseException {
    scheduleData.setRecurrenceType(StyleKey.DAILY.toString());
    scheduleData.setDailySchedule(new DailyScheduleDetails());
    scheduleData.getDailySchedule().setScheduleEndDate(getDate(2));
    context.checking(new Expectations() {
        {
            Date dt = scheduleData.getScheduleStartDate();
            Date endDt = scheduleData.getDailySchedule().getScheduleEndDate();
            List<Date> dates = new LinkedList<Date>();
            dates.add(new Date());
            dates.add(DateUtils.addDays(new Date(), 2));
            Time24HrFmt time = new Time24HrFmt(TIME24HR_0_1);
            int day = scheduleData.getDailySchedule().getDay();
            one(scheduleService).getIntervalInDaysScheduledDates(dt, endDt, time, day);
            will(returnValue(dates));
        }
    });
}

From source file:org.kuali.kra.committee.service.CommitteeScheduleServiceImplTest.java

/**
 * This method test's if Protocol is deletable.
 * @throws Exception/*  w w w  . ja  va 2s.  c o m*/
 */
@Test
public void testIsCommitteeScheduleDeletableWithCurrentDate() throws Exception {
    boolean flag = false;
    Date newdate = DateUtils.addDays(new Date(), -1);
    committeeSchedule.setScheduledDate(new java.sql.Date(newdate.getTime()));
    flag = service.isCommitteeScheduleDeletable(committeeSchedule);
    assertTrue(flag);
}

From source file:org.kuali.kra.committee.service.CommitteeScheduleServiceImplTest.java

/**
 * This method adds offset to today's date.
 * @param offset/*from ww  w .  jav a  2  s .com*/
 * @return
 */
private java.sql.Date getDate(int offset) {
    java.sql.Date sqlDt = new java.sql.Date(new Date().getTime());
    Date dt = DateUtils.addDays(sqlDt, offset);
    return new java.sql.Date(dt.getTime());
}

From source file:org.kuali.kra.iacuc.actions.IacucActionHelper.java

/**
 * Builds an expiration date, defaulting to the expiration date from the protocol.  
 * /* w w  w . java  2  s. co  m*/
 * If the expiration date from the protocol is null, or if the protocol is new or a renewal, creates an expiration date exactly one year ahead and one day 
 * less than the approval date.
 * 
 * @param protocol
 * @param approvalDate
 * @return a non-null expiration date
 */
@Override
protected Date buildExpirationDate(ProtocolBase protocol, Date approvalDate) {
    Date expirationDate = protocol.getExpirationDate();

    if (expirationDate == null || protocol.isNew() || protocol.isRenewal()
            || ((IacucProtocol) protocol).isContinuation()) {
        java.util.Date newExpirationDate = DateUtils.addYears(approvalDate,
                getDefaultExpirationDateDifference());
        newExpirationDate = DateUtils.addDays(newExpirationDate, -1);
        expirationDate = org.kuali.coeus.sys.framework.util.DateUtils.convertToSqlDate(newExpirationDate);
    }

    return expirationDate;
}

From source file:org.kuali.kra.irb.actions.ActionHelper.java

/**
 * Prepares all protocol actions for being filtered by setting their isInFilterView attribute.
 *///from   www  . ja  v a 2 s . co m
public void initFilterDatesView() {
    java.util.Date dayBeforeStartDate = null;
    java.util.Date dayAfterEndDate = null;

    if (filteredHistoryStartDate != null && filteredHistoryEndDate != null) {
        dayBeforeStartDate = DateUtils.addDays(filteredHistoryStartDate, -1);
        dayAfterEndDate = DateUtils.addDays(filteredHistoryEndDate, 1);
    }

    for (ProtocolActionBase protocolAction : getSortedProtocolActions()) {
        Timestamp actionDate = protocolAction.getActionDate();
        if (dayBeforeStartDate != null && dayAfterEndDate != null) {
            protocolAction.setIsInFilterView(
                    actionDate.after(dayBeforeStartDate) && actionDate.before(dayAfterEndDate));
        } else {
            protocolAction.setIsInFilterView(true);
        }
        if (protocolAction.getIsInFilterView()) {
            ((ProtocolAction) protocolAction).setQuestionnairePrintOptionFromHelper(this);
        }
    }
}

From source file:org.kuali.kra.irb.actions.history.ProtocolHistoryFilterDatesRuleTest.java

@Test
public void testEndDateBeforeStartDate() {
    new TemplateRuleTest<ProtocolHistoryFilterDatesEvent, ProtocolHistoryFilterDatesRule>() {

        @Override/*from w  w w  .  j a v  a  2  s .  c om*/
        protected void prerequisite() {
            Date startDate = new Date(System.currentTimeMillis());
            Date endDate = DateUtils.addDays(startDate, -1);

            event = new ProtocolHistoryFilterDatesEvent(null, startDate, endDate);
            rule = new ProtocolHistoryFilterDatesRule();
            expectedReturnValue = false;
        }

        @Override
        public void checkRuleAssertions() {
            assertError(Constants.PROTOCOL_HISTORY_DATE_RANGE_FILTER_START_DATE_KEY,
                    KeyConstants.ERROR_START_DATE_AFTER_END_DATE);
        }
    };
}

From source file:org.kuali.kra.protocol.actions.ActionHelperBase.java

/**
 * Builds an expiration date, defaulting to the expiration date from the protocol.  
 * /*w w  w  . j av a 2 s .c o m*/
 * If the expiration date from the protocol is null, or if the protocol is new or a renewal, creates an expiration date exactly one year ahead and one day 
 * less than the approval date.
 * 
 * @param protocol
 * @param approvalDate
 * @return a non-null expiration date
 */
protected Date buildExpirationDate(ProtocolBase protocol, Date approvalDate) {
    Date expirationDate = protocol.getExpirationDate();

    if (expirationDate == null || protocol.isNew() || protocol.isRenewal()) {
        java.util.Date newExpirationDate = DateUtils.addYears(approvalDate,
                getDefaultExpirationDateDifference());
        newExpirationDate = DateUtils.addDays(newExpirationDate, -1);
        expirationDate = org.kuali.coeus.sys.framework.util.DateUtils.convertToSqlDate(newExpirationDate);
    }

    return expirationDate;
}

From source file:org.kuali.kra.protocol.actions.ActionHelperBase.java

/**
 * Prepares all protocol actions for being filtered by setting their isInFilterView attribute.
 *///from  ww  w  .j av a2s .c  o m
public void initFilterDatesView() {
    java.util.Date dayBeforeStartDate = null;
    java.util.Date dayAfterEndDate = null;

    if (filteredHistoryStartDate != null && filteredHistoryEndDate != null) {
        dayBeforeStartDate = DateUtils.addDays(filteredHistoryStartDate, -1);
        dayAfterEndDate = DateUtils.addDays(filteredHistoryEndDate, 1);
    }

    for (ProtocolActionBase protocolAction : getSortedProtocolActions()) {
        Timestamp actionDate = protocolAction.getActionDate();
        if (dayBeforeStartDate != null && dayAfterEndDate != null) {
            protocolAction.setIsInFilterView(
                    actionDate.after(dayBeforeStartDate) && actionDate.before(dayAfterEndDate));
        } else {
            protocolAction.setIsInFilterView(true);
        }
        if (protocolAction.getIsInFilterView()) {

        }
    }
}