Example usage for org.joda.time LocalDate plusDays

List of usage examples for org.joda.time LocalDate plusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusDays.

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:at.jclehner.rxdroid.db.Drug.java

License:Open Source License

public LocalDate getNextScheduledDate(LocalDate reference) {
    if (repeatMode == REPEAT_DAILY)
        return reference;

    final int maxLoopDays;

    if (repeatMode == REPEAT_21_7)
        maxLoopDays = 28;/*w  ww  .  jav  a  2s.co  m*/
    else if (repeatMode == REPEAT_EVERY_N_DAYS)
        maxLoopDays = (int) repeatArg;
    else if (repeatMode == REPEAT_WEEKDAYS)
        maxLoopDays = 7;
    else
        throw new UnsupportedOperationException("repeatMode=" + repeatMode);

    for (int i = 0; i != maxLoopDays; ++i) {
        final LocalDate date = reference.plusDays(i);
        if (hasDoseOnDate(date.toDate()))
            return date;
    }

    return null;
}

From source file:at.jclehner.rxdroid.DrugEditFragment.java

License:Open Source License

private boolean fixInvalidRepeatOrigin(Drug drug, LocalDate reference) {
    if (reference == null)
        return false;

    final Date invalidRepeatOrigin = drug.getRepeatOrigin();

    for (int i = 0; i != 2; ++i) {
        final LocalDate date = reference.plusDays(i);
        if (drug.hasDoseOnDate(date.toDate())) {
            updateRepeatOrigin(drug, date);
            Log.i(TAG, "Updated invalid repeatOrigin: " + drug.getRepeatOrigin());
            return true;
        }/*www  . j  a  va  2 s.  c om*/
    }

    try {
        Reflect.setFieldValue(Drug.class.getDeclaredField("repeatOrigin"), drug, invalidRepeatOrigin);
    } catch (NoSuchFieldException e) {
        throw new WrappedCheckedException(e);
    }

    return false;
}

From source file:cache.BreakerCache.java

Vector<ElectricalValue> get_data(Breaker breaker, LocalDate startDate, LocalDate endDate, BaseCache cache)
        throws NoActiveDbConnectionException, NoItemSelectedException {
    Vector<ElectricalValue> toreturn = new Vector<>();
    LocalDate currdate = null;

    int cacheditems = 0;
    int totalitems = 0;

    currdate = new LocalDate(startDate);
    while (currdate.isBefore(endDate)) {

        YearCache wanted_year = null;//from  w  ww  . j  a v a2 s .  c om
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {

            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);

        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        if (wanted_day.data != null) {
            cacheditems++;
        }
        totalitems++;

        currdate = currdate.plusDays(1);
    }

    if (cacheditems / totalitems > 0.9) {

        currdate = new LocalDate(startDate);
        while (currdate.isBefore(endDate)) {

            YearCache wanted_year = null;
            for (YearCache yc : years) {
                if (yc.year == currdate.getYear()) {
                    wanted_year = yc;
                    break;
                }

            }
            if (wanted_year == null) {

                wanted_year = new YearCache(currdate.getYear());
                years.add(wanted_year);

            }

            MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
            DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

            cache.cache_day(wanted_day);
            if (wanted_day.data == null) {
                wanted_day.data = LoadDataFromDB.get_data(breaker, currdate, currdate.plusDays(1));
            }
            toreturn.addAll(wanted_day.data);
            currdate = currdate.plusDays(1);

        }
    } else {
        toreturn = LoadDataFromDB.get_data(breaker, startDate, endDate);

        currdate = new LocalDate(startDate);

        YearCache wanted_year = null;
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {
            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);
        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        currdate = currdate.plusDays(1);

        Vector<ElectricalValue> daydata = new Vector<>();
        for (int i = 0; i < toreturn.size(); i++) {
            if (toreturn.get(i).datetime.toLocalDate().isBefore(currdate)) {
                daydata.add(toreturn.get(i));

            } else {

                if (daydata.size() > 0) {
                    wanted_day.data = daydata;
                    cache.cache_day(wanted_day);
                    daydata = new Vector<>();
                }

                wanted_year = null;
                for (YearCache yc : years) {
                    if (yc.year == currdate.getYear()) {
                        wanted_year = yc;
                        break;
                    }

                }
                if (wanted_year == null) {
                    wanted_year = new YearCache(currdate.getYear());
                    years.add(wanted_year);
                }

                wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
                wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

                currdate = currdate.plusDays(1);

            }

        }

    }
    return toreturn;
}

From source file:cache.TransformerCache.java

Vector<ElectricalValue> get_data(Transformer transformer, LocalDate startDate, LocalDate endDate,
        BaseCache cache) throws NoActiveDbConnectionException, NoItemSelectedException {
    Vector<ElectricalValue> toreturn = new Vector<>();
    LocalDate currdate = null;

    int cacheditems = 0;
    int totalitems = 0;

    currdate = new LocalDate(startDate);
    while (currdate.isBefore(endDate)) {

        YearCache wanted_year = null;/*from w w w  . j a v  a 2 s  .c  o  m*/
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {

            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);

        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        if (wanted_day.data != null) {
            cacheditems++;
        }
        totalitems++;

        currdate = currdate.plusDays(1);
    }

    if (cacheditems / totalitems > 0.9) {

        currdate = new LocalDate(startDate);
        while (currdate.isBefore(endDate)) {

            YearCache wanted_year = null;
            for (YearCache yc : years) {
                if (yc.year == currdate.getYear()) {
                    wanted_year = yc;
                    break;
                }

            }
            if (wanted_year == null) {

                wanted_year = new YearCache(currdate.getYear());
                years.add(wanted_year);

            }

            MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
            DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

            cache.cache_day(wanted_day);
            if (wanted_day.data == null) {
                wanted_day.data = LoadDataFromDB.get_data(transformer, currdate, currdate.plusDays(1));
            }
            toreturn.addAll(wanted_day.data);
            currdate = currdate.plusDays(1);

        }
    } else {
        toreturn = LoadDataFromDB.get_data(transformer, startDate, endDate);

        currdate = new LocalDate(startDate);

        YearCache wanted_year = null;
        for (YearCache yc : years) {
            if (yc.year == currdate.getYear()) {
                wanted_year = yc;
                break;
            }

        }
        if (wanted_year == null) {
            wanted_year = new YearCache(currdate.getYear());
            years.add(wanted_year);
        }

        MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
        DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

        currdate = currdate.plusDays(1);

        Vector<ElectricalValue> daydata = new Vector<>();
        for (int i = 0; i < toreturn.size(); i++) {
            if (toreturn.get(i).datetime.toLocalDate().isBefore(currdate)) {
                daydata.add(toreturn.get(i));

            } else {

                if (daydata.size() > 0) {
                    wanted_day.data = daydata;
                    cache.cache_day(wanted_day);
                    daydata = new Vector<>();
                }

                wanted_year = null;
                for (YearCache yc : years) {
                    if (yc.year == currdate.getYear()) {
                        wanted_year = yc;
                        break;
                    }

                }
                if (wanted_year == null) {
                    wanted_year = new YearCache(currdate.getYear());
                    years.add(wanted_year);
                }

                wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1];
                wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1];

                currdate = currdate.plusDays(1);

            }

        }

    }
    return toreturn;
}

From source file:cherry.foundation.bizcal.SimpleWorkdayStore.java

License:Apache License

@Override
public LocalDate getNextWorkday(String name, LocalDate from, int numberOfWorkday) {
    return from.plusDays(numberOfWorkday - 1);
}

From source file:cherry.goods.util.LocalDateUtil.java

License:Apache License

/**
 * (TO)???//from   www . j a v a2s.  c  o  m
 * 
 * @param to ??
 * @return ????(TO)??
 */
public static LocalDate rangeTo(LocalDate to) {
    if (to == null) {
        return null;
    }
    return to.plusDays(1);
}

From source file:com.axelor.apps.account.service.debtrecovery.ReminderSessionService.java

License:Open Source License

/**
 * Session de relance//www .j a v  a2s . c o  m
 *
 * @param reminder
 *             Une relance
 * @throws AxelorException
 */
public Reminder reminderSession(Reminder reminder) throws AxelorException {

    log.debug("Begin ReminderActiveSession service...");

    LocalDate referenceDate = reminder.getReferenceDate();
    BigDecimal balanceDueReminder = reminder.getBalanceDueReminder();

    int reminderLevel = 0;
    if (reminder.getReminderMethodLine() != null
            && reminder.getReminderMethodLine().getReminderLevel().getName() != null) {
        reminderLevel = reminder.getReminderMethodLine().getReminderLevel().getName();
    }

    int theoricalReminderLevel;

    int levelMax = this.getMaxLevel(reminder);

    // Test inutile...  verifier
    if ((today.isAfter(referenceDate) || today.isEqual(referenceDate))
            && balanceDueReminder.compareTo(BigDecimal.ZERO) > 0) {
        log.debug(
                "Si la date actuelle est gale ou ultrieur  la date de rfrence et le solde due relanable positif");
        //Pour les client  haut risque vital, on passe directement du niveau de relance 2 au niveau de relance 4
        if (reminderLevel < levelMax) {
            log.debug("Sinon ce n'est pas un client  haut risque vital");
            theoricalReminderLevel = reminderLevel + 1;
        } else {
            log.debug("Sinon c'est un client  un haut risque vital");
            theoricalReminderLevel = levelMax;
        }

        ReminderMethodLine reminderMethodLine = this.getReminderMethodLine(reminder, theoricalReminderLevel);

        if ((!(referenceDate.plusDays(reminderMethodLine.getStandardDeadline())).isAfter(today))
                && balanceDueReminder.compareTo(reminderMethodLine.getMinThreshold()) > 0) {
            log.debug("Si le seuil du solde exigible relanable est respect et le dlai est respect");

            if (!reminderMethodLine.getManualValidationOk()) {
                log.debug("Si le niveau ne necessite pas de validation manuelle");
                reminder.setReminderMethodLine(reminderMethodLine); // Afin d'afficher la ligne de niveau sur le tiers
                reminder.setWaitReminderMethodLine(null);
                // et lancer les autres actions du niveau
            } else {
                log.debug("Si le niveau necessite une validation manuelle");
                reminder.setWaitReminderMethodLine(reminderMethodLine); // Si le passage est manuel
            }
        }

    } else {
        log.debug("Sinon on lance une rinitialisation");
        this.reminderInitialisation(reminder);
    }
    log.debug("End ReminderActiveSession service");
    return reminder;
}

From source file:com.axelor.apps.account.service.invoice.InvoiceToolService.java

License:Open Source License

public static LocalDate getDueDate(PaymentCondition paymentCondition, LocalDate invoiceDate) {

    switch (paymentCondition.getTypeSelect()) {
    case PaymentConditionRepository.TYPE_NET:

        return invoiceDate.plusDays(paymentCondition.getPaymentTime());

    case PaymentConditionRepository.TYPE_END_OF_MONTH_N_DAYS:

        return invoiceDate.dayOfMonth().withMaximumValue().plusDays(paymentCondition.getPaymentTime());

    case PaymentConditionRepository.TYPE_N_DAYS_END_OF_MONTH:

        return invoiceDate.plusDays(paymentCondition.getPaymentTime()).dayOfMonth().withMaximumValue();

    case PaymentConditionRepository.TYPE_N_DAYS_END_OF_MONTH_AT:

        return invoiceDate.plusDays(paymentCondition.getPaymentTime()).dayOfMonth().withMaximumValue()
                .plusDays(paymentCondition.getDaySelect());

    default:// ww  w.java 2 s.  c  o m
        return invoiceDate;
    }

}

From source file:com.axelor.apps.base.service.DurationServiceImpl.java

License:Open Source License

public LocalDate computeDuration(Duration duration, LocalDate date) {

    if (duration == null) {
        return date;
    }//from w w  w.  j a v a  2  s.  c om

    switch (duration.getTypeSelect()) {

    case DurationRepository.TYPE_MONTH:

        return date.plusMonths(duration.getValue());

    case DurationRepository.TYPE_DAY:

        return date.plusDays(duration.getValue());

    default:

        return date;
    }

}

From source file:com.axelor.apps.base.service.scheduler.SchedulerService.java

License:Open Source License

/**
 * Mthode qui dtermine la prochaine date d'xcution d'un planificateur pour un rythme quotidien
 *
 * @param scheduler// w  ww .java  2  s.  c o  m
 *       Instance de planificateur
 * @param date
 *       Derniere date d'xcution thorique
 *
 * @return LocalDate
 *       Prochaine date d'xcution
 */
private LocalDate getDailyComputeDate(Scheduler scheduler, LocalDate date) {

    return date.plusDays(scheduler.getDayDaily());
}