Example usage for org.joda.time LocalDate isBefore

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

Introduction

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

Prototype

public boolean isBefore(ReadablePartial partial) 

Source Link

Document

Is this partial earlier than the specified partial.

Usage

From source file:at.jclehner.rxdroid.preferences.DatePreference.java

License:Open Source License

@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    final LocalDate date = new LocalDate(year, monthOfYear + 1, dayOfMonth);
    mIsValidDate = !date.isBefore(mToday);

    if (mIsValidDate)
        mDate = date;/*from   w  w  w  .  ja  v  a2 s  . c o  m*/

    ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(mIsValidDate);
}

From source file:br.com.moonjava.flight.util.VerifierString.java

License:Apache License

public static boolean isBirthDay(String word, String country) {
    boolean birthDay = false;
    LocalDate date = FormatDateTimeDesk.parseToLocalDate(word, country);
    boolean leapYear = new GregorianCalendar().isLeapYear(date.getYear());
    LocalDate now = new LocalDate();

    // US MM/DD/YYYY
    if (country.equals("US")) {
        // No pode conter 30 e 31 em fevereiro e nem ser maior que a data atual
        if (!word.startsWith("02/30") && !word.startsWith("02/31") && date.isBefore(now) || date.isEqual(now)) {
            // Se for bissexto deve considerar 02/29
            if (word.startsWith("02/29") && leapYear || !word.startsWith("02/29")) {
                Pattern pattern = Pattern.compile("(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d)");
                Matcher matcher = pattern.matcher(word);
                birthDay = matcher.find();
            }/*from w  ww  .j av  a  2  s.  c o  m*/
        }

        // BR DD/MM/YYYY
    } else {
        if (!word.startsWith("30/02") && !word.startsWith("31/02") && date.isBefore(now) || date.isEqual(now)) {
            // No pode conter 30 e 31 em fevereiro e nem ser maior que a data atual
            if (word.startsWith("29/02") && leapYear || !word.startsWith("29/02")) {
                // Se for bissexto deve considerar 29/02
                Pattern pattern = Pattern.compile("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/((19|20)\\d\\d)");
                Matcher matcher = pattern.matcher(word);
                birthDay = matcher.find();
            }
        }
    }

    return birthDay;
}

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  ww w . jav  a2 s  .com
        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  . ja  v a  2s. 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(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:com.axelor.apps.account.service.BudgetService.java

License:Open Source License

public List<BudgetLine> updateLines(Budget budget) {
    if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) {
        for (BudgetLine budgetLine : budget.getBudgetLineList()) {
            budgetLine.setAmountRealized(BigDecimal.ZERO);
        }/*from  w  w  w .  j  a v  a 2  s  .c om*/
        List<BudgetDistribution> budgetDistributionList = Beans.get(BudgetDistributionRepository.class).all()
                .filter("self.budget.id = ?1 AND (self.invoiceLine.invoice.statusSelect = ?2 OR self.invoiceLine.invoice.statusSelect = ?3)",
                        budget.getId(), InvoiceRepository.STATUS_VALIDATED, InvoiceRepository.STATUS_VENTILATED)
                .fetch();
        for (BudgetDistribution budgetDistribution : budgetDistributionList) {
            LocalDate orderDate = budgetDistribution.getInvoiceLine().getInvoice().getInvoiceDate();
            if (orderDate != null) {
                for (BudgetLine budgetLine : budget.getBudgetLineList()) {
                    LocalDate fromDate = budgetLine.getFromDate();
                    LocalDate toDate = budgetLine.getToDate();
                    if ((fromDate.isBefore(orderDate) || fromDate.isEqual(orderDate))
                            && (toDate.isAfter(orderDate) || toDate.isEqual(orderDate))) {
                        budgetLine.setAmountRealized(
                                budgetLine.getAmountRealized().add(budgetDistribution.getAmount()));
                        break;
                    }
                }
            }
        }
    }
    return budget.getBudgetLineList();
}

From source file:com.axelor.apps.account.service.BudgetService.java

License:Open Source License

public List<BudgetLine> generatePeriods(Budget budget) {

    if (budget.getBudgetLineList() != null && !budget.getBudgetLineList().isEmpty()) {
        List<BudgetLine> budgetLineList = budget.getBudgetLineList();
        budgetLineList.clear();//www  .  jav  a 2 s.c  om
    }

    List<BudgetLine> budgetLineList = new ArrayList<BudgetLine>();
    Integer duration = budget.getPeriodDurationSelect();
    LocalDate fromDate = budget.getFromDate();
    LocalDate toDate = budget.getToDate();
    LocalDate budgetLineToDate = fromDate;
    Integer budgetLineNumber = 1;

    while (budgetLineToDate.isBefore(toDate)) {
        if (budgetLineNumber != 1)
            fromDate = fromDate.plusMonths(duration);
        budgetLineToDate = fromDate.plusMonths(duration).minusDays(1);
        if (budgetLineToDate.isAfter(toDate))
            budgetLineToDate = toDate;
        if (fromDate.isAfter(toDate))
            continue;
        BudgetLine budgetLine = new BudgetLine();
        budgetLine.setFromDate(fromDate);
        budgetLine.setToDate(budgetLineToDate);
        budgetLine.setBudget(budget);
        budgetLine.setAmountExpected(budget.getAmountForGeneration());
        budgetLineList.add(budgetLine);
        budgetLineNumber++;
    }
    return budgetLineList;
}

From source file:com.axelor.apps.account.service.PaymentScheduleService.java

License:Open Source License

public LocalDate getMostRecentDatePaymentScheduleLine(List<PaymentScheduleLine> paymentScheduleLineList) {
    LocalDate minPaymentScheduleLineDate = new LocalDate();

    if (paymentScheduleLineList != null && !paymentScheduleLineList.isEmpty()) {
        for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
            if (minPaymentScheduleLineDate.isBefore(paymentScheduleLine.getScheduleDate())) {
                minPaymentScheduleLineDate = paymentScheduleLine.getScheduleDate();
            }//  ww w  .  java  2  s  . c  o m
        }
    } else {
        minPaymentScheduleLineDate = null;
    }
    return minPaymentScheduleLineDate;
}

From source file:com.axelor.apps.account.service.YearService.java

License:Open Source License

public List<Period> generatePeriods(Year year) {

    List<Period> periods = new ArrayList<Period>();
    Integer duration = year.getPeriodDurationSelect();
    LocalDate fromDate = year.getFromDate();
    LocalDate toDate = year.getToDate();
    LocalDate periodToDate = fromDate;
    Integer periodNumber = 1;/*from  w  w  w. j  a va2 s  .c o m*/

    while (periodToDate.isBefore(toDate)) {
        if (periodNumber != 1)
            fromDate = fromDate.plusMonths(duration);
        periodToDate = fromDate.plusMonths(duration).minusDays(1);
        if (periodToDate.isAfter(toDate))
            periodToDate = toDate;
        if (fromDate.isAfter(toDate))
            continue;
        Period period = new Period();
        period.setFromDate(fromDate);
        period.setToDate(periodToDate);
        period.setYear(year);
        period.setName(String.format("%02d", periodNumber) + "/" + year.getCode());
        period.setCode(
                String.format("%02d", periodNumber) + "/" + year.getCode() + "_" + year.getCompany().getCode());
        period.setCompany(year.getCompany());
        period.setStatusSelect(year.getStatusSelect());
        periods.add(period);
        periodNumber++;
    }
    return periods;
}

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

License:Open Source License

/**
 * Mthode qui dtermine si une instance de planificateur peut etre lanc
 *
 * @param schedulerI//  w w w .java  2  s  . com
 *       Instance de planificateur
 *
 * @return boolean
 *       True si il est temps de lancer, sinon False
 *
 * @throws AxelorException
 */
public boolean isSchedulerInstanceIsReady(SchedulerInstance schedulerI) throws AxelorException {

    LocalDate firstExecution = schedulerI.getFirstExecutionDate();
    LocalDate lastTheoreticalExecution = schedulerI.getLastTheoreticalExecutionDate();

    //Si date de dmarrage egal ou suprieur  date du jour
    if (lastTheoreticalExecution == null) {
        LOG.debug("Date de dernire excution absente");
        if (firstExecution == null) {
            LOG.debug(String.format("Date de premiere executon absente"));
        } else if (firstExecution.equals(today) || firstExecution.isBefore(today)) {
            LOG.debug("Date de dmarrage suprieur ou gal a date du jour");
            return true;
        } else {
            LOG.debug(String.format("La facturation ne peux pas encore tre excut : %s < %s", today,
                    firstExecution));
        }
    } else {
        //Sinon calcul le cycle
        return this.processScheduler(schedulerI);
    }

    return false;
}

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

License:Open Source License

/**
 * Mthode qui dtermine si une instance de planificateur peut etre lanc
 *
 * @param schedulerI/*from w w w .jav a  2 s  . c  o m*/
 *       Instance de planificateur
 *
 * @return boolean
 *       True si il est temps de lancer, sinon False
 *
 * @throws AxelorException
 */
private boolean processScheduler(SchedulerInstance schedulerI) throws AxelorException {

    LocalDate date = this.getComputeDate(schedulerI);

    LOG.debug("Date dernire xcution thorique: " + schedulerI.getLastTheoreticalExecutionDate());
    LOG.debug("Date calcul : " + date);
    LOG.debug("Date du jour : " + today);

    if (date != null && (date.equals(today) || date.isBefore(today)))
        return true;

    return false;
}