List of usage examples for org.apache.commons.lang3.time DateUtils addDays
public static Date addDays(final Date date, final int amount)
From source file:siddur.solidtrust.insurancehelper.InsuranceService.java
/** * calculate alert data for special day// w ww . ja v a2s. c o m * * @param aheadDays, default: 4 * 7days * * Always alert today */ public void alert() { String ahead = configBean.getValue(AHEAD_DAYS); int aheadDays = StringUtils.isEmpty(ahead) ? (4 * 7) : Integer.parseInt(ahead); Date start = new Date(); String startStr = DateUtil.date2String(start); Date end = DateUtils.addDays(start, aheadDays); String endStr = DateUtil.date2String(end); String ql = "update InsuranceCar set status = 2," //mark status = 2 + " alertAt = '" + startStr + "'" //mark alert date + " where status = 1" // only ones ready to alert + " and expectedSoldDate <= '" + endStr + "'"; // can include past days' records without alert long count = persister.executeNativeQuery(ql); log4j.info("Archieve " + count + " records on [" + start + "-" + endStr + "]"); }
From source file:siddur.solidtrust.insurancehelper.InsuranceService.java
/** * demo in admin page//from w w w .ja v a2 s. c om * @param daysToAlert days from today * @param aheadDays default: 4 * 7days * @return */ public Page<InsuranceCar> alertDemo(Pageable pageable, int daysToAlert, int aheadDays) { Date start = new Date(); Date end = DateUtils.addDays(start, aheadDays); end = DateUtils.addDays(end, daysToAlert); String date = DateUtil.date2String(end); String baseJpql = "from InsuranceCar i" + " where i.status > 0" //include status = 1 or 2. It is different from alert() function. + " and i.expectedSoldDate <= '" + date + "'"; log4j.info(baseJpql); String ql = baseJpql + " order by i.licensePlate"; long count = em.createQuery("select count(i) " + baseJpql, Long.class).getSingleResult(); List<InsuranceCar> list = em.createQuery(ql, InsuranceCar.class) .setFirstResult(pageable.getPageSize() * pageable.getPageNumber()) .setMaxResults(pageable.getPageSize()).getResultList(); Page<InsuranceCar> page = new PageImpl<InsuranceCar>(list, pageable, (int) count); return page; }
From source file:storybook.model.dao.LocationDAOImpl.java
public long countByPersonLocationDate(Person person, Location location, Date date) { date = DateUtil.getZeroTimeDate(date); Query query = session//from www. j a v a 2 s . com .createQuery("select count(s) from Scene as s" + " join s.persons as p" + " join s.locations as l" + " where p=:person and l=:location" + " and s.sceneTs between :tsStart and :tsEnd"); query.setEntity("person", person); query.setEntity("location", location); Timestamp tsStart = new Timestamp(date.getTime()); date = DateUtils.addDays(date, 1); date = DateUtils.addMilliseconds(date, -1); Timestamp tsEnd = new Timestamp(date.getTime()); query.setTimestamp("tsStart", tsStart); query.setTimestamp("tsEnd", tsEnd); return (Long) query.uniqueResult(); }
From source file:storybook.model.dao.SceneDAOImpl.java
@SuppressWarnings("unchecked") public List<Scene> findByDate(Date date) { if (date == null) { return new ArrayList<Scene>(); }// w w w. j a v a 2 s . co m Query query = session.createQuery("select s from Scene as s" + " where s.sceneTs between :tsStart and :tsEnd" + " order by s.sceneTs, s.sceneno"); Timestamp tsStart = new Timestamp(date.getTime()); date = DateUtils.addDays(date, 1); date = DateUtils.addMilliseconds(date, -1); Timestamp tsEnd = new Timestamp(date.getTime()); query.setTimestamp("tsStart", tsStart); query.setTimestamp("tsEnd", tsEnd); return (List<Scene>) query.list(); }
From source file:storybook.model.dao.SceneDAOImpl.java
@SuppressWarnings("unchecked") public List<Scene> findByStrandAndDate(Strand strand, Date date) { if (date == null) { return new ArrayList<Scene>(); }// ww w . ja va 2 s . c o m // OLD: Query query = session // .createQuery("from Scene s where s.sceneTs = :sceneTs and s.strand=:strand order by s.sceneTs"); Query query = session.createQuery("select s from Scene as s" + " left join s.chapter as ch" + " where s.sceneTs between :tsStart and :tsEnd and s.strand=:strand" + " order by s.sceneTs, ch.chapterno, s.sceneno"); Timestamp tsStart = new Timestamp(date.getTime()); Date date2 = DateUtils.addDays(date, 1); date2 = DateUtils.addMilliseconds(date2, -1); Timestamp tsEnd = new Timestamp(date2.getTime()); query.setTimestamp("tsStart", tsStart); query.setTimestamp("tsEnd", tsEnd); query.setEntity("strand", strand); List<Scene> ret = query.list(); // find scenes with relative date List<Scene> scenes = findScenesWithRelativeSceneId(); for (Scene scene : scenes) { if (!scene.getStrand().getId().equals(strand.getId())) { continue; } Scene relativeScene = (Scene) session.get(Scene.class, scene.getRelativeSceneId()); Date sceneDate = scene.getRelativeDate(relativeScene); if (sceneDate == null) { continue; } if (sceneDate.compareTo(date) != 0) { continue; } ret.add(scene); } return ret; }
From source file:storybook.model.entity.Scene.java
public Date getRelativeDate(Scene relativeScene) { if (relativeScene == null) { return null; }/*from www .j a v a 2 s. c o m*/ Date date = relativeScene.getDate(); if (date == null) { return null; } return DateUtils.addDays(date, relativeDateDifference); }
From source file:storybook.model.hbn.dao.SceneDAOImpl.java
@SuppressWarnings("unchecked") public List<Scene> findByDate(Date date) { if (date == null) { return new ArrayList<>(); }//from w w w .j a v a 2 s .c o m Query query = session.createQuery("select s from Scene as s" + " where s.sceneTs between :tsStart and :tsEnd" + " order by s.sceneTs, s.sceneno"); Timestamp tsStart = new Timestamp(date.getTime()); date = DateUtils.addDays(date, 1); date = DateUtils.addMilliseconds(date, -1); Timestamp tsEnd = new Timestamp(date.getTime()); query.setTimestamp("tsStart", tsStart); query.setTimestamp("tsEnd", tsEnd); return (List<Scene>) query.list(); }
From source file:storybook.model.hbn.dao.SceneDAOImpl.java
@SuppressWarnings("unchecked") public List<Scene> findByStrandAndDate(Strand strand, Date date) { if (date == null) { return new ArrayList<>(); }/*from w w w . jav a 2 s. c om*/ // OLD: Query query = session // .createQuery("from Scene s where s.sceneTs = :sceneTs and s.strand=:strand order by s.sceneTs"); Query query = session.createQuery("select s from Scene as s" + " left join s.chapter as ch" + " where s.sceneTs between :tsStart and :tsEnd and s.strand=:strand" + " order by s.sceneTs, ch.chapterno, s.sceneno"); Timestamp tsStart = new Timestamp(date.getTime()); Date date2 = DateUtils.addDays(date, 1); date2 = DateUtils.addMilliseconds(date2, -1); Timestamp tsEnd = new Timestamp(date2.getTime()); query.setTimestamp("tsStart", tsStart); query.setTimestamp("tsEnd", tsEnd); query.setEntity("strand", strand); List<Scene> ret = query.list(); // find scenes with relative date List<Scene> scenes = findScenesWithRelativeSceneId(); for (Scene scene : scenes) { if (!scene.getStrand().getId().equals(strand.getId())) { continue; } Scene relativeScene = (Scene) session.get(Scene.class, scene.getRelativeSceneId()); Date sceneDate = scene.getRelativeDate(relativeScene); if (sceneDate == null) { continue; } if (sceneDate.compareTo(date) != 0) { continue; } ret.add(scene); } return ret; }
From source file:storybook.toolkit.DateUtil.java
public static void expandDatesToFuture(List<Date> dates, int count) { dates.removeAll(Collections.singletonList(null)); if (dates.isEmpty()) { return;// ww w. j a va2 s . c o m } for (int i = 0; i < count; ++i) { Date lastDate = Collections.max(dates); if (lastDate == null) { return; } lastDate = new Date(DateUtils.addDays(lastDate, 1).getTime()); dates.add(lastDate); } }
From source file:storybook.toolkit.DateUtil.java
public static void expandDatesToPast(List<Date> dates, int count) { if (dates.isEmpty()) { return;/* w w w . j av a 2 s . c o m*/ } dates.removeAll(Collections.singletonList(null)); for (int i = 0; i < count; ++i) { Date firstDate = Collections.min(dates); firstDate = new Date(DateUtils.addDays(firstDate, -1).getTime()); dates.add(firstDate); } }