List of usage examples for org.joda.time DateTime plusYears
public DateTime plusYears(int years)
From source file:com.linagora.obm.ui.scenario.event.EventStepdefs.java
License:Open Source License
@And("^event \"([^\"]*)\" appears every year at (\\d+)/(\\d+)/(\\d+) from (\\d+):(\\d+) to (\\d+):(\\d+)$") public void eventAppearsEveryYear(String title, int day, int month, int year, int beginHour, int beginMin, int endHour, int endMin) { processedCalendarPage.calendarViewWidget().listView(); processedCalendarPage.calendarCalRangeWidget().monthlyEvents(); DateTime dateTime = new DateTime().withDate(year, month, day); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); String expectedEventDatesTitle = expectedEventDatesTitle(beginHour, beginMin, endHour, endMin); for (int numberOfChecks = 0; numberOfChecks < 3; numberOfChecks++) { boolean found = false; dateTime = dateTime.plusYears(1); for (int monthIterator = 0; monthIterator < 12; monthIterator++) { processedCalendarPage.calendarNavBarWidget().nextPage(); found = isYearlyEventInPrintedMonth(title, dateTimeFormatter.print(dateTime), expectedEventDatesTitle); if (found) { break; }// w w w . j a va 2s.c o m } assertThat(found).isTrue(); } }
From source file:com.money.manager.ex.servicelayer.RecurringTransactionService.java
License:Open Source License
/** * @param date to start calculate//from w w w. j a v a 2 s .c o m * @param repeatType type of repeating transactions * @param numberOfPeriods Number of instances (days, months) parameter. Used for In (x) Days, for * example to indicate x. * @return next Date */ public DateTime getNextScheduledDate(DateTime date, Recurrence repeatType, Integer numberOfPeriods) { if (numberOfPeriods == null || numberOfPeriods == Constants.NOT_SET) { numberOfPeriods = 0; } if (repeatType.getValue() >= 200) { repeatType = Recurrence.valueOf(repeatType.getValue() - 200); } // set auto execute without user acknowledgement if (repeatType.getValue() >= 100) { repeatType = Recurrence.valueOf(repeatType.getValue() - 100); } // set auto execute on the next occurrence DateTime result = new DateTime(date); switch (repeatType) { case ONCE: //none break; case WEEKLY: //weekly result = result.plusWeeks(1); break; case BIWEEKLY: //bi_weekly result = result.plusWeeks(2); break; case MONTHLY: //monthly result = result.plusMonths(1); break; case BIMONTHLY: //bi_monthly result = result.plusMonths(2); break; case QUARTERLY: //quarterly result = result.plusMonths(3); break; case SEMIANNUALLY: //half_year result = result.plusMonths(6); break; case ANNUALLY: //yearly result = result.plusYears(1); break; case FOUR_MONTHS: //four_months result = result.plusMonths(4); break; case FOUR_WEEKS: //four_weeks result = result.plusWeeks(4); break; case DAILY: //daily result = result.plusDays(1); break; case IN_X_DAYS: //in_x_days case EVERY_X_DAYS: //every_x_days result = result.plusDays(numberOfPeriods); break; case IN_X_MONTHS: //in_x_months case EVERY_X_MONTHS: //every_x_months result = result.plusMonths(numberOfPeriods); break; case MONTHLY_LAST_DAY: //month (last day) // if the date is not the last day of this month, set it to the end of the month. // else set it to the end of the next month. DateTime lastDayOfMonth = MmxDateTimeUtils.getLastDayOfMonth(result); if (!result.equals(lastDayOfMonth)) { // set to last day of the month result = lastDayOfMonth; } else { result = lastDayOfMonth.plusMonths(1); } break; case MONTHLY_LAST_BUSINESS_DAY: //month (last business day) // if the date is not the last day of this month, set it to the end of the month. // else set it to the end of the next month. DateTime lastDayOfMonth2 = MmxDateTimeUtils.getLastDayOfMonth(result); if (!result.equals(lastDayOfMonth2)) { // set to last day of the month result = lastDayOfMonth2; } else { result = lastDayOfMonth2.plusMonths(1); } // get the last day of the next month, // then iterate backwards until we are on a weekday. while (result.getDayOfWeek() == DateTimeConstants.SATURDAY || result.getDayOfWeek() == DateTimeConstants.SUNDAY) { result = result.minusDays(1); } break; } return result; }
From source file:com.mycompany.assignment1.Course.java
public Course(String name, DateTime start, DateTime end) { this.courseName = name; this.Start = start; this.End = end.plusYears(4); //based on a four year Course from todays date. }
From source file:com.netflix.ice.basic.BasicDataManager.java
License:Apache License
private double[] getData(Interval interval, TagLists tagLists) throws ExecutionException { DateTime start = config.startDate; DateTime end = config.startDate;/*from w w w . j a va2s . c o m*/ if (consolidateType == ConsolidateType.hourly) { start = interval.getStart().withDayOfMonth(1).withMillisOfDay(0); end = interval.getEnd(); } else if (consolidateType == ConsolidateType.daily) { start = interval.getStart().withDayOfYear(1).withMillisOfDay(0); end = interval.getEnd(); } int num = 0; if (consolidateType == ConsolidateType.hourly) { num = interval.toPeriod(PeriodType.hours()).getHours(); if (interval.getStart().plusHours(num).isBefore(interval.getEnd())) num++; } else if (consolidateType == ConsolidateType.daily) { num = interval.toPeriod(PeriodType.days()).getDays(); if (interval.getStart().plusDays(num).isBefore(interval.getEnd())) num++; } else if (consolidateType == ConsolidateType.weekly) { num = interval.toPeriod(PeriodType.weeks()).getWeeks(); if (interval.getStart().plusWeeks(num).isBefore(interval.getEnd())) num++; } else if (consolidateType == ConsolidateType.monthly) { num = interval.toPeriod(PeriodType.months()).getMonths(); if (interval.getStart().plusMonths(num).isBefore(interval.getEnd())) num++; } double[] result = new double[num]; do { ReadOnlyData data = getReadOnlyData(start); int resultIndex = 0; int fromIndex = 0; if (interval.getStart().isBefore(start)) { if (consolidateType == ConsolidateType.hourly) { resultIndex = Hours.hoursBetween(interval.getStart(), start).getHours(); } else if (consolidateType == ConsolidateType.daily) { resultIndex = Days.daysBetween(interval.getStart(), start).getDays(); } else if (consolidateType == ConsolidateType.weekly) { resultIndex = Weeks.weeksBetween(interval.getStart(), start).getWeeks(); } else if (consolidateType == ConsolidateType.monthly) { resultIndex = Months.monthsBetween(interval.getStart(), start).getMonths(); } } else { if (consolidateType == ConsolidateType.hourly) { fromIndex = Hours.hoursBetween(start, interval.getStart()).getHours(); } else if (consolidateType == ConsolidateType.daily) { fromIndex = Days.daysBetween(start, interval.getStart()).getDays(); } else if (consolidateType == ConsolidateType.weekly) { fromIndex = Weeks.weeksBetween(start, interval.getStart()).getWeeks(); if (start.getDayOfWeek() != interval.getStart().getDayOfWeek()) fromIndex++; } else if (consolidateType == ConsolidateType.monthly) { fromIndex = Months.monthsBetween(start, interval.getStart()).getMonths(); } } List<Integer> columeIndexs = Lists.newArrayList(); int columeIndex = 0; for (TagGroup tagGroup : data.getTagGroups()) { if (tagLists.contains(tagGroup)) columeIndexs.add(columeIndex); columeIndex++; } while (resultIndex < num && fromIndex < data.getNum()) { double[] fromData = data.getData(fromIndex++); for (Integer cIndex : columeIndexs) result[resultIndex] += fromData[cIndex]; resultIndex++; } if (consolidateType == ConsolidateType.hourly) start = start.plusMonths(1); else if (consolidateType == ConsolidateType.daily) start = start.plusYears(1); else break; } while (start.isBefore(end)); return result; }
From source file:com.netflix.ice.reader.ReaderConfig.java
License:Apache License
private void readData(Product product, DataManager dataManager, Interval interval, ConsolidateType consolidateType) { if (consolidateType == ConsolidateType.hourly) { DateTime start = interval.getStart().withDayOfMonth(1).withMillisOfDay(0); do {/*from w w w . ja v a 2 s . c o m*/ int hours = dataManager.getDataLength(start); logger.info("found " + hours + " hours data for " + product + " " + interval); start = start.plusMonths(1); } while (start.isBefore(interval.getEnd())); } else if (consolidateType == ConsolidateType.daily) { DateTime start = interval.getStart().withDayOfYear(1).withMillisOfDay(0); do { dataManager.getDataLength(start); start = start.plusYears(1); } while (start.isBefore(interval.getEnd())); } else { dataManager.getData(interval, new TagLists(), TagType.Account, AggregateType.both, false); } }
From source file:com.netflix.raigad.indexmanagement.ElasticSearchIndexManager.java
License:Apache License
/** * Courtesy Jae Bae//from w w w . j a v a 2 s. com */ public void preCreateIndex(IndexMetadata indexMetadata, Client esTransportClient) throws UnsupportedAutoIndexException { logger.info("Running PreCreate Index task"); IndicesStatusResponse getIndicesResponse = getIndicesStatusResponse(esTransportClient); Map<String, IndexStatus> indexStatusMap = getIndicesResponse.getIndices(); if (!indexStatusMap.isEmpty()) { for (String indexNameWithDateSuffix : indexStatusMap.keySet()) { if (config.isDebugEnabled()) logger.debug("Index Name = <" + indexNameWithDateSuffix + ">"); if (indexMetadata.getIndexNameFilter().filter(indexNameWithDateSuffix) && indexMetadata.getIndexNameFilter().getNamePart(indexNameWithDateSuffix) .equalsIgnoreCase(indexMetadata.getIndexName())) { for (int i = 0; i < indexMetadata.getRetentionPeriod(); ++i) { DateTime dt = new DateTime(); int addedDate; switch (indexMetadata.getRetentionType()) { case DAILY: dt = dt.plusDays(i); addedDate = Integer.parseInt(String.format("%d%02d%02d", dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth())); break; case MONTHLY: dt = dt.plusMonths(i); addedDate = Integer .parseInt(String.format("%d%02d", dt.getYear(), dt.getMonthOfYear())); break; case YEARLY: dt = dt.plusYears(i); addedDate = Integer.parseInt(String.format("%d", dt.getYear())); break; default: throw new UnsupportedAutoIndexException( "Given index is not (DAILY or MONTHLY or YEARLY), please check your configuration."); } if (config.isDebugEnabled()) logger.debug("Added Date = " + addedDate); if (!esTransportClient.admin().indices() .prepareExists(indexMetadata.getIndexName() + addedDate).execute() .actionGet(config.getAutoCreateIndexTimeout()).isExists()) { esTransportClient.admin().indices() .prepareCreate(indexMetadata.getIndexName() + addedDate).execute() .actionGet(config.getAutoCreateIndexTimeout()); logger.info(indexMetadata.getIndexName() + addedDate + " is created"); } else { //TODO: Change to Debug after Testing logger.warn(indexMetadata.getIndexName() + addedDate + " already exists"); } } } } } else { logger.info("No existing indices, hence can not pre-create any indices"); } }
From source file:com.netflix.raigad.indexmanagement.IndexUtils.java
License:Apache License
public static int getFutureRetentionDate(IndexMetadata indexMetadata) throws UnsupportedAutoIndexException { DateTime dt = new DateTime(); int currentDate; switch (indexMetadata.getRetentionType()) { case DAILY:/*from w w w .j a va2 s . c o m*/ dt = dt.plusDays(indexMetadata.getRetentionPeriod()); currentDate = Integer .parseInt(String.format("%d%02d%02d", dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth())); break; case MONTHLY: dt = dt.plusMonths(indexMetadata.getRetentionPeriod()); currentDate = Integer.parseInt(String.format("%d%02d", dt.getYear(), dt.getMonthOfYear())); break; case YEARLY: dt = dt.plusYears(indexMetadata.getRetentionPeriod()); currentDate = Integer.parseInt(String.format("%d", dt.getYear())); break; default: throw new UnsupportedAutoIndexException( "Given index is not (DAILY or MONTHLY or YEARLY), please check your configuration."); } return currentDate; }
From source file:com.netsteadfast.greenstep.bsc.action.MeasureDataCalendarQueryAction.java
License:Apache License
private String handlerDate() throws Exception { String dateStr = this.getFields().get("date"); String frequency = this.getFields().get("frequency"); String dateStatus = this.getFields().get("dateStatus"); DateTime dateTime = new DateTime(dateStr); if ("-1".equals(dateStatus)) { // if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)) { // dateTime = dateTime.plusMonths(-1); } else { // dateTime = dateTime.plusYears(-1); }/* ww w. jav a 2 s .co m*/ } if ("1".equals(dateStatus)) { // if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)) { // dateTime = dateTime.plusMonths(1); } else { // dateTime = dateTime.plusYears(1); } } return dateTime.toString("yyyy-MM-dd"); }
From source file:com.ning.billing.catalog.DefaultDuration.java
License:Apache License
@Override public DateTime addToDateTime(final DateTime dateTime) { if ((number == null) && (unit != TimeUnit.UNLIMITED)) { return dateTime; }/* w ww. j a v a 2 s .c om*/ switch (unit) { case DAYS: return dateTime.plusDays(number); case MONTHS: return dateTime.plusMonths(number); case YEARS: return dateTime.plusYears(number); case UNLIMITED: return dateTime.plusYears(100); default: return dateTime; } }
From source file:com.ning.billing.util.clock.DefaultClock.java
License:Apache License
public static DateTime addOrRemoveDuration(final DateTime input, final List<Duration> durations, final boolean add) { DateTime result = input; for (final Duration cur : durations) { switch (cur.getUnit()) { case DAYS: result = add ? result.plusDays(cur.getNumber()) : result.minusDays(cur.getNumber()); break; case MONTHS: result = add ? result.plusMonths(cur.getNumber()) : result.minusMonths(cur.getNumber()); break; case YEARS: result = add ? result.plusYears(cur.getNumber()) : result.minusYears(cur.getNumber()); break; case UNLIMITED: default:/* ww w .j a v a 2s. c o m*/ throw new RuntimeException("Trying to move to unlimited time period"); } } return result; }