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:ru.mystamps.web.service.UsersActivationServiceImpl.java

@Override
@Transactional(readOnly = true)/*from  w w  w  .j a  v a2  s .  c o  m*/
public List<UsersActivationFullDto> findOlderThan(int days) {
    Validate.isTrue(days > 0, "Days must be greater than zero");

    Date expiredSince = DateUtils.addDays(new Date(), -days);

    return usersActivationDao.findOlderThan(expiredSince);
}

From source file:service.BookingServiceImpl.java

@Override
public List<Booking> findAllBookingsByStartDateAndLengthOfStay(Integer id_structure, Date startDate,
        Integer lengthOfStay) {/*from  w ww  . j  a  v  a 2s  .  co  m*/
    List<Booking> bookings = null;
    Booking booking = null;
    Date endDate = DateUtils.addDays(startDate, lengthOfStay);

    bookings = new ArrayList<Booking>();
    for (Integer id : this.getBookingMapper().findBookingIdsByIdStructure(id_structure)) {
        booking = this.findBookingById(id);
        if (this.checkifExistBookingInRangeOfDates(booking, startDate, endDate)) {
            bookings.add(booking);
        }

    }
    return bookings;
}

From source file:share.TimeUtil.java

public static long tomorowTime(String dayToken) {
    try {/* w  w w .  j ava 2  s  .  c o m*/
        Date toDay = dayTokenFormatter.parse(dayToken);
        Date tomorow = DateUtils.addDays(toDay, 1);

        return tomorow.getTime();
    } catch (ParseException ex) {
        Logger.getLogger(TimeUtil.class.getName()).log(Level.SEVERE, null, ex);
    }

    return 0;
}

From source file:siddur.solidtrust.autoscout.price.AutoscoutPriceService.java

@Transactional(readOnly = true)
public void compareList(String lp, Integer mileage, Model model) {
    long start = System.currentTimeMillis();
    AutoscoutNl nl = getByPlate(lp, mileage);
    log4j.info("1>" + (System.currentTimeMillis() - start) / 1000);
    if (nl != null) {
        AutoscoutPrice ap = new AutoscoutPrice();
        String from = DateUtil.date2String(DateUtils.addDays(new Date(), -90));
        ap.setLicensePlate(lp);//w  w  w  .j  av a2  s  .  c om
        ap.setBrand(nl.getBrand());
        ap.setModel(nl.getModel());
        ap.setBuildYear(nl.getBuild());
        ap.setFuelType(nl.getFuel());
        ap.setEnginesize(nl.getEnginesize());
        ap.setMileage(mileage);
        log4j.info("brand=" + nl.getBrand() + ", model=" + nl.getModel() + ", build=" + nl.getBuild()
                + ", fuel=" + nl.getFuel() + ", engine=" + nl.getEnginesize() + ", mileage=" + nl.getMileage());

        int i = 0;
        for (int j = 1; j < MILEAGE_RANGE.length; j++) {
            if (MILEAGE_RANGE[j] >= mileage) {
                i = j - 1;
                break;
            }
        }

        model.addAttribute("item", ap);
        ap.setPriceNl(getAutoscoutNl(model, ap, from, MILEAGE_RANGE[i], MILEAGE_RANGE[i + 1]));
        log4j.info("2>" + (System.currentTimeMillis() - start) / 1000);
        ap.setPriceDe(getAutoscout(model, ap, AutoscoutDe.class, from, MILEAGE_RANGE[i], MILEAGE_RANGE[i + 1]));
        log4j.info("3>" + (System.currentTimeMillis() - start) / 1000);
        ap.setPriceFr(getAutoscout(model, ap, AutoscoutFr.class, from, MILEAGE_RANGE[i], MILEAGE_RANGE[i + 1]));
        log4j.info("4>" + (System.currentTimeMillis() - start) / 1000);
        ap.setPriceEs(getAutoscout(model, ap, AutoscoutEs.class, from, MILEAGE_RANGE[i], MILEAGE_RANGE[i + 1]));
        log4j.info("5>" + (System.currentTimeMillis() - start) / 1000);
    }
}

From source file:siddur.solidtrust.azure.AzureCarController.java

@RequestMapping(value = "/mark_repetition")
public void markRepetition(@RequestParam("table") String table, @RequestParam("all") int all) {
    String start = all == 1 ? null : DateUtil.date2String(DateUtils.addDays(new Date(), -10));
    log4j.info("Start date: " + start);
    if (table.equals("Marktplaats")) {
        persister.markMarktplaatsRepetition(table, start);
    } else if (table.equals("AutoscoutNl")) {
        persister.markAutoscoutRepetition(table, start);
    }/* w w  w  . j ava2s. co m*/
}

From source file:siddur.solidtrust.azure.AzureCarController.java

@RequestMapping(value = "/update_others")
public void updateOtherTables(@RequestParam(value = "table", required = false, defaultValue = "0") int table) {
    String start = DateUtil.date2String(DateUtils.addDays(new Date(), -10));
    if (table == 0 || table == 1) {
        log4j.info("update dateRegisted field in Marktplaats");
        try {/* w ww  .j a  va 2 s .  c o  m*/
            persister.updateMarktplaats();
            persister.updateSortedMarktplaats();
            persister.markMarktplaatsRepetition("Marktplaats", start);
        } catch (Exception e) {
            log4j.error(e.getMessage(), e);
        }
    }

    if (table == 0 || table == 2) {
        log4j.info("update AutoscoutNl field in AutoscoutNl");
        try {
            persister.updateAutoscoutNl();
            persister.markAutoscoutRepetition("AutoscoutNl", start); // AutoscoutNl has not AdDate
        } catch (Exception e) {
            log4j.error(e.getMessage(), e);
        }
    }

    if (table == 0 || table == 3) {
        try {
            log4j.info("update Wachtopkeuren field in AutoscoutNl");
            doUpdateWachtopkeuren();
        } catch (Exception e) {
            log4j.error(e.getMessage(), e);
        }
    }
}

From source file:siddur.solidtrust.azure.AzureConnector.java

public static Enumerable<OEntity> updateDateField(int days, int pageIndex, String field) throws Exception {
    int top = pageSize;
    int skip = pageIndex * pageSize;

    Date d = new Date();
    d = DateUtils.addDays(d, -days);
    String day = DateUtil.date2String(d);

    ODataConsumer c = ODataConsumers.create(AzureCarConstants.API_URL);
    OQueryRequest<OEntity> request = c.getEntities("KENT_VRTG_O_DAT").skip(skip).top(top);

    if (field.equals(AzureCarConstants.DATUMAANVANGTENAAMSTELLING)) {
        request.filter("Datumaanvangtenaamstelling eq datetime'" + day + "'")
                .select("Datumaanvangtenaamstelling");
    } else if (field.equals(AzureCarConstants.VERVALDATUMAPK)) {
        request.filter("VervaldatumAPK gt datetime'" + day + "'").select("VervaldatumAPK");
    }/*from  w  w w  .  jav a  2 s  . co  m*/

    Enumerable<OEntity> entityList = request.execute();
    return entityList;
}

From source file:siddur.solidtrust.azure.AzureDownloader.java

private static void archeveCSV() {
    File f = new File(FileSystemUtil.getTempDir(), "azure.csv");
    if (f.isFile()) {
        Date today = new Date();
        String date = DateUtil.date2String(today);
        File dest = new File(FileSystemUtil.getTempDir(), "azure" + date + ".csv");
        if (!dest.isFile()) {
            log4j.info("archeve yesterday's csv");
            f.renameTo(dest);//  w w  w  .  j  ava 2s .c o  m
        }

        //delete file ten days ago.
        String tenDaysAgo = DateUtil.date2String(DateUtils.addDays(today, -10));
        String file = "azure" + tenDaysAgo + ".csv";
        new File(FileSystemUtil.getTempDir(), file).delete();
        log4j.info("deleted file: " + file);
    }
}

From source file:siddur.solidtrust.bi.data.DataPump.java

public void pump(String tablename) {
    webSources = em.createQuery("from WebSource", WebSource.class).getResultList();
    List<CurrencyRate> rates = em.createQuery("from CurrencyRate", CurrencyRate.class).getResultList();
    for (CurrencyRate r : rates) {
        currencyRates.put(r.getCurrency(), r.getRate());
    }//from   ww  w  .ja v  a  2 s.c o  m

    Date d = new Date();
    d = DateUtils.addDays(DateUtils.truncate(d, Calendar.DATE), -1);
    yesterday = sdf.format(d);

    for (WebSource webSource : webSources) {
        if (tablename == null || tablename.equalsIgnoreCase(webSource.getTablename())) {
            log4j.info("Start to synchronize " + webSource.getTablename());
            int total = pumpEach(webSource);
            log4j.info("Synchronized " + total + " records");
        }
    }
}

From source file:siddur.solidtrust.image.ImageController.java

@RequestMapping(value = "/image/manage")
@Transactional(readOnly = true)/*from w  w  w . ja va 2 s  .  c  om*/
public String manage(@RequestParam(value = "type", required = false, defaultValue = "0") int type,
        @RequestParam(value = "daterange", required = false) String daterange,
        @RequestParam(value = "page", required = false, defaultValue = "1") Integer pageIndex, Model model)
        throws Exception {
    int pageSize = 8;
    Pageable pageable = new PageRequest(pageIndex - 1, pageSize);
    Page<ImageProduct> page = null;
    if (type == 0) {
        List<ImageProduct> list = em.createQuery("from ImageProduct", ImageProduct.class)
                .setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize).getResultList();
        long count = em.createQuery("select count(ip) from ImageProduct ip", Long.class).getSingleResult();
        page = new PageImpl<ImageProduct>(list, pageable, count);
    } else if (type == 1) {
        if (daterange.equals("")) {
            type = 0;
        } else {
            model.addAttribute("daterange", daterange);
            String[] dates = daterange.split(" - ");
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            Date from = formatter.parse(dates[0]);
            Date to = formatter.parse(dates[1]);
            to = DateUtils.addDays(to, 1);
            List<ImageProduct> list = em
                    .createQuery("from ImageProduct ip where ip.createdAt between :from and :to",
                            ImageProduct.class)
                    .setParameter("from", from).setParameter("to", to)
                    .setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize).getResultList();

            long count = em.createQuery(
                    "select count(ip) from ImageProduct ip where ip.createdAt between :from and :to",
                    Long.class).setParameter("from", from).setParameter("to", to).getSingleResult();
            page = new PageImpl<ImageProduct>(list, pageable, count);
        }
    }

    if (page != null)
        model.addAttribute("page", page);
    model.addAttribute("type", type);
    return "image/manage";
}