List of usage examples for org.apache.commons.lang3.time DateUtils addMonths
public static Date addMonths(final Date date, final int amount)
From source file:org.openmrs.ISO8601Duration.java
/** * Add this duration to given startDate/* w w w . ja v a 2s. c o m*/ * * @param startDate * @param frequency is used to calculate time to be added to startDate when duration unit is * 'Recurring Interval' * @return date which is startDate plus duration */ public Date addToDate(Date startDate, OrderFrequency frequency) { if (SECONDS_CODE.equals(code)) return DateUtils.addSeconds(startDate, duration); if (MINUTES_CODE.equals(code)) return DateUtils.addMinutes(startDate, duration); if (HOURS_CODE.equals(code)) return DateUtils.addHours(startDate, duration); if (DAYS_CODE.equals(code)) return DateUtils.addDays(startDate, duration); if (WEEKS_CODE.equals(code)) return DateUtils.addWeeks(startDate, duration); if (MONTHS_CODE.equals(code)) return DateUtils.addMonths(startDate, duration); if (YEARS_CODE.equals(code)) return DateUtils.addYears(startDate, duration); if (RECURRING_INTERVAL_CODE.equals(code)) { if (frequency == null) throw new APIException("Frequency can not be null when duration in Recurring Interval"); return DateUtils.addSeconds(startDate, (int) (duration * SECONDS_PER_DAY / frequency.getFrequencyPerDay())); } throw new APIException(String.format("Unknown code '%s' for ISO8601 duration units", code)); }
From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java
@Test public void saveNewPhoto() 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);/*from w w w . ja v a2 s . c om*/ 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 = Transaction .performInOne(() -> MediaDAO.saveMedia(OperationContext.fromUser(adminAccessUser), newPhoto)); assertThat(newPhoto.getId(), notNullValue()); assertThat(newPhoto.getId(), is(newId)); try (Connection connection = getConnection()) { IDataSet actualDataSet = getActualDataSet(connection); 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:org.silverpeas.components.gallery.dao.MediaDaoIT.java
@Test public void saveExistingPhoto() throws Exception { Date now = DateUtil.getNow(); Date endVisibilityDate = DateUtils.addMonths(now, 4); Date beginDownloadDate = DateUtils.addDays(now, -10); String mediaIdToUpdate = "2"; try (Connection connection = getConnection()) { IDataSet actualDataSet = getActualDataSet(connection); ITable mediaTable = actualDataSet.getTable("SC_Gallery_Media"); assertThat(mediaTable.getRowCount(), is(MEDIA_ROW_COUNT)); ITable internalTable = actualDataSet.getTable("SC_Gallery_Internal"); assertThat(internalTable.getRowCount(), is(MEDIA_INTERNAL_ROW_COUNT)); ITable photoTable = actualDataSet.getTable("SC_Gallery_Photo"); assertThat(photoTable.getRowCount(), is(MEDIA_PHOTO_ROW_COUNT)); 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", mediaIdToUpdate); assertThat(mediaRow.getString("mediaId"), is(mediaIdToUpdate)); assertThat(mediaRow.getString("mediaType"), is(MediaType.Photo.name())); assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A)); assertThat(mediaRow.getString("title"), is("title 2")); assertThat(mediaRow.getValue("description"), nullValue()); assertThat(mediaRow.getValue("author"), nullValue()); assertThat(mediaRow.getValue("keyword"), nullValue()); assertThat(mediaRow.getLong("beginVisibilityDate"), is(DateUtil.MINIMUM_DATE.getTime())); assertThat(mediaRow.getLong("endVisibilityDate"), is(DateUtil.MAXIMUM_DATE.getTime())); assertThat(mediaRow.getDate("createDate"), is(CREATE_DATE)); assertThat(mediaRow.getString("createdBy"), is("0")); assertThat(mediaRow.getDate("lastUpdateDate"), is(CREATE_DATE)); assertThat(mediaRow.getString("lastUpdatedBy"), is("0")); TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", mediaIdToUpdate); assertThat(iMediaRow.getString("mediaId"), is(mediaIdToUpdate)); assertThat(iMediaRow.getString("fileName"), is("fileName_2")); assertThat(iMediaRow.getLong("fileSize"), is(102L)); assertThat(iMediaRow.getString("fileMimeType"), is("image/png")); assertThat(iMediaRow.getInteger("download"), is(0)); assertThat(iMediaRow.getValue("beginDownloadDate"), nullValue()); assertThat(iMediaRow.getValue("endDownloadDate"), nullValue()); TableRow photoRow = getTableRowFor(photoTable, "mediaId", mediaIdToUpdate); assertThat(photoRow.getString("mediaId"), is(mediaIdToUpdate)); assertThat(photoRow.getInteger("resolutionH"), is(600)); assertThat(photoRow.getInteger("resolutionW"), is(800)); }//from w ww . j a v a 2 s . c o m Photo photoToUpdate = Transaction .performInOne( () -> MediaDAO.getByCriteria(defaultMediaCriteria().identifierIsOneOf(mediaIdToUpdate))) .getPhoto(); photoToUpdate.setTitle(photoToUpdate.getTitle() + "_updated"); photoToUpdate.setKeyWord("keywords_updated"); photoToUpdate.setVisibilityPeriod(Period.from(DateUtil.MINIMUM_DATE, endVisibilityDate)); photoToUpdate.setFileName(photoToUpdate.getFileName() + "_updated"); photoToUpdate.setFileSize(2048); photoToUpdate.setFileMimeType(MediaMimeType.TIFF); photoToUpdate.setDownloadAuthorized(true); photoToUpdate.setDownloadPeriod(Period.from(beginDownloadDate, DateUtil.MAXIMUM_DATE)); photoToUpdate.setDefinition(Definition.of(200, 100)); String savedMediaId = photoToUpdate.getId(); String mediaId = Transaction .performInOne(() -> MediaDAO.saveMedia(OperationContext.fromUser(publisherUser), photoToUpdate)); assertThat(mediaId, is(savedMediaId)); assertThat(mediaId, is(photoToUpdate.getId())); try (Connection connection = getConnection()) { IDataSet actualDataSet = getActualDataSet(connection); ITable mediaTable = actualDataSet.getTable("SC_Gallery_Media"); assertThat(mediaTable.getRowCount(), is(MEDIA_ROW_COUNT)); ITable internalTable = actualDataSet.getTable("SC_Gallery_Internal"); assertThat(internalTable.getRowCount(), is(MEDIA_INTERNAL_ROW_COUNT)); ITable photoTable = actualDataSet.getTable("SC_Gallery_Photo"); assertThat(photoTable.getRowCount(), is(MEDIA_PHOTO_ROW_COUNT)); 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", mediaIdToUpdate); assertThat(mediaRow.getString("mediaId"), is(mediaIdToUpdate)); assertThat(mediaRow.getString("mediaType"), is(MediaType.Photo.name())); assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A)); assertThat(mediaRow.getString("title"), is("title 2_updated")); assertThat(mediaRow.getString("description"), isEmptyString()); assertThat(mediaRow.getString("author"), isEmptyString()); assertThat(mediaRow.getString("keyword"), is("keywords_updated")); assertThat(mediaRow.getLong("beginVisibilityDate"), is(DateUtil.MINIMUM_DATE.getTime())); assertThat(mediaRow.getLong("endVisibilityDate"), is(endVisibilityDate.getTime())); assertThat(mediaRow.getDate("createDate"), is(CREATE_DATE)); assertThat(mediaRow.getString("createdBy"), is("0")); assertThat(mediaRow.getDate("lastUpdateDate"), greaterThanOrEqualTo(now)); assertThat(mediaRow.getString("lastUpdatedBy"), is(publisherUser.getId())); TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", mediaIdToUpdate); assertThat(iMediaRow.getString("mediaId"), is(mediaIdToUpdate)); assertThat(iMediaRow.getString("fileName"), is("fileName_2_updated")); 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.getValue("endDownloadDate"), nullValue()); TableRow photoRow = getTableRowFor(photoTable, "mediaId", mediaIdToUpdate); assertThat(photoRow.getString("mediaId"), is(mediaIdToUpdate)); assertThat(photoRow.getInteger("resolutionH"), is(100)); assertThat(photoRow.getInteger("resolutionW"), is(200)); } }
From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java
@Test public void saveNewVideo() throws Exception { Date now = DateUtil.getNow(); Date beginVisibilityDate = DateUtils.addMonths(now, -1); Date endDownloadDate = DateUtils.addDays(now, 5); Video newVideo = new Video(); newVideo.setComponentInstanceId(INSTANCE_A); newVideo.setTitle("A video title"); newVideo.setAuthor("A video author"); newVideo.setKeyWord("video keywords"); newVideo.setVisibilityPeriod(Period.from(beginVisibilityDate, DateUtil.MAXIMUM_DATE)); newVideo.setFileName("new video file name"); newVideo.setFileSize(2048);//w w w . ja v a 2 s . c o m newVideo.setFileMimeType(MediaMimeType.MP4); newVideo.setDownloadAuthorized(false); newVideo.setDownloadPeriod(Period.from(DateUtil.MINIMUM_DATE, endDownloadDate)); newVideo.setDefinition(Definition.of(1920, 1080)); assertThat(newVideo.getId(), nullValue()); String newId = Transaction .performInOne(() -> MediaDAO.saveMedia(OperationContext.fromUser(writerUser), newVideo)); assertThat(newVideo.getId(), notNullValue()); assertThat(newVideo.getId(), is(newId)); try (Connection connection = getConnection()) { IDataSet actualDataSet = getActualDataSet(connection); 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)); ITable videoTable = actualDataSet.getTable("SC_Gallery_Video"); assertThat(videoTable.getRowCount(), is(MEDIA_VIDEO_ROW_COUNT + 1)); 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", newVideo.getId()); assertThat(mediaRow.getString("mediaId"), is(newId)); assertThat(mediaRow.getString("mediaType"), is(MediaType.Video.name())); assertThat(mediaRow.getString("instanceId"), is(INSTANCE_A)); assertThat(mediaRow.getString("title"), is("A video title")); assertThat(mediaRow.getString("description"), isEmptyString()); assertThat(mediaRow.getString("author"), is("A video author")); assertThat(mediaRow.getString("keyword"), is("video keywords")); assertThat(mediaRow.getLong("beginVisibilityDate"), is(beginVisibilityDate.getTime())); assertThat(mediaRow.getLong("endVisibilityDate"), is(DateUtil.MAXIMUM_DATE.getTime())); assertThat(mediaRow.getDate("createDate"), greaterThanOrEqualTo(now)); assertThat(mediaRow.getString("createdBy"), is(writerUser.getId())); assertThat(mediaRow.getDate("lastUpdateDate"), is(mediaRow.getDate("createDate"))); assertThat(mediaRow.getString("lastUpdatedBy"), is(writerUser.getId())); TableRow iMediaRow = getTableRowFor(internalTable, "mediaId", newVideo.getId()); assertThat(iMediaRow.getString("mediaId"), is(newId)); assertThat(iMediaRow.getString("fileName"), is("new video file name")); assertThat(iMediaRow.getLong("fileSize"), is(2048L)); assertThat(iMediaRow.getString("fileMimeType"), is("video/mp4")); assertThat(iMediaRow.getInteger("download"), is(0)); assertThat(iMediaRow.getLong("beginDownloadDate"), nullValue()); assertThat(iMediaRow.getLong("endDownloadDate"), is(endDownloadDate.getTime())); TableRow videoRow = getTableRowFor(videoTable, "mediaId", newVideo.getId()); assertThat(videoRow.getString("mediaId"), is(newId)); assertThat(videoRow.getInteger("resolutionH"), is(1080)); assertThat(videoRow.getInteger("resolutionW"), is(1920)); assertThat(videoRow.getLong("bitrate"), is(0L)); assertThat(videoRow.getLong("duration"), is(0L)); } }
From source file:org.silverpeas.core.date.AbstractDateDatable.java
@Override public T addMonths(final int amount) { return newInstanceFrom(DateUtils.addMonths(this, amount)); }
From source file:org.silverpeas.core.util.DateUtilTest.java
@Test public void testGetOutputDateAndHour() { Date date = DateUtil.resetHour(java.sql.Date.valueOf("2013-05-21")); assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/21/2013")); Date year = DateUtils.addYears(date, 1); assertThat(DateUtil.getOutputDateAndHour(year, LANGUAGE), is("05/21/2014")); Date month = DateUtils.addMonths(date, 1); assertThat(DateUtil.getOutputDateAndHour(month, LANGUAGE), is("06/21/2013")); Date day = DateUtils.addDays(date, 1); assertThat(DateUtil.getOutputDateAndHour(day, LANGUAGE), is("05/22/2013")); Date hour = DateUtils.addHours(date, 1); assertThat(DateUtil.getOutputDateAndHour(hour, LANGUAGE), is("05/21/2013 01:00")); hour = DateUtils.addHours(date, 12); assertThat(DateUtil.getOutputDateAndHour(hour, LANGUAGE), is("05/21/2013 12:00")); hour = DateUtils.addHours(date, 22); assertThat(DateUtil.getOutputDateAndHour(hour, LANGUAGE), is("05/21/2013 22:00")); Date minute = DateUtils.addMinutes(date, 1); assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 00:01")); minute = DateUtils.addMinutes(date, 59); assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 00:59")); minute = DateUtils.addMinutes(date, 60); assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 01:00")); minute = DateUtils.addMinutes(date, 61); assertThat(DateUtil.getOutputDateAndHour(minute, LANGUAGE), is("05/21/2013 01:01")); Date second = DateUtils.addSeconds(date, 1); assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:00")); second = DateUtils.addSeconds(date, 59); assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:00")); second = DateUtils.addSeconds(date, 60); assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:01")); second = DateUtils.addSeconds(date, 61); assertThat(DateUtil.getOutputDateAndHour(second, LANGUAGE), is("05/21/2013 00:01")); Date millisecond = DateUtils.addMilliseconds(date, 1); assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00")); millisecond = DateUtils.addMilliseconds(date, 999); assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00")); millisecond = DateUtils.addMilliseconds(date, 1000); assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00")); millisecond = DateUtils.addMilliseconds(date, 1001); assertThat(DateUtil.getOutputDateAndHour(millisecond, LANGUAGE), is("05/21/2013 00:00")); // 2013-05-21 23:59:59.999 date = DateUtils.addHours(// w w w . j ava 2s.com DateUtils.addMinutes(DateUtils.addSeconds(DateUtils.addMilliseconds(date, 999), 59), 59), 23); assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/21/2013 23:59")); // 2013-05-22 00:00:00.000 date = DateUtils.addMilliseconds(date, 1); assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/22/2013")); // 2013-05-22 00:00:00.001 date = DateUtils.addMilliseconds(date, 1); assertThat(DateUtil.getOutputDateAndHour(date, LANGUAGE), is("05/22/2013 00:00")); }
From source file:org.silverpeas.core.web.calendar.CalendarTimeWindowViewContext.java
/** * Centralization.// w w w . java 2 s . c om * @param offset */ private void moveReferenceDate(int offset) { switch (viewType) { case YEARLY: setReferenceDay(DateUtils.addYears(referenceDay.getDate(), offset), offset); break; case MONTHLY: setReferenceDay(DateUtils.addMonths(referenceDay.getDate(), offset), offset); break; case WEEKLY: setReferenceDay(DateUtils.addWeeks(referenceDay.getDate(), offset), offset); break; case DAILY: setReferenceDay(DateUtils.addDays(referenceDay.getDate(), offset), offset); break; } }
From source file:org.silverpeas.termsOfService.constant.TermsOfServiceAcceptanceFrequencyTest.java
@Test public void testIsAcceptanceDateExpired() { // This test is to don't forget to add or remove test block below in case of upgrade of the // enum./* w w w . j a va2 s .co m*/ assertThat(values().length, is(7)); // NEVER assertThat(NEVER.isAcceptanceDateExpired(FIRST_OF_JUNE, null, LOCALE), is(false)); assertThat(NEVER.isAcceptanceDateExpired(FIRST_OF_JUNE, FIRST_OF_JUNE, LOCALE), is(false)); assertThat(NEVER.isAcceptanceDateExpired(FIRST_OF_JUNE, java.sql.Date.valueOf("1970-01-01"), LOCALE), is(false)); // ALWAYS assertThat(ALWAYS.isAcceptanceDateExpired(FIRST_OF_JUNE, null, LOCALE), is(true)); assertThat(ALWAYS.isAcceptanceDateExpired(FIRST_OF_JUNE, FIRST_OF_JUNE, LOCALE), is(true)); assertThat(ALWAYS.isAcceptanceDateExpired(FIRST_OF_JUNE, java.sql.Date.valueOf("1970-01-01"), LOCALE), is(true)); // ONE assertThat(ONE.isAcceptanceDateExpired(FIRST_OF_JUNE, null, LOCALE), is(true)); assertThat(ONE.isAcceptanceDateExpired(FIRST_OF_JUNE, FIRST_OF_JUNE, LOCALE), is(false)); assertThat(ONE.isAcceptanceDateExpired(FIRST_OF_JUNE, java.sql.Date.valueOf("1970-01-01"), LOCALE), is(false)); // DAILY assertThat(DAILY.isAcceptanceDateExpired(FIRST_OF_JUNE, null, LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(FIRST_OF_JUNE, FIRST_OF_JUNE, LOCALE), is(false)); assertThat( DAILY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMilliseconds(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addDays(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addWeeks(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMonths(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addYears(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMilliseconds(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(DAILY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addDays(LAST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addWeeks(LAST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMonths(LAST_OF_JUNE, -1), LOCALE), is(true)); assertThat(DAILY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addYears(LAST_OF_JUNE, -1), LOCALE), is(true)); // WEEKLY assertThat(WEEKLY.isAcceptanceDateExpired(FIRST_OF_JUNE, null, LOCALE), is(true)); assertThat(WEEKLY.isAcceptanceDateExpired(FIRST_OF_JUNE, FIRST_OF_JUNE, LOCALE), is(false)); assertThat( WEEKLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMilliseconds(FIRST_OF_JUNE, -1), LOCALE), is(false)); assertThat(WEEKLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addDays(FIRST_OF_JUNE, -1), LOCALE), is(false)); assertThat(WEEKLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addWeeks(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(WEEKLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMonths(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(WEEKLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addYears(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat( WEEKLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMilliseconds(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(WEEKLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addDays(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(WEEKLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addDays(LAST_OF_JUNE, -6), LOCALE), is(false)); assertThat(WEEKLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addWeeks(LAST_OF_JUNE, -1), LOCALE), is(true)); assertThat(WEEKLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMonths(LAST_OF_JUNE, -1), LOCALE), is(true)); assertThat(WEEKLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addYears(LAST_OF_JUNE, -1), LOCALE), is(true)); // MONTHLY assertThat(MONTHLY.isAcceptanceDateExpired(FIRST_OF_JUNE, null, LOCALE), is(true)); assertThat(MONTHLY.isAcceptanceDateExpired(FIRST_OF_JUNE, FIRST_OF_JUNE, LOCALE), is(false)); assertThat(MONTHLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMilliseconds(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(MONTHLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addDays(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(MONTHLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addWeeks(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(MONTHLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMonths(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat(MONTHLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addYears(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat( MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMilliseconds(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addDays(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addDays(LAST_OF_JUNE, -29), LOCALE), is(false)); assertThat(MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addWeeks(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addWeeks(LAST_OF_JUNE, -4), LOCALE), is(false)); assertThat(MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addWeeks(LAST_OF_JUNE, -5), LOCALE), is(true)); assertThat(MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMonths(LAST_OF_JUNE, -1), LOCALE), is(true)); assertThat(MONTHLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addYears(LAST_OF_JUNE, -1), LOCALE), is(true)); // YEARLY assertThat(YEARLY.isAcceptanceDateExpired(FIRST_OF_JUNE, null, LOCALE), is(true)); assertThat(YEARLY.isAcceptanceDateExpired(FIRST_OF_JUNE, FIRST_OF_JUNE, LOCALE), is(false)); assertThat( YEARLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMilliseconds(FIRST_OF_JUNE, -1), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addDays(FIRST_OF_JUNE, -1), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addWeeks(FIRST_OF_JUNE, -1), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addMonths(FIRST_OF_JUNE, -1), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(FIRST_OF_JUNE, DateUtils.addYears(FIRST_OF_JUNE, -1), LOCALE), is(true)); assertThat( YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMilliseconds(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addDays(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addDays(LAST_OF_JUNE, -150), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addWeeks(LAST_OF_JUNE, -25), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMonths(LAST_OF_JUNE, -1), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addMonths(LAST_OF_JUNE, -5), LOCALE), is(false)); assertThat(YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addYears(LAST_OF_JUNE, -1), LOCALE), is(true)); assertThat(YEARLY.isAcceptanceDateExpired(LAST_OF_JUNE, DateUtils.addYears(LAST_OF_JUNE, 1), LOCALE), is(true)); }
From source file:org.springside.examples.schedule.service.ScheduleService.java
public void updateGetedBulletin() throws Exception { //?, XX// w ww . j a v a2 s. co m Date maxAnnouncementDate = bulletinDataDao.findMaxAnnouncementDate(); // Date getFrom; if (maxAnnouncementDate != null) {//?? ?? XX getFrom = maxAnnouncementDate; } else {//? getFrom = DateUtils.addDays(bulletinViewDao.findMinAnnouncementDate(), -1); } //? (step) Date getTo = DateUtils.addMonths(getFrom, stepJumpBulletin); //?? List<BulletinView> bulletinViews = bulletinViewDao.getBulletinViewFromToTime(getFrom, getTo); // List<BulletinData> bulletinDatas = new ArrayList<BulletinData>(); if (bulletinViews != null && bulletinViews.size() > 0) { for (BulletinView bulletinView : bulletinViews) { BulletinData dest = new BulletinData(); BeanUtils.copyProperties(dest, bulletinView); dest.setSynStatus(BulletinData.SYNSTATUS_STANBY); bulletinDatas.add(dest); } } //? bulletinDataDao.save(bulletinDatas); System.out.println("??" + bulletinDatas.size() + "?step=" + stepJumpBulletin); //step if (bulletinDatas.size() == 0 && getTo.before(DateUtils.addMonths(new Date(), 12))) {//?? stepJumpBulletin += stepJumpBulletin; } else { stepJumpBulletin = STEPJUMPBULLETINNUM; } }
From source file:org.springside.examples.schedule.service.ScheduleService.java
public void updateGetedProject() throws Exception { //, XX//from w w w . j av a2 s . c o m Date maxDelegateDate = projectDataDao.findMaxDelegateDate(); // Date getFrom; if (maxDelegateDate != null) {//?? ?? XX getFrom = maxDelegateDate; } else {//? getFrom = DateUtils.addDays(projectViewDao.findMinDelegateDate(), -1); } //? (step) Date getTo = DateUtils.addMonths(getFrom, stepJumpProject); //?? List<ProjectView> projectViews = projectViewDao.getProjectViewFromToTime(getFrom, getTo); // List<ProjectData> projectDatas = new ArrayList<ProjectData>(); List<ProjectPkgData> projectPkgDatas = new ArrayList<ProjectPkgData>(); this.buildProjectAndPkg(projectViews, projectDatas, projectPkgDatas); //? projectDataDao.save(projectDatas); projectDataDao.save(projectPkgDatas); //?, ?????? getFrom ?? ? ???? Date currentDate = new Date(); if (getTo.after(currentDate)) {//?getTo ?? if (backSynProjectFromDate == null) { backSynProjectFromDate = currentDate;//? } long oaprojCount = projectViewDao.countBeforeDate(backSynProjectFromDate); long projCount = projectDataDao.countBeforeDate(backSynProjectFromDate); if (oaprojCount != projCount) { System.out.println("oaprojCount:" + oaprojCount + ", projCount:" + projCount); // //-7 oa List<ProjectView> oaProjectViews = projectViewDao.getProjectViewFromToTime( DateUtils.addDays(backSynProjectFromDate, -7), backSynProjectFromDate); //-7 local List<ProjectData> localProjectDatas = projectDataDao.getProjectDateFromToTime( DateUtils.addDays(backSynProjectFromDate, -7), backSynProjectFromDate); //?local List<ProjectView> notInLocalProjectViews = new ArrayList<ProjectView>(); //?oa List<ProjectData> notInOaProjectDatas = new ArrayList<ProjectData>(); System.out.println( "projectviews:" + oaProjectViews.size() + ",projectdatas:" + localProjectDatas.size()); //?? for (ProjectView projectView : oaProjectViews) { boolean inLocal = false; for (ProjectData projectData : localProjectDatas) { if (StringUtils.equals(projectView.getProjectId(), projectData.getProjectId())) { inLocal = true; break; } } if (!inLocal) { System.out.println("notInLocalProjectViewId:" + projectView.getProjectId()); notInLocalProjectViews.add(projectView); } } //?? for (ProjectData projectData : localProjectDatas) { boolean inOa = false; for (ProjectView projectView : oaProjectViews) { if (StringUtils.equals(projectData.getProjectId(), projectView.getProjectId())) { inOa = true; break; } } if (!inOa) { System.out.println("notInOaProjectDataId:" + projectData.getProjectId()); notInOaProjectDatas.add(projectData); } } //?local if (notInLocalProjectViews != null && notInLocalProjectViews.size() > 0) { List<ProjectData> projectDataBks = new ArrayList<ProjectData>(); List<ProjectPkgData> projectPkgDataBks = new ArrayList<ProjectPkgData>(); this.buildProjectAndPkg(notInLocalProjectViews, projectDataBks, projectPkgDataBks); projectDataDao.save(projectDataBks); projectDataDao.save(projectPkgDataBks); System.out.println("??" + projectDataBks.size() + "?, ?" + projectPkgDataBks.size() + "?"); } //?oa if (notInOaProjectDatas != null && notInOaProjectDatas.size() > 0) { for (ProjectData projectData : notInOaProjectDatas) { projectData.setUseStatus(ProjectData.USESTATUS_INVALID);// //TODO ????? } projectDataDao.save(notInOaProjectDatas); System.out.println("/?" + notInOaProjectDatas.size() + "?"); } backSynProjectFromDate = DateUtils.addDays(backSynProjectFromDate, -7);//? } else { //?? ? backSynProjectFromDate null backSynProjectFromDate = null; } System.out.println("" + backSynProjectFromDate); } System.out.println("??" + projectDatas.size() + "?, ?" + projectPkgDatas.size() + "?step=" + stepJumpProject); //step if (projectDatas.size() == 0 && getTo.before(DateUtils.addMonths(new Date(), 12))) {//?? stepJumpProject += stepJumpProject; } else { stepJumpProject = STEPJUMPPROJECTNUM; } }