Example usage for org.joda.time DateTime minusMonths

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

Introduction

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

Prototype

public DateTime minusMonths(int months) 

Source Link

Document

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

Usage

From source file:org.elasticsearch.xpack.monitoring.cleaner.AbstractIndicesCleanerTestCase.java

License:Open Source License

protected static TimeValue months(int months) {
    DateTime now = now();
    return TimeValue.timeValueMillis(now.getMillis() - now.minusMonths(months).getMillis());
}

From source file:org.encuestame.business.service.StreamService.java

License:Apache License

/**
 * Classify notifications by {@link DateClasificatedEnum}.
 * @throws EnMeNoResultsFoundException//from www.  j a v  a2  s  .  c  o m
 */
public HashMap<DateClasificatedEnum, List<UtilNotification>> classifyNotificationList(
        final List<UtilNotification> utilNotifications, final HttpServletRequest request)
        throws EnMeNoResultsFoundException {
    final HashMap<DateClasificatedEnum, List<UtilNotification>> response = new HashMap<DateClasificatedEnum, List<UtilNotification>>();
    // today notification
    final List<Notification> todayNotifications = filterByDate(DateUtil.getTodayStartDate(),
            DateUtil.getNextDayMidnightDate());
    // this week (minus today)
    DateTime thisWeek = new DateTime(DateUtil.getTodayStartDate());
    thisWeek = thisWeek.minusMinutes(1);
    Date finalThisWeek = thisWeek.minusWeeks(1).toDate();
    final List<Notification> thisWeekList = filterByDate(finalThisWeek, thisWeek.toDate());
    // this months notifications
    final DateTime finalThisWeekMinusOne = new DateTime(finalThisWeek).minusMinutes(1);
    final DateTime finalThisMonth = finalThisWeekMinusOne.minusWeeks(3);
    final List<Notification> thisMonth = filterByDate(finalThisMonth.toDate(), finalThisWeekMinusOne.toDate());
    // last months notifications
    final DateTime lastMontFinal = finalThisMonth.minusMinutes(1);
    final DateTime lastMontInit = lastMontFinal.minusDays(DateClasificatedEnum.THIS_MONTH.toNumber());
    final List<Notification> lastMonth = filterByDate(lastMontInit.toDate(), lastMontFinal.toDate());
    // few months ago
    final DateTime lastFewMontFinal = lastMontInit.minusMinutes(1);
    final DateTime lastFewMontInit = lastFewMontFinal.minusMonths(4); // 4 months, 4 + (1) last + 1 (current) = 6
    final List<Notification> fewMonth = filterByDate(lastFewMontInit.toDate(), lastFewMontFinal.toDate());
    // last year
    final DateTime lastYearFinal = lastFewMontInit.minusMinutes(1);
    final DateMidnight lastYeaInit = new DateMidnight(lastYearFinal).withWeekOfWeekyear(1).withDayOfWeek(1);
    final List<Notification> lastYear = filterByDate(lastYeaInit.toDate(), lastYearFinal.toDate());
    // long time ago
    final DateTime longTimeFinal = new DateTime(lastYeaInit).minusMinutes(1);
    final DateMidnight longTimeInit = new DateMidnight(longTimeFinal).minusYears(3).withWeekOfWeekyear(1)
            .withDayOfWeek(1);
    final List<Notification> longtime = filterByDate(longTimeInit.toDate(), longTimeFinal.toDate());
    response.put(DateClasificatedEnum.TODAY, convertNotificationList(todayNotifications, request));
    response.put(DateClasificatedEnum.THIS_WEEK, convertNotificationList(thisWeekList, request));
    response.put(DateClasificatedEnum.THIS_MONTH, convertNotificationList(thisMonth, request));
    response.put(DateClasificatedEnum.LAST_MONTH, convertNotificationList(lastMonth, request));
    response.put(DateClasificatedEnum.FEW_MONTHS_AGO, convertNotificationList(fewMonth, request));
    response.put(DateClasificatedEnum.LAST_YEAR, convertNotificationList(lastYear, request));
    response.put(DateClasificatedEnum.LONG_TIME_AGO, convertNotificationList(longtime, request));
    return response;
}

From source file:org.everit.jira.reporting.plugin.web.JiraTimetrackerWorklogsWebAction.java

License:Apache License

/**
 * Set dateFrom and dateFromFormated default value.
 *///from   w ww.j a v a 2  s  . com
private void dateFromDefaultInit() {
    DateTime date = new DateTime(TimetrackerUtil.getLoggedUserTimeZone());
    date = date.minusMonths(1);
    dateFromFormated = DateTimeConverterUtil.convertDateTimeToDate(date).getTime();
}

From source file:org.itechkenya.leavemanager.domain.Contract.java

License:Open Source License

public List<PreviouslyCompletedPeriod> calculatePreviouslyCompletedPeriod() {

    List<PreviouslyCompletedPeriod> previousCompletedPeriods = new ArrayList<>();

    DateTime today = new DateTime(new Date());
    DateTime contractStartDate = new DateTime(this.getStartDate());

    SimpleDateFormat monthSdf = new SimpleDateFormat("yyyyMM");
    SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy");

    DateTime earnDateTime;//from www . ja v a  2  s  .c o m
    DateTime recordDateTime;
    Date date;

    if (today.getDayOfMonth() >= contractStartDate.getDayOfMonth()) {
        earnDateTime = today.minusMonths(1);
    } else {
        earnDateTime = today.minusMonths(2);
    }
    recordDateTime = earnDateTime.plusMonths(1);
    date = DateTimeUtil.createDate(recordDateTime.getYear(), recordDateTime.getMonthOfYear(),
            contractStartDate.getDayOfMonth());
    previousCompletedPeriods
            .add(new PreviouslyCompletedPeriod(monthSdf.format(earnDateTime.toDate()), date, PeriodType.MONTH));

    int contractYearCount = this.calculateContractYear();
    if (contractYearCount > 1) {
        int previousContractYear = this.calculatePreviousContractYear(contractYearCount);

        Date recordDate = DateTimeUtil.createDate(previousContractYear + 1, contractStartDate.getMonthOfYear(),
                contractStartDate.getDayOfMonth());

        previousCompletedPeriods.add(new PreviouslyCompletedPeriod(String.valueOf(previousContractYear),
                recordDate, PeriodType.YEAR));
    }
    return previousCompletedPeriods;
}

From source file:org.killbill.billing.subscription.alignment.BaseAligner.java

License:Apache License

private DateTime addOrRemoveDuration(final DateTime input, final Duration duration, boolean add) {
    DateTime result = input;
    switch (duration.getUnit()) {
    case DAYS:/* www  . java  2s  . c om*/
        result = add ? result.plusDays(duration.getNumber()) : result.minusDays(duration.getNumber());
        ;
        break;

    case MONTHS:
        result = add ? result.plusMonths(duration.getNumber()) : result.minusMonths(duration.getNumber());
        break;

    case YEARS:
        result = add ? result.plusYears(duration.getNumber()) : result.minusYears(duration.getNumber());
        break;
    case UNLIMITED:
    default:
        throw new RuntimeException("Trying to move to unlimited time period");
    }
    return result;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public DateTime getPreviousAccrualIntervalDate(String earnInterval, DateTime aDate) {
    DateTime previousAccrualIntervalDate = null;

    if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) {
        previousAccrualIntervalDate = aDate.minusDays(1);
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) {
        previousAccrualIntervalDate = aDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SATURDAY);
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) {
        previousAccrualIntervalDate = aDate.minusDays(15);
        if (previousAccrualIntervalDate.getDayOfMonth() <= 15) {
            previousAccrualIntervalDate = previousAccrualIntervalDate.withDayOfMonth(15);
        } else {/*from   ww  w .j  ava 2 s .  com*/
            previousAccrualIntervalDate = previousAccrualIntervalDate
                    .withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue());
        }
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) {
        previousAccrualIntervalDate = aDate.minusMonths(1);
        previousAccrualIntervalDate = previousAccrualIntervalDate
                .withDayOfMonth(previousAccrualIntervalDate.dayOfMonth().getMaximumValue());
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) {
        previousAccrualIntervalDate = aDate.minusYears(1);
        previousAccrualIntervalDate = previousAccrualIntervalDate
                .withDayOfYear(previousAccrualIntervalDate.dayOfYear().getMaximumValue());
    } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) {
        previousAccrualIntervalDate = aDate;
    }

    return previousAccrualIntervalDate;
}

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

License:Open Source License

@Override
public CashFlowBoundary getCashFlowBoundary(DateTime firstInstallmentDueDate, DateTime lastInstallmentDueDate) {
    DateTime monthAfterLastInstallment = lastInstallmentDueDate
            .plusMonths(EXTRA_DURATION_FOR_CASH_FLOW_SCHEDULE).withDayOfMonth(FIRST_DAY);
    DateTime monthBeforeFirstInstallment = firstInstallmentDueDate
            .minusMonths(EXTRA_DURATION_FOR_CASH_FLOW_SCHEDULE).withDayOfMonth(FIRST_DAY);
    int numberOfMonths = Months.monthsBetween(monthBeforeFirstInstallment, monthAfterLastInstallment)
            .getMonths() + 1;//w w  w .j  av a2s . c  o m
    return new CashFlowBoundary(monthBeforeFirstInstallment.getMonthOfYear(),
            monthBeforeFirstInstallment.getYear(), numberOfMonths);
}

From source file:org.n52.io.PreRenderingJob.java

License:Open Source License

public IntervalWithTimeZone createTimespanFromInterval(String timeseriesId, String period) {
    DateTime now = new DateTime();
    if (period.equals("lastDay")) {
        Interval interval = new Interval(now.minusDays(1), now);
        return new IntervalWithTimeZone(interval.toString());
    } else if (period.equals("lastWeek")) {
        Interval interval = new Interval(now.minusWeeks(1), now);
        return new IntervalWithTimeZone(interval.toString());
    } else if (period.equals("lastMonth")) {
        Interval interval = new Interval(now.minusMonths(1), now);
        return new IntervalWithTimeZone(interval.toString());
    } else {/*from w  w  w.  ja va 2  s . c  o m*/
        throw new ResourceNotFoundException(
                "Unknown interval definition '" + period + "' for timeseriesId " + timeseriesId);
    }
}

From source file:org.n52.io.PreRenderingTask.java

License:Open Source License

public Interval createTimespanFromInterval(String timeseriesId, String interval) {
    DateTime now = new DateTime();
    if (interval.equals("lastDay")) {
        return new Interval(now.minusDays(1), now);
    } else if (interval.equals("lastWeek")) {
        return new Interval(now.minusWeeks(1), now);
    } else if (interval.equals("lastMonth")) {
        return new Interval(now.minusMonths(1), now);
    } else {/* w  w  w.  j  a va  2 s . co m*/
        throw new ResourceNotFoundException(
                "Unknown interval definition '" + interval + "' for timeseriesId " + timeseriesId);
    }
}

From source file:org.obm.push.bean.FilterType.java

License:Open Source License

public Date getFilteredDate(Date fromDate) {
    DateTime fromUTCDate = new DateTime(fromDate).withZone(DateTimeZone.UTC);
    switch (this) {
    case ALL_ITEMS:
        return DateUtils.getEpochPlusOneSecondCalendar().getTime();
    case ONE_DAY_BACK:
        return fromUTCDate.minusDays(1).toDate();
    case THREE_DAYS_BACK:
        return fromUTCDate.minusDays(3).toDate();
    case ONE_WEEK_BACK:
        return fromUTCDate.minusWeeks(1).toDate();
    case TWO_WEEKS_BACK:
        return fromUTCDate.minusWeeks(2).toDate();
    case ONE_MONTHS_BACK:
        return fromUTCDate.minusMonths(1).toDate();
    case THREE_MONTHS_BACK:
        return fromUTCDate.minusMonths(3).toDate();
    case SIX_MONTHS_BACK:
        return fromUTCDate.minusMonths(6).toDate();
    case FILTER_BY_NO_INCOMPLETE_TASKS:
        return fromDate;
    }//from   w ww .jav  a2s . c  om
    throw new IllegalStateException("No filtered date available");
}