List of usage examples for org.joda.time DateTime plusMonths
public DateTime plusMonths(int months)
From source file:com.court.controller.MemberfxmlController.java
private java.util.Date[] setInstallmentDates(int insts, LoanPayment lpLast) { java.util.Date lstDate = lpLast != null ? lpLast.getInstallmentDate() : new java.util.Date(); DateTimeZone zone = DateTimeZone.forID("Asia/Colombo"); DateTime ld = new DateTime(new SimpleDateFormat("yyyy-MM-dd").format(lstDate), zone); java.util.Date furueDates[] = new java.util.Date[insts]; for (int i = 0; i < insts; i++) { furueDates[i] = ld.plusMonths(i + 1).toDate(); }/*from w ww.j a v a2s . c om*/ return furueDates; }
From source file:com.court.controller.MemberfxmlController.java
private java.util.Date[] setInstallmentDates2(int insts, java.util.Date lpLast) { java.util.Date lstDate = lpLast != null ? lpLast : new java.util.Date(); DateTimeZone zone = DateTimeZone.forID("Asia/Colombo"); DateTime ld = new DateTime(new SimpleDateFormat("yyyy-MM-dd").format(lstDate), zone); java.util.Date furueDates[] = new java.util.Date[insts]; for (int i = 0; i < insts; i++) { furueDates[i] = ld.plusMonths(i + 1).toDate(); }//from w w w . ja va 2s . c o m return furueDates; }
From source file:com.cronutils.model.time.ExecutionTime.java
License:Apache License
/** * If date is not match, will return next closest match. * If date is match, will return this date. * @param date - reference DateTime instance - never null; * @return DateTime instance, never null. Value obeys logic specified above. * @throws NoSuchValueException/*from www . j a v a2 s . co m*/ */ DateTime nextClosestMatch(DateTime date) throws NoSuchValueException { List<Integer> year = yearsValueGenerator.generateCandidates(date.getYear(), date.getYear()); TimeNode days = null; int lowestMonth = months.getValues().get(0); int lowestHour = hours.getValues().get(0); int lowestMinute = minutes.getValues().get(0); int lowestSecond = seconds.getValues().get(0); NearestValue nearestValue; DateTime newDate; if (year.isEmpty()) { int newYear = yearsValueGenerator.generateNextValue(date.getYear()); days = generateDays(cronDefinition, new DateTime(newYear, lowestMonth, 1, 0, 0)); return initDateTime(yearsValueGenerator.generateNextValue(date.getYear()), lowestMonth, days.getValues().get(0), lowestHour, lowestMinute, lowestSecond, date.getZone()); } if (!months.getValues().contains(date.getMonthOfYear())) { nearestValue = months.getNextValue(date.getMonthOfYear(), 0); int nextMonths = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), 1, 1, 0, 0, 0, date.getZone()) .plusYears(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getMonthOfYear()) { date = date.plusYears(1); } days = generateDays(cronDefinition, new DateTime(date.getYear(), nextMonths, 1, 0, 0)); return initDateTime(date.getYear(), nextMonths, days.getValues().get(0), lowestHour, lowestMinute, lowestSecond, date.getZone()); } days = generateDays(cronDefinition, date); if (!days.getValues().contains(date.getDayOfMonth())) { nearestValue = days.getNextValue(date.getDayOfMonth(), 0); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), 1, 0, 0, 0, date.getZone()) .plusMonths(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getDayOfMonth()) { date = date.plusMonths(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), nearestValue.getValue(), lowestHour, lowestMinute, lowestSecond, date.getZone()); } if (!hours.getValues().contains(date.getHourOfDay())) { nearestValue = hours.getNextValue(date.getHourOfDay(), 0); int nextHours = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0, 0, date.getZone()).plusDays(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getHourOfDay()) { date = date.plusDays(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), nextHours, lowestMinute, lowestSecond, date.getZone()); } if (!minutes.getValues().contains(date.getMinuteOfHour())) { nearestValue = minutes.getNextValue(date.getMinuteOfHour(), 0); int nextMinutes = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), 0, 0, date.getZone()).plusHours(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getMinuteOfHour()) { date = date.plusHours(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), nextMinutes, lowestSecond, date.getZone()); } if (!seconds.getValues().contains(date.getSecondOfMinute())) { nearestValue = seconds.getNextValue(date.getSecondOfMinute(), 0); int nextSeconds = nearestValue.getValue(); if (nearestValue.getShifts() > 0) { newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), 0, date.getZone()) .plusMinutes(nearestValue.getShifts()); return nextClosestMatch(newDate); } if (nearestValue.getValue() < date.getSecondOfMinute()) { date = date.plusMinutes(1); } return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), nextSeconds, date.getZone()); } return date; }
From source file:com.ehdev.chronos.lib.types.holders.PayPeriodHolder.java
License:Open Source License
/** * Will do the calculations for the start and end of the process *//*from w ww. j av a 2 s .c om*/ public void generate() { //Get the start and end of pay period DateTime startOfPP = gJob.getStartOfPayPeriod(); gDuration = gJob.getDuration(); DateTime endOfPP = DateTime.now(); //Today long duration = endOfPP.getMillis() - startOfPP.getMillis(); DateTimeZone startZone = startOfPP.getZone(); DateTimeZone endZone = endOfPP.getZone(); long offset = endZone.getOffset(endOfPP) - startZone.getOffset(startOfPP); int weeks = (int) ((duration + offset) / 1000 / 60 / 60 / 24 / 7); /* System.out.println("end of pp: " + endOfPP); System.out.println("start of pp: " + startOfPP); System.out.println("dur: " + duration); System.out.println("weeks diff: " + weeks); */ switch (gDuration) { case ONE_WEEK: //weeks = weeks; startOfPP = startOfPP.plusWeeks(weeks); endOfPP = startOfPP.plusWeeks(1); break; case TWO_WEEKS: weeks = weeks / 2; startOfPP = startOfPP.plusWeeks(weeks * 2); endOfPP = startOfPP.plusWeeks(2); break; case THREE_WEEKS: weeks = weeks / 3; startOfPP = startOfPP.plusWeeks(weeks * 3); endOfPP = startOfPP.plusWeeks(3); break; case FOUR_WEEKS: weeks = weeks / 4; startOfPP = startOfPP.plusWeeks(weeks * 4); endOfPP = startOfPP.plusWeeks(4); break; case FULL_MONTH: //in this case, endOfPP is equal to now startOfPP = DateMidnight.now().toDateTime().withDayOfMonth(1); endOfPP = startOfPP.plusMonths(1); break; case FIRST_FIFTEENTH: DateTime now = DateTime.now(); if (now.getDayOfMonth() >= 15) { startOfPP = now.withDayOfMonth(15); endOfPP = startOfPP.plusDays(20).withDayOfMonth(1); } else { startOfPP = now.withDayOfMonth(1); endOfPP = now.withDayOfMonth(15); } break; default: break; } if (startOfPP.isAfter(DateTime.now())) { startOfPP = startOfPP.minusWeeks(getDays() / 7); endOfPP = endOfPP.minusWeeks(getDays() / 7); } gStartOfPP = startOfPP; gEndOfPP = endOfPP; }
From source file:com.epam.ta.reportportal.core.widget.content.StatisticBasedContentLoader.java
License:Open Source License
/** * Create ranged empty timeline billet// ww w . ja v a2 s. c o m * * @param base * @param period * @return */ private Map<String, ChartObject> buildRange(List<ChartObject> base, Period period) { final LongSummaryStatistics statistics = base.stream() .mapToLong(object -> Long.valueOf(object.getStartTime())).summaryStatistics(); final DateTime start = new DateTime(statistics.getMin()); final DateTime end = new DateTime(statistics.getMax()); DateTime intermediate = start; final LinkedHashMap<String, ChartObject> map = new LinkedHashMap<>(); if (base.isEmpty()) return map; while (intermediate.isBefore(end)) { map.put(intermediate.toString(DATE_PATTERN), createChartObject(base.get(0))); switch (period) { case DAY: intermediate = intermediate.plusDays(1); break; case WEEK: intermediate = intermediate.plusDays(1); break; case MONTH: intermediate = intermediate.plusMonths(1); break; } } map.put(end.toString(DATE_PATTERN), createChartObject(base.get(0))); return map; }
From source file:com.goodhuddle.huddle.service.impl.PaymentServiceImpl.java
License:Open Source License
private Payment postProcessPayment(Payment payment) throws CardException, APIException, AuthenticationException, InvalidRequestException, APIConnectionException { // get the fee information PaymentSettings settings = getPaymentSettings(); BalanceTransaction transaction = BalanceTransaction.retrieve(payment.getStripeBalanceTransactionId(), settings.getSecretKey());//from w w w . j a v a 2s .c om payment.setFeesInCents(transaction.getFee()); paymentRepository.save(payment); if (payment.getSubscription() != null) { Subscription subscription = payment.getSubscription(); DateTime nextPaymentDue = new DateTime(payment.getPaidOn()); switch (subscription.getFrequency()) { case week: nextPaymentDue = nextPaymentDue.plusWeeks(1); break; case month: nextPaymentDue = nextPaymentDue.plusMonths(1); break; case year: nextPaymentDue = nextPaymentDue.plusYears(1); break; default: throw new IllegalArgumentException("Unsupported frequency: " + subscription.getFrequency()); } subscription.setNextPaymentDue(nextPaymentDue); subscriptionRepository.save(subscription); } return payment; }
From source file:com.google.android.apps.paco.NonESMSignalGenerator.java
License:Open Source License
private DateTime getNextScheduleDay(DateTime midnightTomorrow) { switch (schedule.getScheduleType()) { case SignalSchedule.DAILY: return nextRepeatDaily(midnightTomorrow); case SignalSchedule.WEEKDAY: int tomorrowDOW = midnightTomorrow.getDayOfWeek(); if (tomorrowDOW > DateTimeConstants.FRIDAY) { return midnightTomorrow.plusDays(8 - tomorrowDOW); } else {//from w w w .j ava2 s . c o m return midnightTomorrow; } case SignalSchedule.WEEKLY: int scheduleDays = schedule.getWeekDaysScheduled(); if (scheduleDays == 0) { return null; } for (int i = 0; i < 8; i++) { // go at least to the same day next week. int midnightTomorrowDOW = midnightTomorrow.getDayOfWeek(); Integer nowDowIndex = SignalSchedule.DAYS_OF_WEEK[midnightTomorrowDOW == 7 ? 0 : midnightTomorrowDOW]; // joda is 1 based & counts Monday as first day of the week so Sunday is 7 instead of 0. if ((scheduleDays & nowDowIndex) == nowDowIndex) { return nextRepeatWeekly(midnightTomorrow); } midnightTomorrow = midnightTomorrow.plusDays(1); } throw new IllegalStateException("Cannot get to here. Weekly must repeat at least once a week"); case SignalSchedule.MONTHLY: if (schedule.getByDayOfMonth()) { int midnightDOM = midnightTomorrow.getDayOfMonth(); int scheduledDOM = schedule.getDayOfMonth(); if (midnightDOM == scheduledDOM) { return midnightTomorrow; } else if (midnightDOM > scheduledDOM) { MutableDateTime mutableDateTime = midnightTomorrow.plusMonths(1).toMutableDateTime(); mutableDateTime.setDayOfMonth(scheduledDOM); return nextRepeatMonthly(mutableDateTime.toDateTime()); } else { return nextRepeatMonthly(midnightTomorrow.plusDays(scheduledDOM - midnightDOM)); } } else { Integer nthOfMonth = schedule.getNthOfMonth(); Integer dow = getDOWFromIndexedValue(); // only one selection, so take log2 to get index of dow DateMidnight nthDowDate = getNthDOWOfMonth(midnightTomorrow, nthOfMonth, dow).toDateMidnight(); DateTime returnDate = null; if (nthDowDate.equals(midnightTomorrow)) { returnDate = midnightTomorrow; } else if (nthDowDate.isAfter(midnightTomorrow)) { returnDate = nthDowDate.toDateTime(); } else { returnDate = getNthDOWOfMonth(midnightTomorrow.plusMonths(1), nthOfMonth, dow).toDateTime(); } return nextRepeatMonthly(returnDate); } default: throw new IllegalStateException("Schedule has an unknown type: " + schedule.getScheduleType()); } }
From source file:com.google.android.apps.paco.NonESMSignalGenerator.java
License:Open Source License
private DateTime nextRepeatMonthly(DateTime midnightTomorrow) { if (schedule.getRepeatRate() == 1) { return midnightTomorrow; }/*w w w . java2s. c o m*/ if (schedule.getByDayOfMonth()) { int distanceBetweenStartAndTomorrow = Months .monthsBetween(new DateTime(schedule.getBeginDate()).toDateMidnight(), midnightTomorrow) .getMonths(); if (distanceBetweenStartAndTomorrow == 0 || distanceBetweenStartAndTomorrow == schedule.getRepeatRate()) { if ((distanceBetweenStartAndTomorrow == 0 && midnightTomorrow .getDayOfMonth() <= new DateMidnight(schedule.getBeginDate()).getDayOfMonth())) { // we crossed a month boundary, so add one month. return midnightTomorrow.plusMonths(schedule.getRepeatRate() - 1); } return midnightTomorrow; } else if (distanceBetweenStartAndTomorrow > schedule.getRepeatRate()) { int remainder = distanceBetweenStartAndTomorrow % schedule.getRepeatRate(); return midnightTomorrow.plusMonths(schedule.getRepeatRate() - remainder); } else { return midnightTomorrow.plusMonths(schedule.getRepeatRate() - distanceBetweenStartAndTomorrow); } } else { int distanceBetweenStartAndTomorrow = Months .monthsBetween(new DateTime(schedule.getBeginDate()).toDateMidnight(), midnightTomorrow) .getMonths(); if (distanceBetweenStartAndTomorrow == 0 || distanceBetweenStartAndTomorrow == schedule.getRepeatRate()) { if ((distanceBetweenStartAndTomorrow == 0 && midnightTomorrow .getDayOfMonth() <= new DateMidnight(schedule.getBeginDate()).getDayOfMonth())) { // we crossed a month boundary, so add one month. return getNthDOWOfMonth(midnightTomorrow.plusMonths(schedule.getRepeatRate() - 1), schedule.getNthOfMonth(), getDOWFromIndexedValue()); } return midnightTomorrow; } else if (distanceBetweenStartAndTomorrow > schedule.getRepeatRate()) { int remainder = distanceBetweenStartAndTomorrow % schedule.getRepeatRate(); return getNthDOWOfMonth(midnightTomorrow.plusMonths(schedule.getRepeatRate() - remainder), schedule.getNthOfMonth(), getDOWFromIndexedValue()); } else { return getNthDOWOfMonth( midnightTomorrow.plusMonths(schedule.getRepeatRate() - distanceBetweenStartAndTomorrow), schedule.getNthOfMonth(), getDOWFromIndexedValue()); } } }
From source file:com.google.api.ads.adwords.awreporting.model.entities.dateranges.ThisMonthDateRangeHandler.java
License:Open Source License
@Override public DateTime retrieveDateEnd(DateTime date) { DateTime plusMonth = date.plusMonths(1); plusMonth = new DateTime(plusMonth.getYear(), plusMonth.getMonthOfYear(), 1, 12, 0); return plusMonth.minusDays(1); }
From source file:com.linagora.obm.ui.scenario.event.EventStepdefs.java
License:Open Source License
@Then("^event \"([^\"]*)\" appears every month at (\\d+)/(\\d+)/(\\d+) from (\\d+):(\\d+) to (\\d+):(\\d+)$") public void eventAppearsEveryMonth(String title, int day, int month, int year, int beginHour, int beginMin, int endHour, int endMin) { DateTime dateTimeDayOfMonth = dateTime(day, month, year, beginHour, beginMin); DateTime timelessDayOfMonth = timelessDateTime(day, month, year); String expectedEventDatesTitle = expectedEventDatesTitle(beginHour, beginMin, endHour, endMin); for (int numberOfChecksi = 0; numberOfChecksi < 5; numberOfChecksi++) { WebElement divElement = processedCalendarPage.getDivByTitle(title); assertThat(divElement.getAttribute("id")) .endsWith(String.valueOf(dateTimeDayOfMonth.getMillis() / 1000)); WebElement hrefElement = divElement.findElement(new ByCssSelector("a")); assertThat(hrefElement.getText()).isEqualTo(expectedEventDatesTitle); boolean found = false; dateTimeDayOfMonth = dateTimeDayOfMonth.plusMonths(1); timelessDayOfMonth = timelessDayOfMonth.plusMonths(1); for (int weekIterator = 0; weekIterator < 5; weekIterator++) { processedCalendarPage.calendarNavBarWidget().nextPage(); found = isDayOfMonthInPrintedWeek(timelessDayOfMonth); if (found) { break; }//from ww w. j a v a 2s . c om } assertThat(found).isTrue(); } }