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

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

Introduction

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

Prototype

public static Date addHours(Date date, int amount) 

Source Link

Document

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

Usage

From source file:controllers.integration.IntegrationServiceController.java

public static void saveJsonPosition() {
    final String jsonString = request.params.get("body", String.class);
    final PositionBO jsonObject = PositionBO.fromJson(jsonString, PositionBO.class);
    validateRequest(jsonObject);/*from  w  ww . j  av a2 s  . c om*/
    jsonObject.setDate(DateUtils.addHours(jsonObject.getDate(), -3));
    jsonObject.setPositionItinerary(jsonObject.getBus().getItinerary().getRouteNumber());
    jsonObject.merge()._save();
    ok();
}

From source file:controllers.integration.IntegrationServiceController.java

public static void savePosition(final Double latitude, final Double longitude, final Date date,
        final Short speed, final PositionSense positionSense, String licensePlate, Long busNumber,
        Short capacity, String routeNumber, String startPoint, String endPoint) {
    final PositionBO object = new PositionBO();
    object.setLatitude(latitude);//from   w  w  w .  jav  a 2  s.  c o m
    object.setLongitude(longitude);
    object.setDate(date);
    object.setSpeed(speed);
    object.setPositionSense(positionSense);
    object.setBus(
            new BusBO(licensePlate, busNumber, capacity, new ItineraryBO(routeNumber, startPoint, endPoint)));
    validateRequest(object);
    object.setDate(DateUtils.addHours(date, -2));
    object.setPositionItinerary(object.getBus().getItinerary().getRouteNumber());
    object.merge()._save();
    ok();
}

From source file:com.hs.mail.imap.schedule.ScheduleUtils.java

public static Date getTimeAfter(String str, Date defaultTime) {
    if (str != null) {
        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            char ch = str.charAt(i);
            if (!Character.isDigit(ch)) {
                try {
                    int amount = Integer.parseInt(str.substring(0, i));
                    switch (Character.toUpperCase(ch)) {
                    case 'H':
                        return DateUtils.addHours(new Date(), amount);
                    case 'M':
                        return DateUtils.addMinutes(new Date(), amount);
                    }//from ww  w .ja va  2  s. co m
                } catch (NumberFormatException e) {
                    break;
                }
            }
        }
    }
    return defaultTime;
}

From source file:fr.xebia.demo.objectgrid.ticketing.TrainSearchAgentTest.java

public void test() throws Exception {

    Date today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
    Date noonToday = DateUtils.addHours(today, 12);

    TrainSearchAgent trainSearchAgent = new TrainSearchAgent(PARIS_GARE_DE_LYON, noonToday,
            MARSEILLE_SAINT_CHARLES);/*from w  ww  .  j a  va  2  s  . c  o m*/

    Session session = objectGrid.getSession();
    ObjectMap employeeMap = session.getMap("Train");
    AgentManager agentManager = employeeMap.getAgentManager();

    List<RouteDetails> matchingTrainsByPartionId = (List<RouteDetails>) agentManager
            .callReduceAgent(trainSearchAgent);
    logger.debug(matchingTrainsByPartionId.size() + " matching trains found ");

    for (RouteDetails routeDetails : matchingTrainsByPartionId) {
        logger.debug(routeDetails);
    }
}

From source file:iddb.scheduller.jobs.PenaltyEventWorker.java

@Override
public void execute() {
    Date grace = DateUtils.addHours(new Date(), THRESHOLD * -1);

    PenaltyDAO penaltyDAO = (PenaltyDAO) DAOFactory.forClass(PenaltyDAO.class);
    PenaltyHistoryDAO historyDAO = (PenaltyHistoryDAO) DAOFactory.forClass(PenaltyHistoryDAO.class);

    List<PenaltyHistory> penalties = historyDAO.listByStatus(PenaltyHistory.ST_WAITING);

    int c = 0;/* ww  w.ja  v  a 2  s. co  m*/
    for (PenaltyHistory p : penalties) {
        if (p.getUpdated().before(grace)) {
            try {
                Penalty penalty = penaltyDAO.get(p.getPenaltyId());
                penalty.setSynced(false);
                p.setStatus(PenaltyHistory.ST_PENDING);
                penaltyDAO.save(penalty);
                historyDAO.save(p);
                c++;
            } catch (EntityDoesNotExistsException e) {
                log.error(e.getMessage());
            }
        }
    }
    log.debug("Updated {}", c);

}

From source file:de.hybris.platform.acceleratorservices.order.strategies.impl.ReminderUncollectedConsignmentStrategy.java

@Override
public boolean processConsignment(final ConsignmentModel consignmentModel) {
    if (consignmentModel != null) {
        final Date timeLimit = DateUtils.addHours(new Date(), 0 - getTimeThreshold().intValue());
        if (timeLimit.after(consignmentModel.getShippingDate())) {
            if (getBusinessProcessService()
                    .getProcess("consignmentCollectionReminderProcess-" + consignmentModel.getCode()) == null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Process consignmentCollectionReminderProcess-" + consignmentModel.getCode()
                            + " created.");
                }/* w w w  . jav  a2 s . co  m*/
                final ConsignmentProcessModel consignmentProcessModel = getBusinessProcessService()
                        .createProcess("consignmentCollectionReminderProcess-" + consignmentModel.getCode(),
                                "consignmentCollectionReminderProcess");
                if (consignmentProcessModel != null) {
                    consignmentProcessModel.setConsignment(consignmentModel);
                    getModelService().save(consignmentProcessModel);
                    getBusinessProcessService().startProcess(consignmentProcessModel);
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:de.hybris.platform.acceleratorservices.order.strategies.impl.CustomerServiceUncollectedConsignmentStrategy.java

@Override
public boolean processConsignment(final ConsignmentModel consignmentModel) {
    if (consignmentModel != null) {
        final Date timeLimit = DateUtils.addHours(new Date(), 0 - getTimeThreshold().intValue());
        if (timeLimit.after(consignmentModel.getShippingDate())) {
            if (getBusinessProcessService().getProcess(
                    "moveConsignmentToCustomerServicesProcess-" + consignmentModel.getCode()) == null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Process moveConsignmentToCustomerServicesProcess-" + consignmentModel.getCode()
                            + " created.");
                }/*from w  w  w .  j  a  v a  2s  .c o m*/
                final ConsignmentProcessModel consignmentProcessModel = getBusinessProcessService()
                        .createProcess("moveConsignmentToCustomerServicesProcess-" + consignmentModel.getCode(),
                                "moveConsignmentToCustomerServicesProcess");
                if (consignmentProcessModel != null) {
                    consignmentProcessModel.setConsignment(consignmentModel);
                    getModelService().save(consignmentProcessModel);
                    getBusinessProcessService().startProcess(consignmentProcessModel);
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:com.hs.mail.imap.schedule.DiskCleanupJob.java

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    if (logger.isDebugEnabled()) {
        logger.debug("Starting disk cleanup job.");
    }//from   w w w  .  j av  a2  s .c  om
    String prop = Config.getProperty("stop_cron_after", "2h");
    Date stopAt = ScheduleUtils.getTimeAfter(prop, DateUtils.addHours(new Date(), 2));
    if ((prop = Config.getProperty("expunge_after", null)) != null) {
        new MessageExpunger(manager).expunge(prop, stopAt.getTime());
    }
    if ((prop = Config.getProperty("compress_after", null)) != null) {
        new MessageCompressor().compress(prop, stopAt.getTime());
    }
}

From source file:eu.xipi.bro4xipi.XiPiScenarioRequest.java

public XiPiScenarioRequest() {

    logger.debug("In XiPiScenarioRequest constructor");
    scenario = new RequestedFederationScenario();
    scenario.setName("myScenario");
    this.setStartDate(new Date());
    this.setEndDate(DateUtils.addHours(this.getStartDate(), 24));
    ServicesRequest newServicesRequest = new ServicesRequest();
    scenario.setServicesRequest(newServicesRequest);
    offeredPlans = new Vector<OfferedPlan>(); //not to be null, usually assigned by resource advisor

}

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

public void removeOldInvitations(final int olderThanHours) {

    Date date = DateUtils.addHours(new Date(), -olderThanHours);
    getCurrentSesssion().createQuery(REMOVE_BY_AGE).setDate("cDate", date).executeUpdate();
}