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:Gui.panels.analyticsguipanels.CondencePanel.java

public boolean is_inside_period(DateTime startdate, DateTime testdate) {

    switch (condence_value) {
    case 1://from   ww  w  .j  a va  2s . c o  m
        return false;
    case 2:
        return startdate.plusDays(1).isAfter(testdate);
    case 3:
        return startdate.plusDays(7).isAfter(testdate);
    case 4:
        return startdate.plusMonths(1).isAfter(testdate);
    }
    return false;
}

From source file:influent.server.dataaccess.DataAccessHelper.java

License:MIT License

public static DateTime getExclusiveEndDate(FL_DateRange date) {

    if (date == null) {
        return null;
    }/*from   w w  w.  jav  a 2 s. com*/

    DateTime d = new DateTime((long) date.getStartDate(), DateTimeZone.UTC);

    switch (date.getDurationPerBin().getInterval()) {
    case SECONDS:
        return d.plusSeconds(date.getNumBins().intValue());
    case HOURS:
        return d.plusHours(date.getNumBins().intValue());
    case DAYS:
        return d.plusDays(date.getNumBins().intValue());
    case WEEKS:
        return d.plusWeeks(date.getNumBins().intValue());
    case MONTHS:
        return d.plusMonths(date.getNumBins().intValue());
    case QUARTERS:
        return d.plusMonths(date.getNumBins().intValue() * 3);
    case YEARS:
        return d.plusYears(date.getNumBins().intValue());
    }

    return d;
}

From source file:io.renren.common.utils.DateUtils.java

License:Apache License

/**
 * ?/?//  ww w . j  av a  2s . c  om
 *
 * @param date 
 * @param months ?
 * @return /??
 */
public static Date addDateMonths(Date date, int months) {
    DateTime dateTime = new DateTime(date);
    return dateTime.plusMonths(months).toDate();
}

From source file:io.terminus.snz.user.service.CompanyServiceImpl.java

private CompanyPerformance getCompanyPerformance(List<SupplierTQRDCInfo> supplierTQRDCInfos) {
    CompanyPerformance companyPerformance = new CompanyPerformance();
    if (supplierTQRDCInfos == null) {
        return companyPerformance;
    }/*  w w  w. j  a va  2  s .com*/

    List<Double> locations = Lists.newArrayListWithCapacity(12); //??
    List<Integer> modules = Lists.newArrayListWithCapacity(12); //?
    List<Integer> ranks = Lists.newArrayListWithCapacity(12); //??
    List<Integer> tScore = Lists.newArrayListWithCapacity(12); //?
    List<Integer> tRanks = Lists.newArrayListWithCapacity(12); //??
    List<Integer> qScore = Lists.newArrayListWithCapacity(12); //??
    List<Integer> qRanks = Lists.newArrayListWithCapacity(12); //???
    List<Integer> rScore = Lists.newArrayListWithCapacity(12); //??
    List<Integer> rRanks = Lists.newArrayListWithCapacity(12); //???
    List<Integer> dScore = Lists.newArrayListWithCapacity(12); //?
    List<Integer> dRanks = Lists.newArrayListWithCapacity(12); //??
    List<Integer> cScore = Lists.newArrayListWithCapacity(12); //??
    List<Integer> cRanks = Lists.newArrayListWithCapacity(12); //???

    //?(?????)
    SupplierTQRDCInfo lastMonth = supplierTQRDCInfos.get(supplierTQRDCInfos.size() - 1);
    lastMonth.shortComing(); //?
    companyPerformance.setSupplierTQRDCInfo(lastMonth);

    //????
    Integer redLocations = 0;
    DateTime month = MONTH_FORMAT.parseDateTime(DateUtil.getCurrentYearFirstMonth());

    for (int i = 1; i <= 12; i++) {

        boolean existed = false;
        for (SupplierTQRDCInfo supplierTQRDCInfo : supplierTQRDCInfos) {

            if (Objects.equal(supplierTQRDCInfo.getMonth(), MONTH_FORMAT.print(month))) {

                locations.add(getLocationValue(supplierTQRDCInfo.getLocation()));
                modules.add(supplierTQRDCInfo.getCompositeScore());
                ranks.add(supplierTQRDCInfo.getRank());
                tScore.add(supplierTQRDCInfo.getTechScore());
                tRanks.add(supplierTQRDCInfo.getTechScoreRank());
                qScore.add(supplierTQRDCInfo.getQualityScore());
                qRanks.add(supplierTQRDCInfo.getQualityScoreRank());
                rScore.add(supplierTQRDCInfo.getRespScore());
                rRanks.add(supplierTQRDCInfo.getRespScoreRank());
                dScore.add(supplierTQRDCInfo.getDeliverScore());
                dRanks.add(supplierTQRDCInfo.getDeliveryScoreRank());
                cScore.add(supplierTQRDCInfo.getCostScore());
                cRanks.add(supplierTQRDCInfo.getCostScoreRank());

                if (Objects.equal("", supplierTQRDCInfo.getLocation())) {
                    ++redLocations;
                }

                existed = true;
                break;
            }

        }

        //?null
        if (!existed) {
            locations.add(null);
            modules.add(null);
            ranks.add(null);
            tScore.add(null);
            tRanks.add(null);
            qScore.add(null);
            qRanks.add(null);
            rScore.add(null);
            rRanks.add(null);
            dScore.add(null);
            dRanks.add(null);
            cScore.add(null);
            cRanks.add(null);
        }

        month = month.plusMonths(1);

    }

    companyPerformance.setRedLocations(redLocations);
    companyPerformance.setLocations(locations);
    companyPerformance.setModules(modules);
    companyPerformance.modulesTrend(); //?
    companyPerformance.setRanks(ranks);
    companyPerformance.setT(tScore);
    companyPerformance.setTranks(tRanks);
    companyPerformance.setQ(qScore);
    companyPerformance.setQranks(qRanks);
    companyPerformance.setR(rScore);
    companyPerformance.setRranks(rRanks);
    companyPerformance.setD(dScore);
    companyPerformance.setDranks(dRanks);
    companyPerformance.setC(cScore);
    companyPerformance.setCranks(cRanks);

    companyPerformance.computeTQRDCTrend(); //tqrdc??

    SupplierModuleCount moduleCount = supplierModuleCountDao.findByModuleName(lastMonth.getModule());
    companyPerformance.setModuleCount(moduleCount);

    Integer count = supplierModuleDetailDao.countBySupplierCode(lastMonth.getSupplierCode());
    companyPerformance.setEliminated(count > 0);

    return companyPerformance;
}

From source file:io.warp10.script.functions.ADDMONTHS.java

License:Apache License

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {

    Object top = stack.pop();//from  w  ww.jav  a 2  s .c  o m

    if (!(top instanceof Long)) {
        throw new WarpScriptException(getName() + " expects a number of months on top of the stack.");
    }

    int months = ((Number) top).intValue();

    top = stack.pop();

    String tz = null;

    if (top instanceof String) {
        tz = top.toString();
        top = stack.pop();
        if (!(top instanceof Long)) {
            throw new WarpScriptException(
                    getName() + " operates on a tselements list, timestamp, or timestamp and timezone.");
        }
    } else if (!(top instanceof List) && !(top instanceof Long)) {
        throw new WarpScriptException(
                getName() + " operates on a tselements list, timestamp, or timestamp and timezone.");
    }

    if (top instanceof Long) {
        long instant = ((Number) top).longValue();

        if (null == tz) {
            tz = "UTC";
        }

        DateTimeZone dtz = DateTimeZone.forID(null == tz ? "UTC" : tz);

        DateTime dt = new DateTime(instant / Constants.TIME_UNITS_PER_MS, dtz);

        dt = dt.plusMonths(months);

        long ts = dt.getMillis() * Constants.TIME_UNITS_PER_MS + (instant % Constants.TIME_UNITS_PER_MS);

        stack.push(ts);
    } else {
        List<Object> elts = new ArrayList<Object>((List<Object>) top);

        int year = ((Number) elts.get(0)).intValue();
        int month = ((Number) elts.get(1)).intValue();

        if (months < 0) {
            while (months < 0) {
                months++;
                month = month - 1;
                if (month < 1) {
                    month = 12;
                    year--;
                }
            }
        } else {
            while (months > 0) {
                months--;
                month = month + 1;
                if (month > 12) {
                    month = 1;
                    year++;
                }
            }
        }

        elts.set(0, (long) year);
        elts.set(1, (long) month);

        // Now check that the month is compatible with the day

        if (elts.size() > 2) {
            int day = ((Number) elts.get(2)).intValue();

            if (2 == month && day > 28) {
                if ((0 != year % 4) || (0 == year % 100)) {
                    elts.set(2, (long) 28);
                } else {
                    elts.set(2, (long) 29);
                }
            } else if (day > 30 && (4 == month || 6 == month || 9 == month || 11 == month)) {
                elts.set(2, (long) 30);
            }
        }

        stack.push(elts);
    }

    return stack;
}

From source file:kr.debop4j.timeperiod.calendars.DateDiff.java

License:Apache License

private int calcMonths() {
    if (Objects.equal(start, end))
        return 0;

    int compareDay = Math.min(end.getDayOfMonth(),
            timeCalendar.getDaysInMonth(getStartYear(), getStartMonthOfYear()));
    DateTime compareDate = Times.asDate(getStartYear(), getStartMonthOfYear(), compareDay)
            .plusMillis(end.getMillisOfDay());

    // log.trace("compareDay=[{}], compareDate=[{}]", compareDay, compareDate);

    if (end.compareTo(start) > 0) {
        if (compareDate.compareTo(start) < 0)
            compareDate = compareDate.plusMonths(1);
    } else if (compareDate.compareTo(start) > 0) {
        compareDate = compareDate.plusMonths(-1);
    }//  w  w  w  . j  ava 2s  . co m

    int month = (getEndYear() * TimeSpec.MonthsPerYear + getEndMonthOfYear())
            - (timeCalendar.getYear(compareDate) * TimeSpec.MonthsPerYear
                    + timeCalendar.getMonthOfYear(compareDate));

    // log.trace("calc month=[{}]", month);

    return month;
}

From source file:kr.debop4j.timeperiod.timerange.HalfyearTimeRange.java

License:Apache License

/**
 * Gets months./*from   www  .j  a va2 s  .  c  o  m*/
 *
 * @return the months
 */
public List<MonthRange> getMonths() {
    DateTime startMonth = Times.asDate(getStartYear(), 1, 1);
    int monthCount = getHalfyearCount() * TimeSpec.MonthsPerHalfyear;

    List<MonthRange> months = Lists.newArrayListWithCapacity(monthCount);
    for (int m = 0; m < monthCount; m++) {
        months.add(new MonthRange(startMonth.plusMonths(m), getTimeCalendar()));
    }
    return months;
}

From source file:kr.debop4j.timeperiod.timerange.HalfyearTimeRange.java

License:Apache License

private static TimeRange getPeriodOf(int year, Halfyear halfyear, int halfyearCount) {
    assert halfyearCount > 0;

    DateTime yearStart = Times.startTimeOfYear(year);
    DateTime start = yearStart.plusMonths((halfyear.getValue() - 1) * TimeSpec.MonthsPerHalfyear);
    DateTime end = start.plusMonths(halfyearCount * TimeSpec.MonthsPerHalfyear);

    return new TimeRange(start, end);
}

From source file:kr.debop4j.timeperiod.timerange.MonthRangeCollection.java

License:Apache License

/**
 * Gets months./*from  w  w  w .j  a v  a2s.c om*/
 *
 * @return the months
 */
public List<MonthRange> getMonths() {
    DateTime startTime = this.getStart();
    List<MonthRange> months = Lists.newArrayListWithCapacity(getMonthCount());

    for (int m = 0; m < getMonthCount(); m++) {
        months.add(new MonthRange(startTime.plusMonths(m), getTimeCalendar()));
    }
    return months;
}

From source file:kr.debop4j.timeperiod.timerange.MonthTimeRange.java

License:Apache License

/**  (Month)? ? ? ({@link DayRange}) ? . */
public List<DayRange> getDays() {
    DateTime startMonth = Times.startTimeOfMonth(getStart());
    List<DayRange> days = Lists.newArrayListWithCapacity(monthCount * TimeSpec.MaxDaysPerMonth);

    for (int m = 0; m < monthCount; m++) {
        DateTime monthStart = startMonth.plusMonths(m);
        int daysOfMonth = Times.getDaysInMonth(monthStart.getYear(), monthStart.getMonthOfYear());
        for (int d = 0; d < daysOfMonth; d++) {
            days.add(new DayRange(monthStart.plusDays(d), getTimeCalendar()));
        }/*www.j  a v a  2s  .  c om*/
    }
    return days;
}