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:cn.mypandora.util.MyDateUtils.java
/** * .//from ww w . j a va 2 s. c o m * * @param begin . * @param end ? . * @return */ public static List<String> getDaysListBetweenDates(String begin, String end) { List<String> dateList = new ArrayList<String>(); Date d1; Date d2; try { d1 = DateUtils.parseDate(begin, DATE_FORMAT); d2 = DateUtils.parseDate(end, DATE_FORMAT); if (d1.compareTo(d2) > 0) { return dateList; } do { dateList.add(DateFormatUtils.format(d1, DATE_FORMAT)); d1 = DateUtils.addDays(d1, 1); } while (d1.compareTo(d2) <= 0); } catch (ParseException e) { e.printStackTrace(); } return dateList; }
From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBeanHibernateTest.java
@Test public void testSendRenewalReminders() { AnnualRegistration registrationWithinWindow = createTestRegistration(profile, configuration, null, DateUtils.addDays(new Date(), 30)); AnnualRegistration withdrawnRegistrationWithinWindow = createTestRegistration(withdrawnProfile, configuration, null, DateUtils.addDays(new Date(), 30)); AnnualRegistration disqualifiedRegistrationWithinWindow = createTestRegistration(disqualifiedProfile, configuration, null, DateUtils.addDays(new Date(), 30)); AnnualRegistration registrationOutsideOfWindow = createTestRegistration(profile, configuration, null, DateUtils.addDays(new Date(), 30 + 1)); AnnualRegistration submittedRegistrationWithinWindow = createTestRegistration(profile, configuration, null, DateUtils.addDays(new Date(), 30)); submittedRegistrationWithinWindow.setStatus(RegistrationStatus.SUBMITTED); AnnualRegistration reminderSentRegistrationWithinWindow = createTestRegistration(profile, configuration, null, DateUtils.addDays(new Date(), 30)); reminderSentRegistrationWithinWindow.setSecondRenewalNotificationSent(true); saveAndFlush(registrationWithinWindow, withdrawnRegistrationWithinWindow, disqualifiedRegistrationWithinWindow, registrationOutsideOfWindow, submittedRegistrationWithinWindow, reminderSentRegistrationWithinWindow); bean.sendRenewalReminders();/*from w w w. ja v a2 s .co m*/ registrationWithinWindow = reloadObject(registrationWithinWindow); withdrawnRegistrationWithinWindow = reloadObject(withdrawnRegistrationWithinWindow); disqualifiedRegistrationWithinWindow = reloadObject(disqualifiedRegistrationWithinWindow); registrationOutsideOfWindow = reloadObject(registrationOutsideOfWindow); reminderSentRegistrationWithinWindow = reloadObject(reminderSentRegistrationWithinWindow); submittedRegistrationWithinWindow = reloadObject(submittedRegistrationWithinWindow); assertTrue(registrationWithinWindow.isSecondRenewalNotificationSent()); assertFalse(withdrawnRegistrationWithinWindow.isSecondRenewalNotificationSent()); assertFalse(disqualifiedRegistrationWithinWindow.isSecondRenewalNotificationSent()); assertTrue(reminderSentRegistrationWithinWindow.isSecondRenewalNotificationSent()); assertFalse(registrationOutsideOfWindow.isSecondRenewalNotificationSent()); assertFalse(submittedRegistrationWithinWindow.isSecondRenewalNotificationSent()); }
From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java
@Test public void testWaitingQueueForUnboundedCategory() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository) .getKey();/* www. j a va2 s . com*/ TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).get(0); TicketReservationModification tr = new TicketReservationModification(); tr.setAmount(AVAILABLE_SEATS); tr.setTicketCategoryId(unbounded.getId()); TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty()); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(mod), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.<String>empty(), Optional.<String>empty(), Locale.ENGLISH, false); TotalPrice reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId); PaymentResult result = ticketReservationManager.confirm("", null, event, reservationId, "test@test.ch", new CustomerName("Full Name", "Full", "Name", event), Locale.ENGLISH, "", reservationCost, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null); assertTrue(result.isSuccessful()); assertEquals(0, eventRepository.findStatisticsFor(event.getId()).getDynamicAllocation()); }
From source file:com.omertron.themoviedbapi.methods.TmdbPeopleTest.java
/** * Test of getPersonChanges method, of class TmdbPeople. * * @throws com.omertron.themoviedbapi.MovieDbException *///from www .j ava2s . com @Test public void testGetPersonChanges() throws MovieDbException { LOG.info("getPersonChanges"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String startDate = sdf.format(DateUtils.addDays(new Date(), -14)); String endDate = ""; int maxCheck = 5; TmdbChanges chgs = new TmdbChanges(getApiKey(), getHttpTools()); ResultList<ChangeListItem> changeList = chgs.getChangeList(MethodBase.PERSON, null, null, null); LOG.info("Found {} person changes to check", changeList.getResults().size()); int count = 1; ResultList<ChangeKeyItem> result; for (ChangeListItem item : changeList.getResults()) { result = instance.getPersonChanges(item.getId(), startDate, endDate); for (ChangeKeyItem ci : result.getResults()) { assertNotNull("Null changes", ci); } if (count++ > maxCheck) { break; } } }
From source file:gov.nih.nci.firebird.service.user.CertificateAuthorityManagerBeanTest.java
@Test public void testIsCertificateExpired_Expired() throws Exception { X509CertificateObject certificate = mock(X509CertificateObject.class); when(certificate.getNotAfter()).thenReturn(DateUtils.addDays(new Date(), -1)); assertTrue(bean.isCertificateExpired(certificate)); }
From source file:gov.nih.nci.firebird.service.user.CertificateAuthorityManagerBeanTest.java
@Test public void testIsCertificateExpired_NotExpired() throws Exception { X509CertificateObject certificate = mock(X509CertificateObject.class); when(certificate.getNotAfter()).thenReturn(DateUtils.addDays(new Date(), 1)); assertFalse(bean.isCertificateExpired(certificate)); }
From source file:gov.nih.nci.firebird.test.nes.NesTestDataLoader.java
boolean isCachedDataFresh() { Date lastModified = new Date(getCacheFile().lastModified()); return lastModified.after(DateUtils.addDays(new Date(), -1)); }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
/** * Get the entire timeframe based on the panel settings * * @return TimeFrame The timeframe//from ww w . ja va2s. c om */ public TimeFrame getTimeFrame() { Date correctedArrive = DateUtils.addDays(maxArriveTimeField.getSelectedDate(), 1); correctedArrive = DateUtils.addSeconds(correctedArrive, -1); maxArriveTimeField.setDate(correctedArrive); TimeFrame frame = new TimeFrame(minSendTimeField.getSelectedDate(), minSendTimeField.getSelectedDate(), correctedArrive, correctedArrive); DefaultListModel model = (DefaultListModel) jTimeFrameList.getModel(); for (int i = 0; i < jTimeFrameList.getModel().getSize(); i++) { TimeSpan s = (TimeSpan) model.getElementAt(i); if (s.getDirection().equals(TimeSpan.DIRECTION.SEND)) { frame.addStartTimeSpan(s); } else if (s.getDirection().equals(TimeSpan.DIRECTION.ARRIVE)) { frame.addArriveTimeSpan(s); } } return frame; }
From source file:com.inkubator.hrm.service.impl.LogWtAttendanceRealizationServiceImpl.java
@Override @Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void afterMonthEndProcess() throws Exception { /** update payrollType status di periode yg lama menjadi VOID */ WtPeriode wtPeriode = wtPeriodeDao.getEntityByAbsentTypeActive(); wtPeriode.setAbsen(HRMConstant.PERIODE_ABSEN_VOID); wtPeriode.setUpdatedOn(new Date()); wtPeriode.setUpdatedBy(HRMConstant.SYSTEM_ADMIN); wtPeriodeDao.update(wtPeriode);/*from w ww. j av a 2 s . c o m*/ /** dapatkan range (untilPeriode dan fromPeriode) untuk periode yg baru */ Date untilPeriode = wtPeriode.getUntilPeriode(); Date fromPeriode = DateUtils.addDays(untilPeriode, 1); int lastDateOfMonth = DateUtils.toCalendar(untilPeriode).getActualMaximum(Calendar.DAY_OF_MONTH); if (lastDateOfMonth == DateUtils.toCalendar(untilPeriode).get(Calendar.DATE)) { untilPeriode = DateUtils.addMonths(untilPeriode, 1); lastDateOfMonth = DateUtils.toCalendar(untilPeriode).getActualMaximum(Calendar.DAY_OF_MONTH); untilPeriode = DateUtils.setDays(untilPeriode, lastDateOfMonth); } else { untilPeriode = DateUtils.addMonths(untilPeriode, 1); } /** adding process or update the entity if already exist */ WtPeriode wtp = wtPeriodeDao.getEntityByFromPeriodeAndUntilPeriode(fromPeriode, untilPeriode); if (wtp == null) { wtp = new WtPeriode(); wtp.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(9))); wtp.setTahun(String.valueOf(DateUtils.toCalendar(fromPeriode).get(Calendar.YEAR))); wtp.setBulan(DateUtils.toCalendar(fromPeriode).get(Calendar.MONTH) + 1); wtp.setFromPeriode(fromPeriode); wtp.setUntilPeriode(untilPeriode); wtp.setAbsen(HRMConstant.PERIODE_ABSEN_ACTIVE); wtp.setPayrollType(HRMConstant.PERIODE_PAYROLL_NOT_ACTIVE); long totalHoliday = wtHolidayDao.getTotalBetweenDate(fromPeriode, untilPeriode); int workingDays = DateTimeUtil.getTotalWorkingDay(fromPeriode, untilPeriode, (int) totalHoliday, 0); wtp.setWorkingDays(workingDays); wtp.setCreatedOn(new Date()); wtp.setCreatedBy(HRMConstant.SYSTEM_ADMIN); wtPeriodeDao.save(wtp); } else { wtp.setAbsen(HRMConstant.PERIODE_ABSEN_ACTIVE); wtp.setUpdatedOn(new Date()); wtp.setUpdatedBy(HRMConstant.SYSTEM_ADMIN); wtPeriodeDao.update(wtp); } /** delete all the record in the temporary table **/ tempProcessReadFingerDao.deleteAllData(); tempAttendanceRealizationDao.deleteAllData(); }
From source file:gov.nih.nci.firebird.nes.organization.NesOrganizationServiceBeanTest.java
@Test public void testRefreshIfStale_StaleOrganization() throws Exception { Date staleDate = DateUtils.addDays(new Date(), -2); NesOrganizationData nesOrganizationData = (NesOrganizationData) organization.getExternalData(); nesOrganizationData.setLastNesRefresh(staleDate); bean.refreshIfStale(organization);/*from ww w . j a v a 2s . c om*/ verify(mockOrganizationIntegrationService).refresh(organization); }