Example usage for org.joda.time LocalDate isAfter

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

Introduction

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

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

From source file:net.sourceforge.fenixedu.domain.phd.debts.PhdGratuityPaymentPeriod.java

License:Open Source License

public Money fine(double fineRate, Money amount, DateTime when) {
    LocalDate whenPaying = new LocalDate(when.getYear(), when.monthOfYear().get(), when.dayOfMonth().get());
    LocalDate lastPaymentDay = new LocalDate(when.getYear(), getMonthLastPayment(), getDayLastPayment());

    if (whenPaying.isAfter(lastPaymentDay)) {
        int monthsOut = when.getMonthOfYear() - lastPaymentDay.getMonthOfYear();

        // if is in the same month, and a day has passed, at least it
        // counts for one month
        if (monthsOut == 0) {
            monthsOut = 1;/*from w  ww.  j a  v  a 2 s.c om*/
        }
        return new Money(amount.getAmount().multiply(new BigDecimal(fineRate * monthsOut)));
    } else {
        return new Money(0);
    }
}

From source file:net.sourceforge.fenixedu.domain.phd.migration.common.ConversionUtilities.java

License:Open Source License

static public LocalDate parseDate(String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    }/*from w  ww  .j  a  v  a 2s.  co  m*/

    if (value.length() < 2) {
        return null;
    }

    LocalDate result = null;
    String normalizedValue = value;

    if (value.length() == "dMMyyyy".length()) {
        normalizedValue = "0".concat(value);
    }

    for (String pattern : CORRECT_DATE_PATTERNS) {
        try {
            result = DateTimeFormat.forPattern(pattern).parseDateTime(normalizedValue).toLocalDate();
        } catch (IllegalArgumentException e) {
            continue;
        }

        if (result.isAfter(DateTimeFormat.forPattern("yyyy").parseDateTime("1920").toLocalDate())
                && result.isBefore(DateTimeFormat.forPattern("yyy").parseDateTime("2020").toLocalDate())) {
            return result;
        }
    }

    throw new IncorrectDateFormatException(value);
}

From source file:net.sourceforge.fenixedu.domain.phd.PhdProgramCalendarUtil.java

License:Open Source License

static public int countWorkDaysBetween(final LocalDate startDate, final LocalDate endDate) {

    int result = 0;
    LocalDate current = startDate.plusDays(1);

    while (!current.isAfter(endDate)) {
        if (isWorkDay(current)) {
            result++;/*from w  ww .j a  v  a2 s.  c om*/
        }

        current = current.plusDays(1);
    }

    return result;
}

From source file:net.sourceforge.fenixedu.domain.student.SeparationCyclesManagement.java

License:Open Source License

private void markOldRegistrationWithConcludedState(final StudentCurricularPlan oldStudentCurricularPlan) {
    if (oldStudentCurricularPlan.getRegistration().hasState(RegistrationStateType.CONCLUDED)) {
        return;/*  w w w  .  j ava2s.  c o m*/
    }

    LocalDate stateDate = new LocalDate();
    if (stateDate.isAfter(getExecutionYear().getEndDateYearMonthDay())) {
        stateDate = getExecutionYear().getEndDateYearMonthDay().toLocalDate();
    }

    final RegistrationState state = RegistrationStateCreator.createState(
            oldStudentCurricularPlan.getRegistration(), null, stateDate.toDateTimeAtStartOfDay(),
            RegistrationStateType.CONCLUDED);
    state.setResponsiblePerson(null);
}

From source file:net.sourceforge.fenixedu.domain.TutorshipSummary.java

License:Open Source License

public boolean isActive() {
    if (getSemester().getTutorshipSummaryPeriod() == null) {
        return false;
    }//ww w .  j a  v  a  2  s .  c o m

    LocalDate curDate = new LocalDate();
    LocalDate beginDate = getSemester().getTutorshipSummaryPeriod().getBeginDate();
    LocalDate endDate = getSemester().getTutorshipSummaryPeriod().getEndDate();

    return !(curDate.isBefore(beginDate) || curDate.isAfter(endDate));
}

From source file:op.tools.SYSCalendar.java

License:Open Source License

public static void handleDateFocusLost(FocusEvent evt, LocalDate min, LocalDate max) {
    LocalDate dt;
    if (max == null) {
        max = new LocalDate();
    }//from  w  ww .  j  a  va  2s.  co m
    try {
        dt = new LocalDate(parseDate(((JTextField) evt.getSource()).getText()));
    } catch (NumberFormatException ex) {
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.wrongdate")));
        dt = new LocalDate();
    }
    if (dt.isAfter(max)) {
        dt = new LocalDate();
        DisplayMessage dm = new DisplayMessage(
                dt.isAfter(max) ? SYSTools.xx("misc.msg.futuredate") : SYSTools.xx("misc.msg.wrongdate"));
        OPDE.getDisplayManager().addSubMessage(dm);
    }
    if (dt.isBefore(min)) {
        dt = new LocalDate();
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("misc.msg.DateTooOld")));
    }

    ((JTextField) evt.getSource()).setText(DateFormat.getDateInstance().format(dt.toDate()));
}

From source file:org.alexlg.bankit.controllers.AccountController.java

License:Open Source License

/**
 * Display operations list for history and future.
 * @param model Model to fill with operations list
 * @return view name/*w ww  .  j av  a 2s  . c  o m*/
 */
@RequestMapping("/list")
@Transactional(readOnly = true)
public String list(@RequestParam(required = false) String startDate,
        @RequestParam(required = false) String endDate, ModelMap model) {

    //start/end date of operations displayed
    LocalDate startDay = null;
    LocalDate endDay = null;
    boolean buildFuture = false;

    //parse dates if present
    if (startDate != null)
        startDay = parseMonth(startDate);
    if (endDate != null)
        endDay = parseMonth(endDate);

    //select start/end day from parsing or default
    if (startDay == null)
        startDay = calculateFirstHistoDay();
    if (endDay == null) {
        endDay = new LocalDate();
        buildFuture = true;
    } else {
        //select the last day of the endMonth
        endDay = endDay.dayOfMonth().withMaximumValue();

        //force endDay to not go beyond today
        LocalDate today = new LocalDate();
        if (endDay.isAfter(today)) {
            endDay = today;
            buildFuture = true;
        }
    }

    //switch start/end if not in correct order
    if (startDay.isAfter(endDay)) {
        LocalDate tmp = endDay;
        endDay = startDay;
        startDay = tmp;
    }

    //getting history operations
    List<Operation> ops = operationDao.getHistory(startDay, endDay);

    //calculating balance for history
    //current balance
    BigDecimal current = operationDao.getBalanceHistory(startDay);
    //difference between planned and real
    BigDecimal currentDiff = new BigDecimal("0");
    //balance for planned op but not debited
    BigDecimal plannedWaiting = new BigDecimal("0");

    //checking if a balance exists or init the account
    if (current == null && ops.size() == 0) {
        return "redirect:/account/init";
    }

    if (current == null)
        current = new BigDecimal("0");
    BigDecimal initialBalance = current;

    //calculating total for old operations
    for (Operation op : ops) {
        BigDecimal amount = op.getAmount();
        BigDecimal planned = op.getPlanned();

        if (amount != null) {
            //operation done
            current = current.add(amount);
            op.setTotal(current);
            if (planned != null) {
                currentDiff = currentDiff.add(amount).subtract(planned);
            }
        }
    }

    //calculating total for planned undebit operations
    for (Operation op : ops) {
        if (op.getAmount() == null) {
            plannedWaiting = plannedWaiting.add(op.getPlanned());
            op.setTotal(current.add(plannedWaiting));
        }
    }

    if (buildFuture) {
        //getting future operations
        Set<MonthOps> futureOps = buildFutureOps(endDay, operationDao.getFuture(endDay), costDao.getList(),
                current.add(plannedWaiting), NB_FUTURE_MONTH);

        model.put("futureOps", futureOps);
    }

    model.put("startDay", startDay.toDate());
    model.put("endDay", endDay.toDate());
    model.put("ops", ops);
    model.put("current", current);
    model.put("currentDiff", currentDiff);
    model.put("periodBalance", current.subtract(initialBalance));
    model.put("plannedWaiting", plannedWaiting);
    model.put("currentWaiting", current.add(plannedWaiting));
    model.put("lastSyncDate", optionsService.getDate(SyncService.OP_SYNC_OPT));
    model.put("categories", categoryDao.getList());
    //get categories summary (for previous and current month)
    model.put("categoriesSummary", buildCategories(startDay, endDay));

    return "account/list";
}

From source file:org.alexlg.bankit.controllers.AccountController.java

License:Open Source License

/**
 * Build a set of MonthOps for all future ops : "manual" or costs (beyond 2 days of current)
 * @param day Current day/*from  w  w  w.java 2  s  .  c  om*/
 * @param futurePlannedOps List of manual future operations
 * @param costs List of costs
 * @param balance Start balance
 * @param nbMonth Number of month to build in addition to the current month.
 * @return A set of MonthOps for each month planned
 */
protected Set<MonthOps> buildFutureOps(LocalDate day, List<Operation> futurePlannedOps, List<Cost> costs,
        BigDecimal balance, int nbMonth) {

    Set<MonthOps> futureOps = new TreeSet<MonthOps>();
    //going through all months
    for (int i = 0; i < nbMonth + 1; i++) {
        LocalDate monthDate = day.monthOfYear().addToCopy(i);
        int lastDayOfMonth = monthDate.dayOfMonth().getMaximumValue();

        MonthOps monthOps = new MonthOps(monthDate, balance);
        futureOps.add(monthOps);

        //adding "manual" operation of the current month
        if (futurePlannedOps.size() > 0) {
            //loop an add all operation of the month
            for (Operation op : futurePlannedOps) {
                if (new LocalDate(op.getOperationDate()).getMonthOfYear() == monthDate.getMonthOfYear()) {
                    op.setAuto(false);
                    monthOps.addOp(op);
                }
            }
        }

        //adding costs of the current month
        LocalDate costStartDay = day.plusDays(2);
        for (Cost cost : costs) {
            int costDay = cost.getDay();

            //if the operation is planned after the last day of month
            //set it to the last day
            if (costDay > lastDayOfMonth)
                costDay = lastDayOfMonth;

            LocalDate opDate = new LocalDate(monthDate.getYear(), monthDate.getMonthOfYear(), costDay);
            //checking if we add the cost (the date is after current+2)
            if (opDate.isAfter(costStartDay)) {
                Operation op = new Operation();
                //setting a fake id for comparison (as we put the operation in the set)
                op.setOperationId(cost.getCostId() + i);
                op.setOperationDate(opDate.toDate());
                op.setPlanned(cost.getAmount());
                op.setLabel(cost.getLabel());
                op.setCategory(cost.getCategory());
                op.setAuto(true);
                monthOps.addOp(op);
            }
        }

        //saving current balance for next monthOp
        balance = monthOps.getBalance();
    }
    return futureOps;
}

From source file:org.alexlg.bankit.services.SyncService.java

License:Open Source License

/**
 * This function take all the costs between
 * the last execution to create the associated
 * operations in the operation list./*from www.j  a  va2  s  .  c  om*/
 * It runs every day at midnight and 5 seconds
 */
@Transactional
@Scheduled(cron = "5 0 0 * * *")
public void materializeCostsIntoOperation() {
    logger.info("Starting materializeCostsIntoOperation");

    //materialize operations 2 days beyond current date
    LocalDate endDate = getEndSyncDate().plusDays(2);

    Date startSync = optionsService.getDate(COST_SYNC_OPT);
    if (startSync == null) {
        optionsService.set(COST_SYNC_OPT, endDate.toDate());
        return;
    }
    LocalDate startDate = new LocalDate(startSync);

    //retrieve costs list
    List<Cost> costs = null;
    int nbMonth = 1;

    if (endDate.getYear() == startDate.getYear() && endDate.getMonthOfYear() == startDate.getMonthOfYear()) {
        //only retrieve the costs between this 2 "days"
        costs = costDao.getList(startDate.getDayOfMonth(), endDate.getDayOfMonth());
    } else {
        //getting all costs
        costs = costDao.getList();

        //we generate a least for the current month (as nbMonth = 1)
        //then we add whole months between start and end.
        nbMonth += Months.monthsBetween(startDate, endDate).getMonths();

        //as monthsBetween calculate for whole month, if start is for example the 24-09
        //and the end is the 02-10, monthsBetween will return 0 but we need to have
        //2 loops, one for september and one for november so we add a month.
        if (endDate.getDayOfMonth() <= startDate.getDayOfMonth()) {
            nbMonth++;
        }
    }

    //going through each month and each cost to create the operation
    for (int m = 0; m < nbMonth; m++) {
        LocalDate curMonth = startDate.plusMonths(m);
        int lastDayOfMonth = curMonth.dayOfMonth().getMaximumValue();

        for (Cost cost : costs) {
            int costDay = cost.getDay();

            //if the operation is planned after the last day of month
            //set it to the last day
            if (costDay > lastDayOfMonth)
                costDay = lastDayOfMonth;

            //creating operation date
            LocalDate opDate = new LocalDate(curMonth.getYear(), curMonth.getMonthOfYear(), costDay);

            //check if date is in the date interval before creating op
            if (opDate.isAfter(startDate) && opDate.compareTo(endDate) <= 0) {
                Operation op = new Operation();
                op.setOperationDate(opDate.toDate());
                op.setLabel(cost.getLabel());
                op.setPlanned(cost.getAmount());
                op.setCategory(cost.getCategory());
                operationDao.save(op);
            }
        }
    }

    optionsService.set(COST_SYNC_OPT, endDate.toDate());

}

From source file:org.alexlg.bankit.services.SyncService.java

License:Open Source License

/**
 * Sync a list of operation with current ones.
 * @param operations Operations to sync.
 *///from w  w  w.  j  ava2 s.com
public void syncOpList(List<Operation> operations) {
    if (operations == null)
        return;
    Date start = optionsService.getDate(OP_SYNC_OPT);
    LocalDate startSync = start == null ? null : LocalDate.fromDateFields(start);
    LocalDate maxDate = null; //older operation date

    for (Operation op : operations) {
        LocalDate opDate = LocalDate.fromDateFields(op.getOperationDate());

        if (startSync == null || opDate.isAfter(startSync)) {
            operationDao.insert(op);

            //checking if operation if after maxDate
            if (maxDate == null || opDate.isAfter(maxDate))
                maxDate = opDate;
        }
    }

    //setting last execution
    if (maxDate != null)
        optionsService.set(OP_SYNC_OPT, maxDate.toDate());
}