List of usage examples for org.apache.commons.lang3.time DateUtils addWeeks
public static Date addWeeks(final Date date, final int amount)
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * * Get or return Past or Future date based on parameter</p> * <p>//from w ww .j a va 2 s . c o m * <b>Parameter amount :</b> use negative symbol to get past date, use * positive symbol to get future date. Parameter amount combination with * parameter constantParameter. </p> * <p> * <b>Parameter constantParameter :</b> the type of times that will be * added. Example : CommonUtilConstant.DATE_FORMAT_MONTH</p> * <p> * <b>ConstantParameter type :</b></p> * <ul> * <li>CommonUtilConstant.DATE_FORMAT_MILLISECOND = millisecond</li> * <li>CommonUtilConstant.DATE_FORMAT_SECOND = second</li> * <li>CommonUtilConstant.DATE_FORMAT_MINUTES = minutes</li> * <li>CommonUtilConstant.DATE_FORMAT_HOURS = hours</li> * <li>CommonUtilConstant.DATE_FORMAT_DAY = day</li> * <li>CommonUtilConstant.DATE_FORMAT_WEEK = week</li> * <li>CommonUtilConstant.DATE_FORMAT_MONTH = month</li> * <li>CommonUtilConstant.DATE_FORMAT_YEAR = year</li> * </ul> * * @return Date type of past or future date * @param inputParam Date reference to calculate * @param timeDifference Integer reference, can be negative value like -7 or * positive value like 7 * @param constantParameter String reference,see the CommonUtilConstant */ public static Date getDateFrom(Date inputParam, int timeDifference, String constantParameter) { Date returnDate = null; if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_DAY)) { returnDate = DateUtils.addDays(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_HOURS)) { returnDate = DateUtils.addHours(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MILLISECOND)) { returnDate = DateUtils.addMilliseconds(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MINUTES)) { returnDate = DateUtils.addMinutes(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MONTH)) { returnDate = DateUtils.addMonths(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_SECOND)) { returnDate = DateUtils.addSeconds(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_YEAR)) { returnDate = DateUtils.addYears(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_WEEK)) { returnDate = DateUtils.addWeeks(inputParam, timeDifference); } return returnDate; }
From source file:io.lavagna.web.api.MilestoneController.java
@ExpectPermission(Permission.READ) @RequestMapping(value = "/api/project/{projectShortName}/cards-by-milestone-detail/{milestoneId}", method = RequestMethod.GET) public MilestoneDetail findCardsByMilestoneDetail(@PathVariable("projectShortName") String projectShortName, @PathVariable("milestoneId") int milestoneId, UserWithPermission user) { int projectId = projectService.findIdByShortName(projectShortName); LabelListValueWithMetadata ms = cardLabelRepository.findListValueById(milestoneId); if (ms == null) { throw new IllegalArgumentException("Milestone not found"); }/* w w w . j a va 2 s.co m*/ SearchFilter filter = filter(SearchFilter.FilterType.MILESTONE, SearchFilter.ValueType.STRING, ms.getValue()); List<MilestoneCount> mcs = statisticsService.findCardsCountByMilestone(projectId, ms.getId()); Map<Long, Pair<Long, Long>> assignedAndClosedCards = statisticsService.getAssignedAndClosedCardsByMilestone( ms, DateUtils.addWeeks(DateUtils.truncate(new Date(), Calendar.DATE), -2)); SearchFilter notTrashFilter = filter(SearchFilter.FilterType.NOTLOCATION, SearchFilter.ValueType.STRING, BoardColumn.BoardColumnLocation.TRASH.toString()); SearchResults cards = searchService.find(Arrays.asList(filter, notTrashFilter), projectId, null, user); Map<ColumnDefinition, Long> cardsCountByStatus = new HashMap<>(); for (MilestoneCount count : mcs) { cardsCountByStatus.put(count.getColumnDefinition(), count.getCount()); } return new MilestoneDetail(cardsCountByStatus, getStatusColors(projectId), cards, assignedAndClosedCards); }
From source file:io.lavagna.web.api.CardController.java
@ExpectPermission(Permission.READ) @RequestMapping(value = "/api/project/{projectShortName}/cards-by-milestone-detail/{milestone}", method = RequestMethod.GET) public MilestoneDetail findCardsByMilestoneDetail(@PathVariable("projectShortName") String projectShortName, @PathVariable("milestone") String milestone, UserWithPermission user) { int projectId = projectService.findByShortName(projectShortName).getId(); CardLabel label = cardLabelRepository.findLabelByName(projectId, "MILESTONE", CardLabel.LabelDomain.SYSTEM); List<LabelListValueWithMetadata> listValues = cardLabelRepository .findListValuesByLabelIdAndValue(label.getId(), milestone); SearchFilter filter;// w w w . j a va 2s . c om Map<Long, Pair<Long, Long>> assignedAndClosedCards; if (listValues.size() > 0) { filter = filter(FilterType.MILESTONE, ValueType.STRING, milestone); assignedAndClosedCards = statisticsService.getAssignedAndClosedCardsByMilestone(listValues.get(0), DateUtils.addWeeks(DateUtils.truncate(new Date(), Calendar.DATE), -2)); } else { filter = filter(FilterType.MILESTONE, ValueType.UNASSIGNED, null); assignedAndClosedCards = null; } SearchFilter notTrashFilter = filter(SearchFilter.FilterType.NOTLOCATION, SearchFilter.ValueType.STRING, BoardColumnLocation.TRASH.toString()); SearchResults cards = searchService.find(Arrays.asList(filter, notTrashFilter), projectId, null, user); return new MilestoneDetail(cards, assignedAndClosedCards); }
From source file:com.feilong.core.date.DateUtil.java
/** * <code>date</code>? ({@link Calendar#WEEK_OF_YEAR}?,??),,. * <p>//from ww w . j ava2s. co m * ?<code>date</code>?? * </p> * * <h3>:</h3> * * <blockquote> * * <pre class="code"> * DateUtil.addWeek(2012-06-29 00:45:18,5) =2012-08-03 00:45:18 * DateUtil.addWeek(2012-06-29 00:45:18,-5) =2012-05-25 00:45:18 * </pre> * * </blockquote> * * @param date * ? * @param week * ??,<span style="color:red">?</span>,??<br> * @return <code>date</code>null, {@link java.lang.IllegalArgumentException} * @see org.apache.commons.lang3.time.DateUtils#addWeeks(Date, int) */ public static Date addWeek(Date date, int week) { return DateUtils.addWeeks(date, week); }
From source file:org.kuali.kra.subaward.service.SubAwardServiceTest.java
@Test public void testGetCalculatedFollowupDate() { Date checkDate = subAwardService.getCalculatedFollowupDate(new Date(2012, 1, 1)); Date expectedDate = new Date(DateUtils.addWeeks(new Date(2012, 1, 1), 6).getTime()); assertEquals(expectedDate, checkDate); }
From source file:org.openmrs.ISO8601Duration.java
/** * Add this duration to given startDate/* w w w . j a v a 2s . co 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.core.date.AbstractDateDatable.java
@Override public T addWeeks(final int amount) { return newInstanceFrom(DateUtils.addWeeks(this, amount)); }
From source file:org.silverpeas.core.web.calendar.CalendarTimeWindowViewContext.java
/** * Centralization./*w ww. ja v a 2 s.c o m*/ * @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./*from w ww . ja v a 2 s. c om*/ 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:ubic.gemma.core.analysis.report.WhatsNewServiceImpl.java
@Override public WhatsNew getReport() { Calendar c = Calendar.getInstance(); Date date = c.getTime();//from ww w. j a v a 2 s . co m date = DateUtils.addWeeks(date, -1); return this.getReport(date); }