List of usage examples for org.apache.commons.lang.time DateUtils addHours
public static Date addHours(Date date, int amount)
From source file:br.ufc.ivela.ejb.impl.CourseBean.java
public String getTotalTimeLeft(Long systemUserId, Long courseId) { List<UnitContent> allUnitContents = daoCourse.find( "select uc from UnitContent uc, Unit u, " + "Discipline d where uc.unitId = u.id and u.disciplineId = d.id " + "and d.courseId = ?", new Object[] { courseId }); List<Long> finishedUnitContents = daoCourse.find( "select f.unitContent from FinishedUnitContent f " + "where f.course = ? and f.systemUser = ?", new Object[] { courseId, systemUserId }); Date date = new Date(70, 1, 1, 0, 0, 0); for (UnitContent unitContent : allUnitContents) { if (!finishedUnitContents.contains(unitContent.getId())) { date = DateUtils.addHours(date, unitContent.getDuration().getHours()); date = DateUtils.addMinutes(date, unitContent.getDuration().getMinutes()); }/*www.ja v a2s . c om*/ } return ((((date.getDay()) * 24) + date.getHours()) != 0 ? ((date.getDay()) * 24) + date.getHours() + " hora(s) e " : "") + date.getMinutes() + " minuto(s)"; }
From source file:mitm.common.sms.hibernate.SMSGatewayDAOTest.java
@Test public void testGetAvailableOldest() throws DatabaseException { executor.executeTransaction(new DatabaseAction<Long>() { @Override// w ww .j ava 2 s . c o m public Long doAction(Session session) throws DatabaseException { SMS sms = new SMSImpl("123456", "sms body", "some extra data"); return addSMSAction(session, sms, DateUtils.addHours(new Date(), -1)); } }); executor.executeTransaction(new DatabaseAction<Long>() { @Override public Long doAction(Session session) throws DatabaseException { SMS sms = new SMSImpl("789", "qwerty", "111"); return addSMSAction(session, sms, DateUtils.addHours(new Date(), -2)); } }); final Date notAfter = new Date(); SMSGatewayEntity entity = executor.executeTransaction(new DatabaseAction<SMSGatewayEntity>() { @Override public SMSGatewayEntity doAction(Session session) throws DatabaseException { return getNextAvailableAction(session, notAfter); } }); assertNotNull(entity); assertEquals("789", entity.getPhoneNumber()); }
From source file:br.ufc.ivela.ejb.impl.CourseBean.java
public String getTimeLeft(Long systemUserId, Long courseId, Long disciplineId) { List<UnitContent> allUnitContents = daoCourse.find("select uc from UnitContent uc, Unit u, " + "Discipline d where uc.unitId = u.id and u.disciplineId = d.id " + "and d.courseId = ? and u.disciplineId = ?", new Object[] { courseId, disciplineId }); List<Long> finishedUnitContents = daoCourse.find( "select f.unitContent from FinishedUnitContent f " + "where f.course = ? and f.systemUser = ?", new Object[] { courseId, systemUserId }); Date date = new Date(70, 1, 1, 0, 0, 0); for (UnitContent unitContent : allUnitContents) { if (!finishedUnitContents.contains(unitContent.getId())) { date = DateUtils.addHours(date, unitContent.getDuration().getHours()); date = DateUtils.addMinutes(date, unitContent.getDuration().getMinutes()); }/* ww w. j a v a2 s . co m*/ } return ((((date.getDay()) * 24) + date.getHours()) != 0 ? ((date.getDay()) * 24) + date.getHours() + " hora(s) e " : "") + date.getMinutes() + " minuto(s)"; }
From source file:mitm.common.sms.hibernate.SMSGatewayDAOTest.java
@Test public void testGetAvailableNotYetValid() throws DatabaseException { executor.executeTransaction(new DatabaseAction<Long>() { @Override// ww w . ja v a 2 s .c o m public Long doAction(Session session) throws DatabaseException { SMS sms = new SMSImpl("123456", "sms body", "some extra data"); return addSMSAction(session, sms, new Date()); } }); final Date notAfter1 = DateUtils.addHours(new Date(), -1); SMSGatewayEntity entity = executor.executeTransaction(new DatabaseAction<SMSGatewayEntity>() { @Override public SMSGatewayEntity doAction(Session session) throws DatabaseException { return getNextAvailableAction(session, notAfter1); } }); assertNull(entity); final Date notAfter2 = DateUtils.addHours(new Date(), 1); entity = executor.executeTransaction(new DatabaseAction<SMSGatewayEntity>() { @Override public SMSGatewayEntity doAction(Session session) throws DatabaseException { return getNextAvailableAction(session, notAfter2); } }); assertNotNull(entity); assertEquals("123456", entity.getPhoneNumber()); }
From source file:mitm.common.mail.repository.hibernate.MailRepositoryImplTest.java
@Test public void testSorting() throws Exception { MimeMessage message = loadMessage("html-alternative.eml"); assertEquals(0, proxy.getItemCount(DEFAULT_REPOSITORY)); Date now = new Date(); MailRepositoryItem item4 = proxy.addItemWithDate(DEFAULT_REPOSITORY, message, DateUtils.addHours(now, 1)); MailRepositoryItem item3 = proxy.addItemWithDate(DEFAULT_REPOSITORY, message, now); MailRepositoryItem item2 = proxy.addItemWithDate(DEFAULT_REPOSITORY, message, DateUtils.addHours(now, -1)); MailRepositoryItem item1 = proxy.addItemWithDate(DEFAULT_REPOSITORY, message, DateUtils.addHours(now, -2)); assertEquals(4, proxy.getItemCount(DEFAULT_REPOSITORY)); List<? extends MailRepositoryItem> items = proxy.getItems(DEFAULT_REPOSITORY, 0, Integer.MAX_VALUE); assertEquals(4, items.size());//from w w w . j a v a 2 s .c o m assertEquals(item1.getID(), items.get(0).getID()); assertEquals(item2.getID(), items.get(1).getID()); assertEquals(item3.getID(), items.get(2).getID()); assertEquals(item4.getID(), items.get(3).getID()); items = proxy.getItems(DEFAULT_REPOSITORY, 2, Integer.MAX_VALUE); assertEquals(2, items.size()); assertEquals(item3.getID(), items.get(0).getID()); assertEquals(item4.getID(), items.get(1).getID()); items = proxy.searchItems(DEFAULT_REPOSITORY, MailRepositorySearchField.FROM, "%linkedin%", 0, Integer.MAX_VALUE); assertEquals(4, items.size()); assertEquals(item1.getID(), items.get(0).getID()); assertEquals(item2.getID(), items.get(1).getID()); assertEquals(item3.getID(), items.get(2).getID()); assertEquals(item4.getID(), items.get(3).getID()); }
From source file:com.haulmont.cuba.core.app.EmailerTest.java
private Date getDeadlineWhichDoesntMatter() { return DateUtils.addHours(timeSource.currentTimestamp(), 2); }
From source file:mitm.common.mail.repository.hibernate.MailRepositoryImplTest.java
@Test public void testBefore() throws Exception { MimeMessage message = loadMessage("html-alternative.eml"); assertEquals(0, proxy.getItemCount(DEFAULT_REPOSITORY)); Date now = new Date(); proxy.addItemWithDate(DEFAULT_REPOSITORY, message, DateUtils.addHours(now, 1)); proxy.addItemWithDate(DEFAULT_REPOSITORY, message, now); MailRepositoryItem item2 = proxy.addItemWithDate(DEFAULT_REPOSITORY, message, DateUtils.addHours(now, -1)); MailRepositoryItem item1 = proxy.addItemWithDate(DEFAULT_REPOSITORY, message, DateUtils.addHours(now, -2)); assertEquals(4, proxy.getItemCount(DEFAULT_REPOSITORY)); List<? extends MailRepositoryItem> items = proxy.getItemsBefore(DEFAULT_REPOSITORY, now, 0, Integer.MAX_VALUE);//from www .ja v a 2s.c om assertEquals(2, items.size()); assertEquals(item1.getID(), items.get(0).getID()); assertEquals(item2.getID(), items.get(1).getID()); }
From source file:com.lastdaywaiting.example.kalkan.service.SecureManager.java
/** * ? CRL- ?/*from w ww.ja v a2s . c o m*/ * * @param crlName * @return */ private boolean isNeedLoadCrlObject(String crlName) { if (TypeOfCrlLoaded.NO_LOAD.equals(MAP_OF_LOAD_CRL_LABEL.get(crlName))) { return true; // , ? } else if (TypeOfCrlLoaded.LOADING.equals(MAP_OF_LOAD_CRL_LABEL.get(crlName))) { return false; // , ? ? } else if (TypeOfCrlLoaded.LOADED.equals(MAP_OF_LOAD_CRL_LABEL.get(crlName))) { Date currentDt = new Date(); Date lastLoadedCrl = MAP_OF_LOAD_CRL_TIME.get(crlName); Date checkDt = DateUtils.addHours(lastLoadedCrl, HOURS_OF_RELOAD); if (checkDt.before(currentDt)) { return true; // , ? ??? HOURS_OF_RELOAD ? } else { return false; } } else { throw new RuntimeException("?? ? ?? " + MAP_OF_LOAD_CRL_LABEL.get(crlName)); } }
From source file:ch.algotrader.service.PortfolioServiceImpl.java
/** * {@inheritDoc}/*from w w w . j a v a2 s . co m*/ */ @Override @Transactional(propagation = Propagation.REQUIRED) public void restorePortfolioValues(final Strategy strategy, final Date fromDate, final Date toDate) { Validate.notNull(strategy, "Strategy is null"); Validate.notNull(fromDate, "From date is null"); Validate.notNull(toDate, "To date is null"); // delete existing portfolio values; List<PortfolioValue> portfolioValues = this.portfolioValueDao.findByStrategyAndMinDate(strategy.getName(), fromDate); if (portfolioValues.size() > 0) { this.portfolioValueDao.deleteAll(portfolioValues); // need to flush since new portfoliovalues will be created with same date and strategy this.sessionFactory.getCurrentSession().flush(); } // init cron CronSequenceGenerator cron = new CronSequenceGenerator("0 0 * * * 1-5", TimeZone.getDefault()); // group PortfolioValues by strategyId and date Map<MultiKey<Long>, PortfolioValue> portfolioValueMap = new HashMap<>(); // create portfolioValues for all cron time slots Date date = cron.next(DateUtils.addHours(fromDate, -1)); while (date.compareTo(toDate) <= 0) { PortfolioValue portfolioValue = getPortfolioValue(strategy.getName(), date); if (portfolioValue.getNetLiqValueDouble() == 0) { date = cron.next(date); continue; } else { MultiKey<Long> key = new MultiKey<>(strategy.getId(), date.getTime()); portfolioValueMap.put(key, portfolioValue); if (LOGGER.isInfoEnabled()) { LOGGER.info("processed portfolioValue for {} {}", strategy.getName(), date); } date = cron.next(date); } } // save values for all cashFlows List<Transaction> transactions = this.transactionDao.findCashflowsByStrategyAndMinDate(strategy.getName(), fromDate); for (Transaction transaction : transactions) { // only process performanceRelevant transactions if (!transaction.isPerformanceRelevant()) { continue; } // do not save before fromDate if (transaction.getDateTime().compareTo(fromDate) < 0) { continue; } // if there is an existing PortfolioValue, add the cashFlow MultiKey<Long> key = new MultiKey<>(transaction.getStrategy().getId(), transaction.getDateTime().getTime()); if (portfolioValueMap.containsKey(key)) { PortfolioValue portfolioValue = portfolioValueMap.get(key); if (portfolioValue.getCashFlow() != null) { portfolioValue.setCashFlow(portfolioValue.getCashFlow().add(transaction.getGrossValue())); } else { portfolioValue.setCashFlow(transaction.getGrossValue()); } } else { PortfolioValue portfolioValue = getPortfolioValue(transaction.getStrategy().getName(), transaction.getDateTime()); portfolioValue.setCashFlow(transaction.getGrossValue()); portfolioValueMap.put(key, portfolioValue); } if (LOGGER.isInfoEnabled()) { LOGGER.info("processed portfolioValue for {} {} cashflow {}", transaction.getStrategy().getName(), transaction.getDateTime(), transaction.getGrossValue()); } } // perisist the PortfolioValues this.portfolioValueDao.saveAll(portfolioValueMap.values()); }
From source file:org.ala.harvester.BiocacheHarvester.java
/** * Main method for testing this particular Harvester * * @param args/*from ww w.jav a 2 s . c o m*/ */ public static void main(String[] args) throws Exception { String[] locations = { "classpath*:spring.xml" }; ApplicationContext context = new ClassPathXmlApplicationContext(locations); BiocacheHarvester h = (BiocacheHarvester) context.getBean(BiocacheHarvester.class); Repository r = (Repository) context.getBean("repository"); h.setRepository(r); if (args.length == 1) { h.setEndDate(new Date()); if ("-lastYear".equals(args[0])) { h.setStartDate(DateUtils.addYears(h.getEndDate(), -1)); } else if ("-lastMonth".equals(args[0])) { h.setStartDate(DateUtils.addMonths(h.getEndDate(), -1)); } else if ("-lastWeek".equals(args[0])) { h.setStartDate(DateUtils.addWeeks(h.getEndDate(), -1)); } else if ("-lastDay".equals(args[0])) { h.setStartDate(DateUtils.addDays(h.getEndDate(), -1)); } else if ("-lastHour".equals(args[0])) { h.setStartDate(DateUtils.addHours(h.getEndDate(), -1)); } else { //attempt to parse the date down to an acceptable date try { Date startDate = DateUtils.parseDate(args[0], new String[] { "yyyy-MM-dd" }); h.setStartDate(startDate); } catch (java.text.ParseException e) { h.setStartDate(DateUtils.addDays(h.getEndDate(), -1)); } } } else if (args.length == 2 && "-query".equals(args[0])) { h.setQuery(args[1]); } h.start(-1, true); }