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:models.support.SearchCondition.java

public ExpressionList<Issue> asExpressionList(Project project) {
    ExpressionList<Issue> el = Issue.finder.where();
    if (project != null) {
        el.eq("project.id", project.id);
    }//from  w w w  . ja v  a  2s  . co m
    if (StringUtils.isNotBlank(filter)) {
        Junction<Issue> junction = el.disjunction();
        junction.icontains("title", filter).icontains("body", filter);
        List<Object> ids = null;
        if (project == null) {
            ids = Issue.finder.where().icontains("comments.contents", filter).findIds();
        } else {
            ids = Issue.finder.where().eq("project.id", project.id).icontains("comments.contents", filter)
                    .findIds();
        }
        if (!ids.isEmpty()) {
            junction.idIn(ids);
        }
        junction.endJunction();
    }

    if (authorId != null) {
        if (authorId.equals(User.anonymous.id)) {
            el.isNull("authorId");
        } else {
            el.eq("authorId", authorId);
        }
    }

    if (assigneeId != null) {
        if (assigneeId.equals(User.anonymous.id)) {
            el.isNull("assignee");
        } else {
            el.eq("assignee.user.id", assigneeId);
            el.eq("assignee.project.id", project.id);
        }
    }

    if (milestoneId != null) {
        if (milestoneId.equals(Milestone.NULL_MILESTONE_ID)) {
            el.isNull("milestone");
        } else {
            el.eq("milestone.id", milestoneId);
        }
    }

    if (commentedCheck) {
        el.ge("numOfComments", AbstractPosting.NUMBER_OF_ONE_MORE_COMMENTS);
    }

    State st = State.getValue(state);
    if (st.equals(State.OPEN) || st.equals(State.CLOSED)) {
        el.eq("state", st);
    }

    if (CollectionUtils.isNotEmpty(labelIds)) {
        el.add(LabelSearchUtil.createLabelSearchExpression(el.query(), labelIds));
    }

    if (StringUtils.isNotBlank(orderBy)) {
        if (orderBy.equals("dueDate")) {
            String formulaName = orderDir.equals("asc") ? "dueDateAsc" : "dueDateDesc";
            el.orderBy(formulaName + " " + orderDir);
        } else {
            el.orderBy(orderBy + " " + orderDir);
        }
    }

    if (dueDate != null) {
        el.lt("dueDate", DateUtils.addDays(dueDate, 1));
    }

    return el;
}

From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationConfigurationServiceBeanTest.java

@Test
public void testInitializeAnnualRegistrationConfiguration_ConfigurationAlreadyExists() {
    setUpMockSponsorService();/*from   ww w  .  j ava2  s .  c  o m*/
    Date date = DateUtils.addDays(new Date(), -1);
    AnnualRegistrationConfiguration expectedConfiguration = createAndSaveConfiguration(date,
            sponsorOrganization);
    service.initializeAnnualRegistrationConfiguration();
    AnnualRegistrationConfiguration actualConfiguration = service.getCurrentConfiguration();
    assertSamePersistentObjects(expectedConfiguration, actualConfiguration);
}

From source file:gov.nih.nci.firebird.common.FirebirdDateUtilsTest.java

@Test
public void testIsCurrentDateBeforeAndWithinRangeOfDate_True() {
    Date date = DateUtils.addDays(new Date(), 59);
    assertTrue(isCurrentDateBeforeAndWithinRangeOfDate(date, 60));
}

From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBeanHibernateTest.java

@Test
public void testCreatePendingRenewals_DeletedRenewal() {
    AnnualRegistration expiringRegistration = createTestRegistration(profile, configuration,
            DateUtils.addDays(new Date(), -60), null);
    saveAndFlush(expiringRegistration);//from w w  w.  j av a  2s  .com

    bean.createPendingRenewals();
    flushAndClearSession();
    expiringRegistration = reloadObject(expiringRegistration);
    assertNotNull(expiringRegistration.getRenewal());

    bean.delete(expiringRegistration.getRenewal(), expiringRegistration.getRenewal().getProfile().getUser());
    expiringRegistration = reloadObject(expiringRegistration);
    assertNull(expiringRegistration.getRenewal());

    bean.createPendingRenewals();
    expiringRegistration = reloadObject(expiringRegistration);
    assertNull(expiringRegistration.getRenewal());
}

From source file:gov.nih.nci.firebird.common.FirebirdDateUtilsTest.java

@Test
public void testIsCurrentDateBeforeAndWithinRangeOfDate_False() {
    Date date = DateUtils.addDays(new Date(), 61);
    assertFalse(isCurrentDateBeforeAndWithinRangeOfDate(date, 60));
}

From source file:io.wcm.wcm.commons.caching.CacheHeader.java

/**
 * Set expires header to given amount of days in the future.
 * @param response Response/*w ww. j  a  va  2 s  . co  m*/
 * @param days Days to expire
 */
public static void setExpiresDays(HttpServletResponse response, int days) {
    Date expiresDate = DateUtils.addDays(new Date(), days);
    setExpires(response, expiresDate);
}

From source file:gov.nih.nci.firebird.common.FirebirdDateUtilsTest.java

@Test
public void testIsCurrentDateBeforeAndWithinRangeOfDate_False_AfterDate() {
    Date date = DateUtils.addDays(new Date(), -1);
    assertFalse(isCurrentDateBeforeAndWithinRangeOfDate(date, 60));
}

From source file:models.MilestoneTest.java

@Test
public void untilLeft() {
    // Given/*from  ww w . ja  v a  2  s.c  o m*/
    int days = 3;
    Milestone milestone = new Milestone();
    milestone.dueDate = DateUtils.truncate(DateUtils.addDays(new Date(), days), Calendar.DATE);

    // When
    String until = milestone.until();

    // Then
    assertThat(until).isEqualTo(Messages.get("common.time.leftday", days));
}

From source file:com.netsteadfast.greenstep.bsc.action.HistoryItemScoreReportContentQueryAction.java

private String getChangeDateVal() throws ParseException {
    String dateVal = this.getFields().get("dateVal");
    String dateChangeStatus = this.getFields().get("dateChangeStatus");
    String sysNowDate = super.getNowDate().replaceAll("/", "");
    Date dateValObj = DateUtils.parseDate(dateVal, new String[] { "yyyyMMdd" });
    if ("next".equals(dateChangeStatus)) {
        if (Integer.parseInt(dateVal) >= Integer.parseInt(sysNowDate)) {
            dateVal = sysNowDate;/*from w w  w  .j  a  va  2s.  c o  m*/
        } else {
            Date nexDate = DateUtils.addDays(dateValObj, 1);
            dateVal = DateFormatUtils.format(nexDate, "yyyyMMdd");
        }
    }
    if ("prev".equals(dateChangeStatus)) {
        Date nexDate = DateUtils.addDays(dateValObj, -1);
        dateVal = DateFormatUtils.format(nexDate, "yyyyMMdd");
    }
    return dateVal;
}

From source file:com.searchbox.collection.oppfin.EENCollection.java

public ItemReader<Profile> reader() throws RemoteException {
    return new ItemReader<Profile>() {

        IPODServiceSOAPProxy eenService;
        ProfileQueryRequest request;/*from   w w  w .  java  2s. co  m*/
        List<Profile> profiles;
        Date date = new Date(System.currentTimeMillis());
        Date start = new Date(System.currentTimeMillis());
        DateFormat dfmt = new DateFormatManager("YYYYMMdd").getDateFormatInstance();

        {
            // Get the service
            eenService = new IPODServiceSOAPProxy();

            // Set the password
            request = new ProfileQueryRequest();
            request.setUsername(env.getProperty(EEN_SERVICE_USER, EEN_SERVICE_USER_DEFAULT));
            request.setPassword(env.getProperty(EEN_SERVICE_PWD, EEN_SERVICE_PWD_DEFAULT));

            // Start with an empty list of profiles
            profiles = new ArrayList<Profile>();

            date = start;
        }

        public void fillProfiles(Date from, Date to) {
            try {
                LOGGER.info("Fill Profile - ", from.toString(), to.toString());
                // time to get some new profiles...
                JAXBElement<String> jaxbDeadlineDateAfter = new JAXBElement(new QName(
                        "http://schemas.datacontract.org/2004/07/EEN.Merlin.Backend.Core.BO.PODService",
                        "DeadlineDateAfter"), String.class, dfmt.format(from));
                JAXBElement<String> jaxbDeadlineDateBefore = new JAXBElement(new QName(
                        "http://schemas.datacontract.org/2004/07/EEN.Merlin.Backend.Core.BO.PODService",
                        "DeadlineDateBefore"), String.class, dfmt.format(to));
                request.setDeadlineDateAfter(jaxbDeadlineDateAfter);
                request.setDeadlineDateBefore(jaxbDeadlineDateBefore);
                Profile[] newProfiles = eenService.getProfiles(request);
                EENCollection.LOGGER.info("adding: " + newProfiles.length + " new profiles");
                profiles.addAll(Arrays.asList(newProfiles));
            } catch (Exception e) {
                LOGGER.error("Could not load profiles: " + e);
            }
        }

        public Profile read() throws RemoteException {
            if (start.after(DateUtils.addYears(date, 3))) {
                return null;
            }

            if (profiles.isEmpty()) {
                while (start.before(DateUtils.addYears(date, 1)) && profiles.isEmpty()) {
                    Date end = DateUtils.addDays(start, 5);
                    EENCollection.LOGGER.info("Fetching EEN profiles from deadline date " + dfmt.format(start)
                            + " to deadline date" + dfmt.format(end));
                    fillProfiles(start, end);
                    start = end;
                }
                if (start.after(DateUtils.addYears(date, 3))) {
                    return null;
                }
            }
            if (profiles.size() == 0) {
                return null;
            }
            return profiles.remove(0);
        }
    };
}