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:com.formkiq.core.dao.QueueDaoImpl.java
@SuppressWarnings("resource") @Override//from w w w . j a va 2s . c o m public int deleteExpiredMessages() { Date dayBefore = DateUtils.addDays(this.dateservice.now(), -1); String sql = "delete from queue_messages where " + " inserted_date < :date and status=:status"; Session session = getEntityManager().unwrap(Session.class); int result = session.createSQLQuery(sql).setParameter("date", dayBefore) .setParameter("status", QueueMessageStatus.TO_BE_DELETED.name()).executeUpdate(); return result; }
From source file:com.lk.ofo.util.DateUtil.java
/** * ????/* ww w .ja v a 2 s . c o m*/ * * @param addDate * @param hour * @return */ public static Date getAfterDate(int addDate, int hour) { Date currentDate = new Date(); Date date = DateUtils.addDays(currentDate, addDate); date = DateUtils.setHours(date, hour); date = DateUtils.setMinutes(date, 0); date = DateUtils.setSeconds(date, 0); date = DateUtils.setMilliseconds(date, 0); return date; }
From source file:net.diogobohm.timed.impl.ui.overviewwindow.OverviewWindowController.java
private ActionListener createBackPeriodAction() { return new ActionListener() { @Override/*ww w . ja v a 2 s . c om*/ public void actionPerformed(ActionEvent e) { Date curStartDate = getModel().getStartDate(); Date curEndDate = getModel().getEndDate(); Date newEndDate = DateUtils.addDays(curStartDate, -1); Date newStartDate = new Date( newEndDate.getTime() - (curEndDate.getTime() - curStartDate.getTime())); Overview overview = fetchOverviewFor(newStartDate, newEndDate); getModel().setDomainBean(getView(), overview); getModel().setDates(newStartDate, newEndDate); } }; }
From source file:com.epam.ta.reportportal.core.job.BaseInterruptTest.java
protected Launch insertLaunchInProgres() { String randomPart = RandomStringUtils.randomAlphabetic(5); Launch launch = new Launch(); launch.setId(ObjectId.get().toString()); launch.setStartTime(DateUtils.addDays(Calendar.getInstance().getTime(), -1)); launch.setName("launch".concat(randomPart)); launch.setDescription("description".concat(randomPart)); launch.setStatus(Status.IN_PROGRESS); launch.setLastModified(DateUtils.addDays(Calendar.getInstance().getTime(), -1)); launch.setStatistics(new Statistics(new ExecutionCounter(), new IssueCounter())); Project p = new Project(); p.setName("test project"); p.getConfiguration().setStatisticsCalculationStrategy(StatisticsCalculationStrategy.TEST_BASED); p.getConfiguration().setInterruptJobTime(InterruptionJobDelay.THREE_HOURS.getValue()); p.getConfiguration().setKeepLogs(KeepLogsDelay.TWO_WEEKS.getValue()); p.getConfiguration().setKeepScreenshots(KeepScreenshotsDelay.ONE_WEEK.getValue()); projectRepository.save(p);//from www.j a v a 2 s . com launch.setProjectRef(p.getId()); launchRepository.save(launch); return launch; }
From source file:eu.ggnet.dwoss.uniqueunit.assist.gen.UniqueUnitGenerator.java
/** * Generates a random Unit, based on the Product and from the contractor. * <p/>//from ww w.j a v a2 s.com * @param product the product as basis, if null ignored. * @param contractor the contractor, if null randomly selected. * @return the generated unit. */ private UniqueUnit makeUniqueUnit(TradeName contractor, ProductGroup group, Product product) { if (contractor == null) throw new RuntimeException( "As the Contractor is Mandator specific, it must not be null, even for generated Units."); String serial = (product == null ? RandomStringUtils.randomAlphanumeric(22).toUpperCase() : product.getPartNo().replaceAll("\\.", "") + RandomStringUtils.randomAlphanumeric(12).toUpperCase()); if (group == null && product != null) group = product.getGroup(); UniqueUnit uu = new UniqueUnit(); uu.addHistory("Generated by makeUniqueUnit(contractor=" + contractor + ", group=" + group + ", product=" + product + ")"); // Not perfect, but works. Integer refurbisId = CONTRACTOR_REFURBISHIDS.get(contractor); if (refurbisId == null) refurbisId = 123456; else refurbisId++; CONTRACTOR_REFURBISHIDS.put(contractor, refurbisId); uu.setIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbisId.toString()); uu.setIdentifier(UniqueUnit.Identifier.SERIAL, serial); uu.setContractor(contractor); uu.setMfgDate(DateUtils.addDays(new Date(), -1 * R.nextInt(1000))); // Random Date, may 3 years in the past. uu.setCondition(UniqueUnit.Condition.values()[R.nextInt(UniqueUnit.Condition.values().length)]); uu.setEquipments(randomSet(group == null ? UniqueUnit.Equipment.values() : UniqueUnit.Equipment.getEquipments(group).toArray(new UniqueUnit.Equipment[0]))); uu.setComments(randomSet(UniqueUnit.StaticComment.values())); uu.setInternalComments(randomSet(UniqueUnit.StaticInternalComment.values())); if ((Math.random() * 100) > 75) { uu.setWarranty(WARRANTY_TILL_DATE); uu.setWarrentyValid(new Date((long) (System.currentTimeMillis() + Math.random() * 21600000000L))); } return uu; }
From source file:com.actelion.research.spiritapp.ui.audit.RecentChangesDlg.java
public RecentChangesDlg(String userId) { super(UIUtils.getMainFrame(), "Recent Changes"); if (userId == null) { userTextField.setText(""); userTextField.setEnabled(true);/*from ww w.j a v a2s. c om*/ } else { userTextField.setText(userId.length() == 0 ? "NA" : userId); userTextField.setEnabled(false); } userTextField.setTextWhenEmpty("UserId"); fromTextField.setText(FormatterUtils.formatDate(DateUtils.addDays(new Date(), -3))); toTextField.setText(FormatterUtils.formatDate(DateUtils.addDays(new Date(), 1))); //RevisionPanel JButton filterButton = new JIconButton(IconType.SEARCH, "Search"); filterButton.addActionListener(e -> loadRevisions()); userTextField.addActionListener(e -> loadRevisions()); //fromTextField.addActionListener(e->loadRevisions()); //toTextField.addActionListener(e->loadRevisions()); studyComboBox.addActionListener(e -> loadRevisions()); byFieldCheckbox.addActionListener(e -> revisionPanel.setSingular(byFieldCheckbox.isSelected())); byFieldCheckbox.setVisible(SpiritProperties.getInstance().isAdvancedMode()); exportChangeEventsAction.setParentDlg(this); JIconButton exportChangeEventsButton = new JIconButton(IconType.PDF, "Export Change Events...", exportChangeEventsAction); JPanel actionPanel = UIUtils.createHorizontalBox(Box.createHorizontalGlue(), exportChangeEventsButton); JPanel revisionQueryPanel = UIUtils.createTitleBox("Filters", UIUtils.createVerticalBox( UIUtils.createTable(4, new JLabel("From: "), fromTextField, new JLabel(" To: "), toTextField), UIUtils.createHorizontalBox(byFieldCheckbox, Box.createHorizontalGlue()), Box.createVerticalStrut(10), new JSeparator(JSeparator.HORIZONTAL), UIUtils.createHorizontalBox(studyCheckBox, sampleCheckBox, locationCheckBox, resultCheckBox, Box.createHorizontalGlue()), UIUtils.createBox(BorderFactory.createEmptyBorder(10, 10, 10, 0), UIUtils.createTable(2, new JLabel("StudyId: "), studyComboBox/*, new JLabel("UserId: "), userTextField*/)), new JSeparator(JSeparator.HORIZONTAL), UIUtils.createHorizontalBox(adminChanges, Box.createHorizontalGlue()), Box.createVerticalStrut(20), new JSeparator(JSeparator.HORIZONTAL), UIUtils.createHorizontalBox(Box.createHorizontalGlue(), filterButton), Box.createVerticalGlue())); getRootPane().setDefaultButton(filterButton); if (!SpiritProperties.getInstance().isChecked(PropertyKey.SYSTEM_RESULT)) { resultCheckBox.setVisible(false); resultCheckBox.setSelected(false); } //ContentPane setContentPane(UIUtils.createBox(revisionPanel, null, actionPanel, revisionQueryPanel, null)); UIUtils.adaptSize(this, 1200, 800); setVisible(true); }
From source file:jease.cms.service.Contents.java
/** * Deletes all objects older than given days in all Trash objects in the * system.// w w w . j a v a2 s.c o m */ public static void emptyTrash(int daysToKeep) { Date pivotDate = DateUtils.addDays(new Date(), -daysToKeep); for (Trash trash : Database.query(Trash.class)) { if (ArrayUtils.isNotEmpty(trash.getChildren())) { for (Content content : trash.getChildren(Content.class)) { if (content.getLastModified().before(pivotDate)) { if (Contents.isDeletable(content)) { Contents.delete(content); } } } } } }
From source file:net.diogobohm.timed.impl.ui.overviewwindow.OverviewWindowController.java
private ActionListener createForwardPeriodAction() { return new ActionListener() { @Override//from w ww . j av a 2 s . c om public void actionPerformed(ActionEvent e) { Date today = new Date(); Date curStartDate = getModel().getStartDate(); Date curEndDate = getModel().getEndDate(); Date newStartDate = DateUtils.addDays(curEndDate, 1); Date newEndDate = new Date( newStartDate.getTime() + (curEndDate.getTime() - curStartDate.getTime())); if (newStartDate.after(today)) { return; } Overview overview = fetchOverviewFor(newStartDate, newEndDate); getModel().setDomainBean(getView(), overview); getModel().setDates(newStartDate, newEndDate); } }; }
From source file:com.lk.ofo.util.DateUtil.java
/** * ?????/*from ww w .java 2s .com*/ * * @param currentDate * @param addDate * @param hour * @return */ public static Date getAfterDate(Date currentDate, int addDate, int hour) { Date date = DateUtils.addDays(currentDate, addDate); date = DateUtils.setHours(date, hour); date = DateUtils.setMinutes(date, 0); date = DateUtils.setSeconds(date, 0); date = DateUtils.setMilliseconds(date, 0); return date; }
From source file:alfio.manager.Jobs.java
void cleanupForDemoMode() { if (environment.acceptsProfiles(Initializer.PROFILE_DEMO)) { int expirationDate = configurationManager.getIntConfigValue( Configuration.getSystemConfiguration(ConfigurationKeys.DEMO_MODE_ACCOUNT_EXPIRATION_DAYS), 20); List<Integer> userIds = userManager .disableAccountsOlderThan(DateUtils.addDays(new Date(), -expirationDate), User.Type.DEMO); if (!userIds.isEmpty()) { eventManager.disableEventsFromUsers(userIds); }/*from ww w .j a va 2 s. c om*/ } }