List of usage examples for org.apache.commons.lang.time DateUtils addMinutes
public static Date addMinutes(Date date, int amount)
From source file:org.openmrs.module.emr.EmrActivator.java
private void ensureScheduledTasks() { SchedulerService schedulerService = Context.getSchedulerService(); TaskDefinition task = schedulerService.getTaskByName(EmrConstants.TASK_CLOSE_STALE_VISITS_NAME); if (task == null) { task = new TaskDefinition(); task.setName(EmrConstants.TASK_CLOSE_STALE_VISITS_NAME); task.setDescription(EmrConstants.TASK_CLOSE_STALE_VISITS_DESCRIPTION); task.setTaskClass(CloseStaleVisitsTask.class.getName()); task.setStartTime(DateUtils.addMinutes(new Date(), 5)); task.setRepeatInterval(EmrConstants.TASK_CLOSE_STALE_VISITS_REPEAT_INTERVAL); task.setStartOnStartup(true);/*from w w w.j a v a 2 s.c o m*/ try { schedulerService.scheduleTask(task); } catch (SchedulerException e) { throw new RuntimeException("Failed to schedule close stale visits task", e); } } else { // if you modify any of the properties above, you also need to set them here, in order to update existing servers boolean changed = GeneralUtils.setPropertyIfDifferent(task, "taskClass", CloseStaleVisitsTask.class.getName()); if (changed) { schedulerService.saveTask(task); } if (!task.getStarted()) { task.setStarted(true); try { schedulerService.scheduleTask(task); } catch (SchedulerException e) { throw new RuntimeException("Failed to schedule close stale visits task", e); } } } }
From source file:org.openmrs.module.mirebalais.MirebalaisHospitalActivator.java
private void setupCloseStalePullRequestsTask() { SchedulerService schedulerService = Context.getSchedulerService(); TaskDefinition task = schedulerService.getTaskByName(EmrConstants.TASK_CLOSE_STALE_PULL_REQUESTS); if (task == null) { task = new TaskDefinition(); task.setName(EmrConstants.TASK_CLOSE_STALE_PULL_REQUESTS); task.setDescription(EmrConstants.TASK_CLOSE_STALE_PULL_REQUESTS_DESCRIPTION); task.setTaskClass(CloseStalePullRequestsTask.class.getName()); task.setStartTime(DateUtils.addMinutes(new Date(), 5)); task.setRepeatInterval(new Long(3600)); // once an hour task.setStartOnStartup(true);/*from w ww. j a va 2 s .c om*/ try { schedulerService.scheduleTask(task); } catch (SchedulerException e) { throw new RuntimeException("Failed to schedule close stale pull requests task", e); } } else { boolean anyChanges = GeneralUtils.setPropertyIfDifferent(task, "description", EmrConstants.TASK_CLOSE_STALE_PULL_REQUESTS_DESCRIPTION); anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "taskClass", CloseStalePullRequestsTask.class.getName()); anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "repeatInterval", new Long(3600)); anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "startOnStartup", true); if (anyChanges) { schedulerService.saveTask(task); } if (!task.getStarted()) { task.setStarted(true); try { schedulerService.scheduleTask(task); } catch (SchedulerException e) { throw new RuntimeException("Failed to schedule close stale pull requests task", e); } } } }
From source file:org.sakaiproject.kernel.message.chat.ChatMessageCleaner.java
/** * {@inheritDoc}/* w w w . j ava 2 s . co m*/ * * @see java.util.TimerTask#run() */ @Override public void run() { LOGGER.info("Starting chat messages cleanup process."); // need to be admin when in our own thread Session session = null; QueryManager queryManager; try { session = slingRepository.loginAdministrative(null); // Get the current date and substract x minutes of it. Date d = new Date(); d = DateUtils.addMinutes(d, MessageConstants.CLEAUNUP_EVERY_X_MINUTES); // Make the format for the JCR query SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdfMinutes = new SimpleDateFormat("kk:mm:ss"); String timestamp = sdf.format(d) + "T" + sdfMinutes.format(d) + ".000+01:00"; queryManager = session.getWorkspace().getQueryManager(); String queryPath = "/jcr:root/" + ISO9075.encodePath("_user/private") + "//element(*)[@" + JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY + "='" + MessageConstants.SAKAI_MESSAGE_RT + "' and @" + MessageConstants.PROP_SAKAI_TYPE + "='" + MessageConstants.TYPE_CHAT + "' and @" + MessageConstants.PROP_SAKAI_READ + "='false' and @" + JCRConstants.JCR_CREATED + " < xs:dateTime('" + timestamp + "')]"; Query query = queryManager.createQuery(queryPath, Query.XPATH); QueryResult qr = query.execute(); NodeIterator nodes = qr.getNodes(); long i = 0; // Loop the found nodes and delete them while (nodes.hasNext()) { Node n = nodes.nextNode(); n.remove(); i++; } // need to manually save session.save(); LOGGER.info("Removed {} chat messages.", i); } catch (RepositoryException e) { LOGGER.warn("Got a repository exception during clean up process."); throw new MessagingException(e.getMessage(), e); } finally { // need to manually logout and commit try { if (session != null) session.logout(); } catch (Exception e) { throw new RuntimeException("Failed to logout of JCR: " + e, e); } } }
From source file:org.sakuli.builder.TestSuiteExampleBuilder.java
public TestSuiteExampleBuilder() { this.state = TestSuiteState.RUNNING; this.host = "localhost"; this.id = "UnitTest_" + System.nanoTime(); this.startDate = new GregorianCalendar(2014, 7, 17, 14, 0).getTime(); this.stopDate = DateUtils.addMinutes(startDate, 2); this.testCases = Arrays.asList(new TestCaseExampleBuilder().buildExample()); this.warningTime = 0; this.criticalTime = 0; this.folder = null; this.browserInfo = "firefox"; }
From source file:org.sonar.core.persistence.SemaphoreDaoTest.java
private boolean isRecent(Date date) { Date future = DateUtils.addMinutes(now(), 1); Date past = DateUtils.addDays(now(), -1); return date.after(past) && date.before(future); }
From source file:org.vosao.dao.PageDaoTest.java
public void testGetCurrentHourPublishedPages() throws ParseException { Date dt = DateUtils.addMinutes(new Date(), -15); Date dt2 = DateUtils.addHours(new Date(), 1); Date dt3 = DateUtils.addMinutes(new Date(), -30); PageEntity page1 = addPage("test1", dt); PageEntity page2 = addPage("test2", dt2); PageEntity page3 = addPage("test3", dt3); List<PageEntity> list = getDao().getPageDao().getCurrentHourPublishedPages(); assertEquals(2, list.size());//from w ww . j a v a 2 s . c o m }
From source file:ru.altruix.commons.impl.util.Utils.java
public static Date addHours(final Date aDateTime, final double aHours) { final int hours = (int) aHours; final int minutes = (int) ((aHours - (double) hours) * MINUTES_IN_HOUR); final Date timeWithHoursAdded = DateUtils.addHours(aDateTime, hours); return DateUtils.addMinutes(timeWithHoursAdded, minutes); }
From source file:ubic.gemma.util.DateUtil.java
/** * Turn a string like '-7d' into the date equivalent to "seven days ago". Supports 'd' for day, 'h' for hour, 'm' * for minutes, "M" for months and "y" for years. Start with a '-' to indicate times in the past ('+' is not * necessary for future). Values must be integers. * // w w w .j a v a 2 s .c o m * @param date to be added/subtracted to * @param dateString * @author Paul Pavlidis * @return Date relative to 'now' as modified by the input date string. */ public static Date getRelativeDate(Date date, String dateString) { if (date == null) throw new IllegalArgumentException("Null date"); Pattern pat = Pattern.compile("([+-]?[0-9]+)([dmhMy])"); Matcher match = pat.matcher(dateString); boolean matches = match.matches(); if (!matches) { throw new IllegalArgumentException( "Couldn't make sense of " + dateString + ", please use something like -7d or -8h"); } int amount = Integer.parseInt(match.group(1).replace("+", "")); String unit = match.group(2); if (unit.equals("h")) { return DateUtils.addHours(date, amount); } else if (unit.equals("m")) { return DateUtils.addMinutes(date, amount); } else if (unit.equals("d")) { return DateUtils.addDays(date, amount); } else if (unit.equals("y")) { return DateUtils.addYears(date, amount); } else if (unit.equals("M")) { return DateUtils.addMonths(date, amount); } else { throw new IllegalArgumentException( "Couldn't make sense of units in " + dateString + ", please use something like -7d or -8h"); } }