Example usage for org.joda.time DateTime plusMonths

List of usage examples for org.joda.time DateTime plusMonths

Introduction

In this page you can find the example usage for org.joda.time DateTime plusMonths.

Prototype

public DateTime plusMonths(int months) 

Source Link

Document

Returns a copy of this datetime plus the specified number of months.

Usage

From source file:org.kuali.coeus.propdev.impl.budget.ProposalBudgetNumberOfMonthsServiceImpl.java

License:Open Source License

@Override
public double getNumberOfMonth(Date startDate, Date endDate) {
    if (startDate == null || endDate == null || startDate.after(endDate)) {
        return 0.00;
    }//from w ww  . ja va  2 s  .co  m

    final DateTime start = new DateTime(startDate);
    final DateTime end = new DateTime(endDate).plusDays(1);

    final int daysInMonthForEndDate = end.dayOfMonth().getMaximumValue();
    final int wholeMonths = Months.monthsBetween(start, end).getMonths();
    final int daysRemaining = Days.daysBetween(start.plusMonths(wholeMonths), end).getDays();

    //casting to ensure we don't loose precision
    final double numberOfMonths = wholeMonths + ((double) daysRemaining / (double) daysInMonthForEndDate);

    return new ScaleTwoDecimal(numberOfMonths).doubleValue();
}

From source file:org.kuali.kpme.core.calendar.entry.service.CalendarEntryServiceImpl.java

License:Educational Community License

private DateTime plusSemiMonth(DateTime date) {
    //so assuming the common pairs of this are the 1st & 16th, and then 15th and the last day,
    // and 14th with the last day minus 1
    //so we'll peek at the current date and try to figure out the best guesses for addition.
    if (date.getDayOfMonth() == date.dayOfMonth().getMaximumValue()) {
        //date is on the last day of the month.  Set next date to the 15th
        return date.plusMonths(1).withDayOfMonth(15);
    } else if (date.getDayOfMonth() == 15) {
        //we are on the 15th of the month, so now lets go to the end of the month
        return date.withDayOfMonth(date.dayOfMonth().getMaximumValue());
    } else if (date.getDayOfMonth() == 1) {
        //first of the month, next would be 16
        return date.withDayOfMonth(16);
    } else if (date.getDayOfMonth() == 16) {
        //16th, so add a month and set day to '1'
        return date.plusMonths(1).withDayOfMonth(1);
    } else if (date.getDayOfMonth() == 14) {
        //14th day, set next one to last day minus 1
        return date.withDayOfMonth(date.dayOfMonth().getMaximumValue() - 1);
    } else if (date.getDayOfMonth() == date.dayOfMonth().getMaximumValue() - 1) {
        //date is on the second to last day of the month.  Set next date to the 14th
        return date.plusMonths(1).withDayOfMonth(14);
    } else {/*from w w  w .j  a v a2s .com*/
        // so it isn't one of the common dates... i guess we'll just add 15 days...
        return date.plusDays(15);
    }
}

From source file:org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseOfferingServiceTestDataUtils.java

License:Educational Community License

public static AcademicCalendarInfo createAcademicCalendar(String calendarName, String plainName) {
    AcademicCalendarInfo orig = new AcademicCalendarInfo();
    orig.setName(calendarName);// ww w  .  j a  v a2s. c  o m
    orig.setDescr(new RichTextHelper().toRichTextInfo(plainName, "formatted " + plainName));
    orig.setTypeKey(AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY);
    orig.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
    DateTime start = new DateTime();
    orig.setStartDate(start.toDate());
    orig.setEndDate(start.plusMonths(4).toDate());
    orig.setAdminOrgId("testOrgId1");

    return orig;

}

From source file:org.medcada.android.db.DatabaseHandler.java

License:Open Source License

public List<Integer> getAverageGlucoseReadingsByMonth() {
    JodaTimeAndroid.init(mContext);/*from   w  w  w  . j  av  a 2s  .  c o  m*/

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<Integer> averageReadings = new ArrayList<Integer>();

    // The number of months is at least 1 since we do have average for the current week even if incomplete
    int monthsNumber = Months.monthsBetween(minDateTime, maxDateTime).getMonths() + 1;

    for (int i = 0; i < monthsNumber; i++) {
        newDateTime = currentDateTime.plusMonths(1);
        RealmResults<GlucoseReading> readings = realm.where(GlucoseReading.class)
                .between("created", currentDateTime.toDate(), newDateTime.toDate()).findAll();
        averageReadings.add(((int) readings.average("reading")));
        currentDateTime = newDateTime;
    }
    return averageReadings;
}

From source file:org.medcada.android.db.DatabaseHandler.java

License:Open Source License

public List<String> getGlucoseDatetimesByMonth() {
    JodaTimeAndroid.init(mContext);/* www  .ja  v a2  s  .  c  om*/

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<String> finalMonths = new ArrayList<String>();

    // The number of months is at least 1 because current month is incomplete
    int monthsNumber = Months.monthsBetween(minDateTime, maxDateTime).getMonths() + 1;

    DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    for (int i = 0; i < monthsNumber; i++) {
        newDateTime = currentDateTime.plusMonths(1);
        finalMonths.add(inputFormat.format(newDateTime.toDate()));
        currentDateTime = newDateTime;
    }
    return finalMonths;
}

From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithDOM.java

License:Open Source License

protected void getMeetingStartDate() {
    DateTime initialDate = this.createdDate.withDayOfMonth(this.dayNumber);
    if (initialDate.isBefore(this.createdDate)) {
        initialDate = initialDate.plusMonths(1);
    }//  w  ww.  j a va 2 s.  com
    this.startDate = initialDate;
}

From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithDOM.java

License:Open Source License

public void generateSchedule(int numberOfDates) {
    numberOfDates--;/*from  www .j a v a 2  s.c om*/
    getMeetingStartDate();
    fastForwardTillDisbursement();
    DateTime meetingScheduleDate = this.startDate;
    Date meetingDateInMifosFormat;
    for (int i = 0; i <= numberOfDates; i++) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        meetingDateInMifosFormat = getWorkingDay(meetingScheduleDate).toDate();
        this.scheduleList.add(formatter.format(meetingDateInMifosFormat));
        meetingScheduleDate = meetingScheduleDate.plusMonths(this.recAfter);
    }
}

From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithROD.java

License:Open Source License

protected void getMeetingStartDate() {
    sanitizeDays();/*from  w w  w .  j  a  va2  s .  c  o  m*/
    DateTime initialDate = this.createdDate;
    initialDate = initialDate.withDayOfMonth(1);
    initialDate = initialDate.plusWeeks((this.rankOfDays - 1));
    initialDate = initialDate.withDayOfWeek(this.days);
    if (initialDate.isBefore(this.createdDate) || initialDate.isEqual(this.createdDate)) {
        initialDate = initialDate.plusMonths(1);
        initialDate = initialDate.withDayOfMonth(1);
        initialDate = initialDate.plusWeeks((this.rankOfDays - 1));
        initialDate = initialDate.withDayOfWeek(this.days);
    }
    this.startDate = initialDate;
}

From source file:org.mifos.dmt.business.Meetings.schedule.MonthlyScheduleWithROD.java

License:Open Source License

public void generateSchedule(int numberOfDates) {
    numberOfDates--;/*from  w  ww .j  a  v  a 2s.co  m*/
    getMeetingStartDate();
    fastForwardTillDisbursement();
    DateTime meetingScheduleDate = this.startDate;
    Date meetingDateInMifosFormat;
    for (int i = 0; i <= numberOfDates; i++) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        meetingDateInMifosFormat = getWorkingDay(meetingScheduleDate).toDate();
        this.scheduleList.add(formatter.format(meetingDateInMifosFormat));
        meetingScheduleDate = meetingScheduleDate.plusMonths(this.recAfter);
        meetingScheduleDate = meetingScheduleDate.withDayOfMonth(1);
        meetingScheduleDate = meetingScheduleDate.plusWeeks((this.rankOfDays - 1));
        meetingScheduleDate = meetingScheduleDate.withDayOfWeek(this.days);
    }
}

From source file:org.mifos.platform.cashflow.service.CashFlowServiceImpl.java

License:Open Source License

@Override
public CashFlowDetail cashFlowFor(int startYear, int startMonth, double numberOfMonths) {
    DateTime startMonthYear = new DateTime(startYear, startMonth, 1, 1, 1, 1, 1);
    List<MonthlyCashFlowDetail> monthlyCashFlowDetails = new ArrayList<MonthlyCashFlowDetail>();
    for (int i = 0; i < numberOfMonths; i++) {
        monthlyCashFlowDetails.add(getMonthlyCashFlowDetail(startMonthYear));
        startMonthYear = startMonthYear.plusMonths(1);
    }// www.  ja v  a 2  s  . co m
    return new CashFlowDetail(monthlyCashFlowDetails);
}