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.silverpeas.gallery.dao.MediaDaoTest.java
@Test public void getSocialInformationListOfMyContacts() throws Exception { performDAOTest(new DAOTest() { @Override/* w ww. j a v a 2 s . c o m*/ public void test(final Connection connection) throws Exception { Date beginDate = DateUtils.addDays(CREATE_DATE, +1); Date endDate = DateUtils.addDays(CREATE_DATE, +2); List<SocialInformation> socialInformationList = MediaDAO.getSocialInformationListOfMyContacts( connection, Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()), Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate)); assertThat(socialInformationList, hasSize(0)); beginDate = DateUtils.addDays(CREATE_DATE, 0); endDate = DateUtils.addDays(CREATE_DATE, +2); socialInformationList = MediaDAO.getSocialInformationListOfMyContacts(connection, Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()), Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate)); assertThat(socialInformationList, hasSize(4)); beginDate = DateUtils.addDays(LAST_UPDATE_DATE, -2); endDate = DateUtils.addDays(LAST_UPDATE_DATE, +2); socialInformationList = MediaDAO.getSocialInformationListOfMyContacts(connection, Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()), Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate)); assertThat(socialInformationList, hasSize(7)); } }); }
From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBean.java
private boolean isCurrentDateAfterDueDateAndWithinRenewalRange(Date dueDate) { Date now = new Date(); Date boundaryDate = DateUtils.addDays(dueDate, daysAfterDueDateToUseAsBasisForRenewalDate); return now.before(boundaryDate) && now.after(dueDate); }
From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java
private String reserveTickets(Event event, TicketCategory category, int num) { TicketReservationModification tr = new TicketReservationModification(); tr.setAmount(num);/*from ww w .jav a 2s .co m*/ tr.setTicketCategoryId(category.getId()); TicketReservationWithOptionalCodeModification tcm = new TicketReservationWithOptionalCodeModification(tr, Optional.empty()); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(tcm), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.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()); return reservationId; }
From source file:gov.nih.nci.firebird.nes.person.NesPersonServiceBeanTest.java
@Test public void testRefreshIfStale_StaleRecord() throws Exception { NesPersonServiceBean serviceSpy = spy(service); gov.nih.nci.firebird.data.Person person = PersonFactory.getInstance().create(); when(mockPersonClient.getById(any(Id.class))).thenReturn(PersonTranslator.buildNesPerson(person)); Date staleDate = DateUtils.addDays(new Date(), -2); getNesPersonData(person).setLastNesRefresh(staleDate); serviceSpy.refreshIfStale(person);//from w ww . j a v a2 s . co m verify(serviceSpy).refreshNow(person); }
From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBeanTest.java
@Test public void testSetRenewalDateIfNecessary_WithFutureDueDate() { AnnualRegistration registration = new AnnualRegistration(); Date dueDate = DateUtils.addDays(new Date(), daysBeforeDueDateToSendFirstNotification - 1); registration.setDueDate(dueDate);//from w w w. java2s.com bean.setRenewalDateIfNecessary(registration); Date expectedDate = DateUtils.addYears(dueDate, 1); assertEquals(expectedDate, registration.getRenewalDate()); }
From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBeanTest.java
@Test public void testSetRenewalDateIfNecessary_WithPastDueDateWithin30Days() { AnnualRegistration registration = new AnnualRegistration(); Date dueDate = DateUtils.addDays(new Date(), -5); registration.setDueDate(dueDate);//w w w. j a va2s .c o m bean.setRenewalDateIfNecessary(registration); Date expectedDate = DateUtils.addYears(dueDate, 1); assertTrue(DateUtils.isSameDay(expectedDate, registration.getRenewalDate())); }
From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBeanTest.java
@Test public void testSetRenewalDateIfNecessary_WithPastDueDateAfter30Days() { AnnualRegistration registration = new AnnualRegistration(); Date dueDate = DateUtils.addDays(new Date(), -60); registration.setDueDate(dueDate);//from w ww . ja v a 2s . c o m bean.setRenewalDateIfNecessary(registration); Date expectedDate = DateUtils.addYears(new Date(), 1); assertTrue(DateUtils.isSameDay(expectedDate, registration.getRenewalDate())); }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testValidationBoundedFailedPendingTickets() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);//w w w .ja va2s . c om Event event = pair.getLeft(); String username = pair.getRight(); TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0); Map<String, String> categoryDescription = ticketCategoryDescriptionRepository .descriptionForTicketCategory(category.getId()); List<Integer> tickets = ticketRepository.selectTicketInCategoryForUpdate(event.getId(), category.getId(), 1, Collections.singletonList(Ticket.TicketStatus.FREE.name())); String reservationId = "12345678"; ticketReservationRepository.createNewReservation(reservationId, DateUtils.addDays(new Date(), 1), null, "en", event.getId(), event.getVat(), event.isVatIncluded()); ticketRepository.reserveTickets(reservationId, tickets, category.getId(), "en", 100); TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 10, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), false, "", false, null, null, null, null, null); Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username); assertFalse(result.isSuccess()); }
From source file:com.silverpeas.gallery.dao.MediaDaoTest.java
@Test public void saveNewPhoto() throws Exception { performDAOTest(new DAOTest() { @Override// ww w .j ava2s . c om public void test(final Connection connection) throws Exception { Date now = DateUtil.getNow(); Date beginVisibilityDate = DateUtils.addMonths(now, -1); Date endVisibilityDate = DateUtils.addMonths(now, 4); Date beginDownloadDate = DateUtils.addDays(now, -10); Date endDownloadDate = DateUtils.addDays(now, 5); Photo newPhoto = new Photo(); newPhoto.setComponentInstanceId(INSTANCE_A); newPhoto.setTitle("A title"); newPhoto.setDescription("A description"); newPhoto.setAuthor("An author"); newPhoto.setKeyWord("keywords"); newPhoto.setVisibilityPeriod(Period.from(beginVisibilityDate, endVisibilityDate)); newPhoto.setFileName("new file name"); newPhoto.setFileSize(2048); newPhoto.setFileMimeType(MediaMimeType.TIFF); newPhoto.setDownloadAuthorized(true); newPhoto.setDownloadPeriod(Period.from(beginDownloadDate, endDownloadDate)); newPhoto.setDefinition(Definition.of(200, 100)); assertThat(newPhoto.getId(), nullValue()); String newId = MediaDAO.saveMedia(connection, OperationContext.fromUser(adminAccessUser), newPhoto); assertThat(newPhoto.getId(), notNullValue()); assertThat(newPhoto.getId(), is(newId)); IDataSet actualDataSet = getActualDataSet(); ITable mediaTable = actualDataSet.getTable("SC_Gallery_Media"); assertThat(mediaTable.getRowCount(), is(MEDIA_ROW_COUNT + 1)); ITable internalTable = actualDataSet.getTable("SC_Gallery_Internal"); assertThat(internalTable.getRowCount(), is(MEDIA_INTERNAL_ROW_COUNT + 1)); ITable photoTable = actualDataSet.getTable("SC_Gallery_Photo"); assertThat(photoTable.getRowCount(), is(MEDIA_PHOTO_ROW_COUNT + 1)); ITable videoTable = actualDataSet.getTable("SC_Gallery_Video"); assertThat(videoTable.getRowCount(), is(MEDIA_VIDEO_ROW_COUNT)); ITable soundTable = actualDataSet.getTable("SC_Gallery_Sound"); assertThat(soundTable.getRowCount(), is(MEDIA_SOUND_ROW_COUNT)); ITable streamingTable = actualDataSet.getTable("SC_Gallery_Streaming"); assertThat(streamingTable.getRowCount(), is(MEDIA_STREAMING_ROW_COUNT)); ITable pathTable = actualDataSet.getTable("SC_Gallery_Path"); assertThat(pathTable.getRowCount(), is(MEDIA_PATH_ROW_COUNT)); TableRow mediaRow = getTableRowFor(mediaTable, "mediaId", newPhoto.getId()); assertThat(mediaRow.getString("mediaId"), is(newId)); assertThat(mediaRow.getString("mediaType"), is(MediaType.Photo.name())); assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A)); assertThat(mediaRow.getString("title"), is("A title")); assertThat(mediaRow.getString("description"), is("A description")); assertThat(mediaRow.getString("author"), is("An author")); assertThat(mediaRow.getString("keyword"), is("keywords")); assertThat(mediaRow.getLong("beginVisibilityDate"), is(beginVisibilityDate.getTime())); assertThat(mediaRow.getLong("endVisibilityDate"), is(endVisibilityDate.getTime())); assertThat(mediaRow.getDate("createDate"), greaterThanOrEqualTo(now)); assertThat(mediaRow.getString("createdBy"), is(adminAccessUser.getId())); assertThat(mediaRow.getDate("lastUpdateDate"), is(mediaRow.getDate("createDate"))); assertThat(mediaRow.getString("lastUpdatedBy"), is(adminAccessUser.getId())); TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", newPhoto.getId()); assertThat(iMediaRow.getString("mediaId"), is(newId)); assertThat(iMediaRow.getString("fileName"), is("new file name")); assertThat(iMediaRow.getLong("fileSize"), is(2048L)); assertThat(iMediaRow.getString("fileMimeType"), is("image/tiff")); assertThat(iMediaRow.getInteger("download"), is(1)); assertThat(iMediaRow.getLong("beginDownloadDate"), is(beginDownloadDate.getTime())); assertThat(iMediaRow.getLong("endDownloadDate"), is(endDownloadDate.getTime())); TableRow photoRow = getTableRowFor(photoTable, "mediaId", newPhoto.getId()); assertThat(photoRow.getString("mediaId"), is(newId)); assertThat(photoRow.getInteger("resolutionH"), is(100)); assertThat(photoRow.getInteger("resolutionW"), is(200)); } }); }
From source file:com.inkubator.hrm.service.impl.PayTempKalkulasiServiceImpl.java
private Double getDefaultWorkingDay(Date startPeriodDate, Date endPeriodDate) throws Exception { double totalDay = 0.0; //get DEFAULT kelompok kerja karyawan WtGroupWorking workingGroup = wtGroupWorkingDao.getByCode(HRMConstant.WORKING_GROUP_CODE_DEFAULT); if (workingGroup != null) { List<TempJadwalKaryawan> tempJadwalKaryawans = new ArrayList<TempJadwalKaryawan>(); //loop date-nya, check jadwal berdasarkan kelompok kerja for (Date loop = startPeriodDate; loop.before(endPeriodDate) || DateUtils.isSameDay(loop, endPeriodDate); loop = DateUtils.addDays(loop, 1)) { TempJadwalKaryawan jadwal = Lambda.selectFirst(tempJadwalKaryawans, Lambda.having(Lambda.on(TempJadwalKaryawan.class).getTanggalWaktuKerja().getTime(), Matchers.equalTo(loop.getTime()))); if (jadwal == null) { //jika tidak terdapat jadwal kerja di date tersebut, maka generate jadwal kerja temporary-nya, lalu check kembali jadwal kerja-nya List<TempJadwalKaryawan> jadwalKaryawans = wtScheduleShiftService .getAllScheduleForView(workingGroup.getId(), loop, null); tempJadwalKaryawans.addAll(jadwalKaryawans); jadwal = Lambda.selectFirst(tempJadwalKaryawans, Lambda.having(Lambda.on(TempJadwalKaryawan.class).getTanggalWaktuKerja().getTime(), Matchers.equalTo(loop.getTime()))); }//from w w w . j a va2s. c o m //selain "OFF"(hari libur) berarti termasuk jam kerja if (!StringUtils.equals(jadwal.getWtWorkingHour().getCode(), "OFF")) { totalDay++; } } } return totalDay; }