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

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

Introduction

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

Prototype

public static Date addDays(Date date, int amount) 

Source Link

Document

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

Usage

From source file:cn.vlabs.umt.ui.servlet.AppProxyServlet.java

private void genHalfProxy(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String appname = request.getParameter("appname");
    AppService service = (AppService) factory.getBean("ApplicationService");
    Application app = service.getApplication(appname);

    AppCredContent content = new AppCredContent();
    content.setAppKeyId(app.getKeyid());
    content.setIpAddress(RequestUtil.getRemoteIP(request));
    content.setPrincipal(new AppPrincipal(appname));
    Date tommorow = DateUtils.addDays(new Date(), 1);
    content.setValidTime(DateFormatUtils.format(tommorow, "yyyy-MM-dd hh:mm:ss"));

    Application umt = service.getApplication("umt");
    content.setUMTKeyId(umt.getKeyid());

    // UMTCredential cred= (UMTCredential)factory.getBean("UMTCredUtil");
    SignedEnvelope env = new SignedEnvelope(content.toXML());
    // env.genSignature(cred.getUMTKey()); kevin deleted //TODO //FIXME

    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    out.println(env.toXML());//from w ww.j a  v  a 2s  .  c o m
    out.flush();
    out.close();
}

From source file:com.edgenius.wiki.dao.hibernate.ActivityLogDAOHibernate.java

public void removeOldByDays(final int days) {
    Date date = DateUtils.addDays(new Date(), -days);
    getCurrentSesssion().createQuery(REMOVE_BY_AGE).setDate("cDate", date).executeUpdate();
}

From source file:fr.amapj.service.services.meslivraisons.MesLivraisonsService.java

/**
 * Permet de charger la liste de tous les livraisons
 * dans une transaction en lecture/*from w  w w. j a v a2  s  .  co m*/
 */
@DbRead
public MesLivraisonsDTO getMesLivraisons(Date d, List<RoleList> roles, Long idUtilisateur) {
    EntityManager em = TransactionHelper.getEm();

    MesLivraisonsDTO res = new MesLivraisonsDTO();

    Utilisateur user = em.find(Utilisateur.class, idUtilisateur);

    res.dateDebut = fr.amapj.common.DateUtils.firstMonday(d);
    res.dateFin = DateUtils.addDays(res.dateDebut, 6);

    // On rcupre ensuite la liste de tous les cellules de contrats de cet utilisateur dans cet intervalle
    List<ContratCell> cells = getAllQte(em, res.dateDebut, res.dateFin, user);

    //
    for (ContratCell cell : cells) {
        addCell(cell, res);
    }

    // On rcupre ensuite la liste de toutes les permanences de cet utilisateur dans cet intervalle
    List<DatePermanence> dds = getAllDistributionsForUtilisateur(em, res.dateDebut, res.dateFin, user);
    for (DatePermanence dd : dds) {
        addDistribution(em, dd, res);
    }

    // On rcupre ensuite le planning mensuel si il y en a un
    res.planningMensuel = computePlanningMensuel(em, res.dateDebut, res.dateFin, roles);

    return res;

}

From source file:iddb.web.security.dao.SessionDAO.java

public void cleanUp(Long expire) {
    String sql;/*from   www  . ja va  2s  . com*/
    sql = "delete from user_session where created < ?";
    Connection conn = null;
    try {
        conn = ConnectionFactory.getMasterConnection();
        PreparedStatement st = conn.prepareStatement(sql);
        st.setTimestamp(1, new Timestamp(DateUtils.addDays(new Date(), expire.intValue() * -1).getTime()));
        int r = st.executeUpdate();
        log.debug("Removed {} sessions", Integer.toString(r));
    } catch (SQLException e) {
        log.error("cleanUp", e);
    } catch (IOException e) {
        log.error("cleanUp", e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:it.measureHistory.SinceXDaysHistoryTest.java

private static String getPastDate(int nbPastDays) {
    return new SimpleDateFormat("yyyy-MM-dd").format(DateUtils.addDays(new Date(), nbPastDays * -1));
}

From source file:ch.puzzle.itc.mobiliar.business.resourcegroup.boundary.ResourceRelationsIntegrationTest.java

@Before
public void before() throws GeneralDBException {
    MockitoAnnotations.initMocks(this);
    release1 = new ReleaseEntity();
    release1.setName("Release 1");
    release1.setInstallationInProductionAt(DateUtils.addDays(new Date(), -1));
    release2 = new ReleaseEntity();
    release2.setName("Release 2");
    release2.setInstallationInProductionAt(new Date());
    entityManager.persist(release1);/*from   www .j a va2 s  .  c  o  m*/
    entityManager.persist(release2);

    astype = new ResourceTypeEntity();
    astype.setName(DefaultResourceTypeDefinition.APPLICATIONSERVER.name());
    apptype = new ResourceTypeEntity();
    apptype.setName(DefaultResourceTypeDefinition.APPLICATION.name());
    entityManager.persist(astype);
    entityManager.persist(apptype);

    asRel1 = ResourceFactory.createNewResource("as");
    asRel1.setRelease(release1);
    asRel2 = ResourceFactory.createNewResource(asRel1.getResourceGroup());
    asRel2.setRelease(release2);
    entityManager.persist(asRel1);
    entityManager.persist(asRel2);

    appRel1 = ResourceFactory.createNewResource("app");
    appRel1.setRelease(release1);
    appRel2 = ResourceFactory.createNewResource(appRel1.getResourceGroup());
    appRel2.setRelease(release2);
    entityManager.persist(appRel1);
    entityManager.persist(appRel2);

    ResourceRelationTypeEntity resRelType = new ResourceRelationTypeEntity();
    resRelType.setResourceTypes(astype, apptype);
    entityManager.persist(resRelType);

    entityManager.persist(asRel1.addConsumedResourceRelation(appRel1, resRelType, null, ForeignableOwner.AMW));
    entityManager.persist(asRel1.addConsumedResourceRelation(appRel2, resRelType, null, ForeignableOwner.AMW));
    entityManager.persist(asRel2.addConsumedResourceRelation(appRel1, resRelType, null, ForeignableOwner.AMW));
    entityManager.persist(asRel2.addConsumedResourceRelation(appRel2, resRelType, null, ForeignableOwner.AMW));
    Mockito.when(applistScreenDomainService.getAppServerResourcesWithApplications(Mockito.anyString(),
            Mockito.anyInt(), Mockito.anyList(), Mockito.anyBoolean()))
            .thenReturn(Arrays.asList(asRel1, asRel2));
    service.dependencyResolverService = dependencyResolver;
}

From source file:ch.algotrader.service.CalendarServiceImpl.java

/**
 * {@inheritDoc}/*from  w w w. j  a va 2  s.  c  om*/
 */
@Override
public Date getCurrentTradingDate(final long exchangeId, final Date dateTime) {

    Validate.notNull(dateTime, "Data time is null");

    Exchange exchange = this.exchangeDao.get(exchangeId);
    Validate.notNull(exchange, "exchange not found");

    Date date = DateUtils.addDays(DateUtils.truncate(dateTime, Calendar.DATE), 2);
    NavigableSet<Date> openTimes = new TreeSet<>();
    while ((openTimes.floor(dateTime)) == null) {
        date = DateUtils.addDays(date, -1);
        openTimes.addAll(getOpenTimes(exchange, date));
    }
    return date;

}

From source file:net.audumla.irrigation.EToCalculator.java

public double calculateETo(Date now) {
    // refresh if we are in a different day or an elapse time has passed
    if (!DateUtils.isSameDay(lastCalculated, now)
            || (DateUtils.getFragmentInMinutes(lastCalculated, Calendar.DAY_OF_YEAR)
                    - DateUtils.getFragmentInMinutes(now, Calendar.DAY_OF_YEAR)) > minuteTimeout) {
        double debt = 0.0;
        for (int i = 0; i < calculationDurationInDays; ++i) {
            try {
                // add up all the ETo values over the past days.
                // the current day may use forecast information
                ClimateData data = zone.getClimateObserver().getClimateData(now);
                try {
                    double eto = data.getEvapotranspiration();
                    debt += eto;//from w ww.  j av a2s  .  c  o m
                } catch (UnsupportedOperationException ex) {
                    // no ETo information available
                }

                try {
                    double rain = data.getRainfall();
                    // if the rainfall value is a forecast then we revert to the latest observation and use the value
                    // that is the rainfall since 9am.
                    if (!data.getDataSource().getType()
                            .equals(ClimateDataSource.ClimateDataSourceType.DAILY_FORECAST)) {
                        debt -= rain;
                    } else {
                        debt -= data.getObservation(now, ClimateData.ObservationMatch.CLOSEST).getRainfall();
                    }
                } catch (UnsupportedOperationException ex) {
                    // no rain information available
                }
                // add all the irrigation events for this day against the water debt
                List<Event> events = zone.getIrrigationEventsForDay(now);
                for (Event e : events) {
                    if (e.getEventStartTime().before(now)) {
                        debt -= IrrigationZone.calculateIrrigatedDepth(zone, e.getEventDuration());
                    }
                }
            } catch (UnsupportedOperationException ex) {
                logger.warn("Unable to obtain climate data for " + Time.dateFormatter.format(now), ex);
            } finally {
                now = DateUtils.addDays(now, -1);
            }
        }
        currentETo = debt;
        lastCalculated = now;
    }
    return currentETo;

}

From source file:com.silverpeas.gallery.dao.MediaOrderSQLQueryBuilder.java

@Override
public MediaOrderCriteriaProcessor processNbDaysAfterThatDeleteAnOrder(final Date referenceDate,
        final int nbDaysAfterThatDeleteAnOrder) {
    if (!done) {/* www . j  av a2  s . com*/
        where(conjunction).append("O.createDate < ?");
        parameters.add(DateUtils.addDays(referenceDate, -nbDaysAfterThatDeleteAnOrder));
        conjunction = "";
    }
    return this;
}

From source file:ch.puzzle.itc.mobiliar.presentation.resourcesedit.EditResourceViewTest.java

@Test
public void testNewerRelease() {
    //given/*  ww  w.  j av a  2 s  . c o  m*/
    ResourceGroupEntity group = new ResourceGroupEntity();
    ResourceEntity r = ResourceFactory.createNewResource(group);
    ReleaseEntity rel = new ReleaseEntity();
    rel.setInstallationInProductionAt(new Date());
    r.setRelease(rel);

    ResourceEntity r2 = ResourceFactory.createNewResource(group);
    ReleaseEntity rel2 = new ReleaseEntity();
    rel2.setInstallationInProductionAt(DateUtils.addDays(new Date(), 2));
    r2.setRelease(rel2);

    //when
    context.resource = r;
    //then
    Assert.assertTrue(context.hasNewerRelease());

    //when
    context.resource = r2;
    //then
    Assert.assertFalse(context.hasNewerRelease());

}