Example usage for org.joda.time LocalDate getYear

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

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

From source file:org.fenixedu.academic.domain.reports.RaidesPhdReportFile.java

License:Open Source License

@Override
public void renderReport(Spreadsheet spreadsheet) throws Exception {

    ExecutionYear executionYear = getExecutionYear();
    int civilYear = executionYear.getBeginCivilYear();
    fillSpreadsheet(spreadsheet);/*from   w w w  .j  av  a 2 s.  c o m*/

    logger.info("BEGIN report for " + getDegreeType().getName().getContent());

    List<PhdIndividualProgramProcess> retrieveProcesses = retrieveProcesses(executionYear);

    for (PhdIndividualProgramProcess phdIndividualProgramProcess : retrieveProcesses) {
        if (phdIndividualProgramProcess.isConcluded()) {
            LocalDate conclusionDate = phdIndividualProgramProcess.getThesisProcess().getConclusionDate();

            if (conclusionDate == null
                    || (conclusionDate.getYear() != civilYear && conclusionDate.getYear() != civilYear - 1
                            && conclusionDate.getYear() != civilYear + 1)) {
                continue;
            }
        }
        if (phdIndividualProgramProcess.isConcluded() || phdIndividualProgramProcess.getHasStartedStudies()) {

            reportRaidesGraduate(spreadsheet, phdIndividualProgramProcess, executionYear);
        }
    }
}

From source file:org.fenixedu.treasury.domain.tariff.InterestRate.java

License:Open Source License

public InterestRateBean calculateInterest(final Map<LocalDate, BigDecimal> amountInDebtMap,
        final Map<LocalDate, BigDecimal> createdInterestEntries, final LocalDate dueDate,
        final LocalDate paymentDate) {

    TreeMap<LocalDate, BigDecimal> sortedMap = new TreeMap<LocalDate, BigDecimal>();
    sortedMap.putAll(amountInDebtMap);//from w  w  w .  j a v a2 s  .co m

    if (getInterestType().isGlobalRate()
            && !GlobalInterestRate.findUniqueByYear(dueDate.getYear()).get().isApplyPaymentMonth()) {
        final LocalDate lastDayForInterestCalculation = paymentDate.withField(DateTimeFieldType.dayOfMonth(), 1)
                .minusDays(1);

        for (final LocalDate localDate : Sets.newTreeSet(sortedMap.keySet())) {
            if (localDate.isAfter(lastDayForInterestCalculation)) {
                sortedMap.remove(localDate);
            }
        }

        sortedMap.put(lastDayForInterestCalculation, BigDecimal.ZERO);
    } else {
        sortedMap.put(paymentDate, BigDecimal.ZERO);
    }

    sortedMap = splitDatesWithYearsSpan(sortedMap);

    if (getInterestType().isFixedAmount()) {
        return calculedForFixedAmount();
    }

    if (getInterestType().isDaily() || getInterestType().isGlobalRate()) {
        return calculateDaily(createdInterestEntries, dueDate, paymentDate, sortedMap);
    }

    if (getInterestType().isMonthly()) {
        return calculateMonthly(createdInterestEntries, dueDate, paymentDate, sortedMap);
    }

    throw new RuntimeException("unknown interest type formula");
}

From source file:org.fenixedu.treasury.domain.tariff.InterestRate.java

License:Open Source License

private TreeMap<LocalDate, BigDecimal> splitDatesWithYearsSpan(final TreeMap<LocalDate, BigDecimal> sortedMap) {

    final TreeMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
    LocalDate startDate = null;

    for (final Entry<LocalDate, BigDecimal> entry : sortedMap.entrySet()) {
        if (startDate == null) {
            result.put(entry.getKey(), entry.getValue());
            startDate = entry.getKey();//from   w ww . j  av  a  2  s .  com
            continue;
        }

        if (startDate.getYear() == entry.getKey().getYear()) {
            result.put(entry.getKey(), entry.getValue());
            startDate = entry.getKey();
            continue;
        }

        if (startDate.getYear() == entry.getKey().getYear() - 1) {
            result.put(entry.getKey(), entry.getValue());
            startDate = entry.getKey();
            continue;
        }

        for (LocalDate a = startDate.plusYears(1), b = entry.getKey(); a.getYear() < b.getYear();) {
            result.put(Constants.firstDayInYear(a.getYear()), sortedMap.get(startDate));
            a = a.plusYears(1);
        }

        result.put(entry.getKey(), entry.getValue());
        startDate = entry.getKey();
    }

    return result;
}

From source file:org.fenixedu.treasury.domain.tariff.InterestRate.java

License:Open Source License

private InterestRateBean calculateDaily(final Map<LocalDate, BigDecimal> createdInterestEntries,
        final LocalDate dueDate, final LocalDate paymentDate, final TreeMap<LocalDate, BigDecimal> sortedMap) {
    final InterestRateBean result = new InterestRateBean(getInterestType());

    BigDecimal totalInterestAmount = BigDecimal.ZERO;
    int totalOfDays = 0;

    LocalDate startDate = applyOnFirstWorkdayIfNecessary(
            dueDate.plusDays(numberOfDaysAfterDueDate(dueDate.getYear())));

    // Iterate over amountInDebtMap and calculate amountToPay
    BigDecimal amountInDebt = BigDecimal.ZERO;
    for (final Entry<LocalDate, BigDecimal> entry : sortedMap.entrySet()) {

        if (entry.getKey().isAfter(paymentDate)) {
            break;
        }//from www .j a v a 2  s .  c om

        if (entry.getKey().isBefore(startDate)) {
            amountInDebt = entry.getValue();
            continue;
        }

        final LocalDate endDate = entry.getKey();

        int numberOfDays = 0;
        BigDecimal partialInterestAmount;
        if (startDate.getYear() != endDate.getYear()) {
            boolean reachedMaxDays = false;

            int firstYearDays = Days.daysBetween(startDate, Constants.lastDayInYear(startDate.getYear()))
                    .getDays() + 1;
            int secondYearDays = Days.daysBetween(Constants.firstDayInYear(endDate.getYear()), endDate)
                    .getDays() + 1;

            {
                if (isMaximumDaysToApplyPenaltyApplied()
                        && totalOfDays + firstYearDays >= getMaximumDaysToApplyPenalty()) {
                    firstYearDays = getMaximumDaysToApplyPenalty() - totalOfDays;
                    reachedMaxDays = true;
                }

                final BigDecimal amountPerDay = Constants.divide(amountInDebt,
                        new BigDecimal(Constants.numberOfDaysInYear(startDate.getYear())));

                final BigDecimal rate = interestRate(startDate.getYear());

                partialInterestAmount = Constants.divide(rate, Constants.HUNDRED_PERCENT).multiply(amountPerDay)
                        .multiply(new BigDecimal(firstYearDays));

                numberOfDays += firstYearDays;

                if (Constants.isPositive(partialInterestAmount)) {
                    result.addDetail(partialInterestAmount, startDate,
                            Constants.lastDayInYear(startDate.getYear()), amountPerDay, amountInDebt);
                }
            }

            if (!reachedMaxDays) {

                if (isMaximumDaysToApplyPenaltyApplied()
                        && totalOfDays + firstYearDays + secondYearDays >= getMaximumDaysToApplyPenalty()) {
                    secondYearDays = getMaximumDaysToApplyPenalty() - totalOfDays - firstYearDays;
                }

                final BigDecimal amountPerDay = Constants.divide(amountInDebt,
                        new BigDecimal(Constants.numberOfDaysInYear(endDate.getYear())));

                final BigDecimal rate = interestRate(endDate.getYear());

                final BigDecimal secondInterestAmount = Constants.divide(rate, Constants.HUNDRED_PERCENT)
                        .multiply(amountPerDay).multiply(new BigDecimal(secondYearDays));

                if (Constants.isPositive(partialInterestAmount)) {
                    result.addDetail(secondInterestAmount, Constants.firstDayInYear(endDate.getYear()), endDate,
                            amountPerDay, amountInDebt);
                }

                partialInterestAmount = partialInterestAmount.add(secondInterestAmount);

                numberOfDays += secondYearDays;
            }

        } else {
            numberOfDays = Days.daysBetween(startDate, endDate).getDays() + 1;

            if (isMaximumDaysToApplyPenaltyApplied()
                    && totalOfDays + numberOfDays >= getMaximumDaysToApplyPenalty()) {
                numberOfDays = getMaximumDaysToApplyPenalty() - totalOfDays;
            }

            final BigDecimal amountPerDay = Constants.divide(amountInDebt,
                    new BigDecimal(Constants.numberOfDaysInYear(startDate.getYear())));

            final BigDecimal rate = interestRate(startDate.getYear());
            partialInterestAmount = Constants.divide(rate, Constants.HUNDRED_PERCENT).multiply(amountPerDay)
                    .multiply(new BigDecimal(numberOfDays));

            if (Constants.isPositive(partialInterestAmount)) {
                result.addDetail(partialInterestAmount, startDate, endDate, amountPerDay, amountInDebt);
            }
        }

        totalInterestAmount = totalInterestAmount.add(partialInterestAmount);
        totalOfDays += numberOfDays;

        amountInDebt = entry.getValue();
        startDate = endDate.plusDays(1);

        if (isMaximumDaysToApplyPenaltyApplied() && totalOfDays >= getMaximumDaysToApplyPenalty()) {
            break;
        }
    }

    if (createdInterestEntries != null) {
        final TreeMap<LocalDate, BigDecimal> interestSortedMap = new TreeMap<LocalDate, BigDecimal>();
        interestSortedMap.putAll(createdInterestEntries);

        for (final Entry<LocalDate, BigDecimal> entry : createdInterestEntries.entrySet()) {
            result.addCreatedInterestEntry(entry.getKey(), entry.getValue());

            totalInterestAmount = totalInterestAmount.subtract(entry.getValue());
        }
    }

    result.setInterestAmount(getRelatedCurrency().getValueWithScale(totalInterestAmount));
    result.setNumberOfDays(totalOfDays);

    return result;
}

From source file:org.fenixedu.ulisboa.specifications.ui.firstTimeCandidacy.OriginInformationFormController.java

License:Open Source License

/**
 * @see {@link com.qubit.qubEdu.module.candidacies.domain.academicCandidacy.config.screen.validation.LastCompletedQualificationScreenValidator.validate(WorkflowInstanceState,
 *      WorkflowScreen)}//from w w  w.  j  a  va  2s.  com
 */
protected boolean validate(final Registration registration, final OriginInformationForm form,
        final Model model) {

    /* -------
     * COUNTRY
     * -------
     */

    if (form.getCountryWhereFinishedPreviousCompleteDegree() == null) {
        addErrorMessage(BundleUtil.getString(BUNDLE, "error.personalInformation.requiredCountry"), model);
        return false;
    }

    /* ------------------------
     * DISTRICT AND SUBDIVISION
     * ------------------------
     */

    if (form.getCountryWhereFinishedPreviousCompleteDegree().isDefaultCountry()
            && isDistrictAndSubdivisionRequired()) {
        if (form.getDistrictSubdivisionWhereFinishedPreviousCompleteDegree() == null
                || form.getDistrictWhereFinishedPreviousCompleteDegree() == null) {
            addErrorMessage(
                    BundleUtil.getString(BUNDLE,
                            "error.personalInformation.requiredDistrictAndSubdivisionForDefaultCountry"),
                    model);
            return false;
        }
    }

    /* ------------
     * SCHOOL LEVEL
     * ------------
     */

    if (form.getSchoolLevel() == null) {
        addErrorMessage(BundleUtil.getString(BUNDLE,
                "error.candidacy.workflow.OriginInformationForm.schoolLevel.must.be.filled"), model);
        return false;
    }

    if (form.getSchoolLevel() == SchoolLevelType.OTHER && StringUtils.isEmpty(form.getOtherSchoolLevel())) {
        addErrorMessage(
                BundleUtil.getString(BUNDLE,
                        "error.candidacy.workflow.OriginInformationForm.otherSchoolLevel.must.be.filled"),
                model);
        return false;
    }

    /* -----------
     * INSTITUTION
     * -----------
     */

    if (isInstitutionAndDegreeRequiredWhenNotDefaultCountryOrNotHigherLevel()) {
        if (StringUtils.isEmpty(StringUtils.trim(form.getInstitutionOid()))) {
            addErrorMessage(
                    BundleUtil.getString(BUNDLE,
                            "error.candidacy.workflow.OriginInformationForm.institution.must.be.filled"),
                    model);
            return false;
        }
    } else {
        if (form.getCountryWhereFinishedPreviousCompleteDegree().isDefaultCountry()
                && form.getSchoolLevel().isHigherEducation()) {
            if (StringUtils.isEmpty(StringUtils.trim(form.getInstitutionOid()))) {
                addErrorMessage(
                        BundleUtil.getString(BUNDLE,
                                "error.candidacy.workflow.OriginInformationForm.institution.must.be.filled"),
                        model);
                return false;
            }
        }
    }

    /* ------------------
     * DEGREE DESIGNATION
     * ------------------
     */

    if (form.getCountryWhereFinishedPreviousCompleteDegree() != null
            && form.getCountryWhereFinishedPreviousCompleteDegree().isDefaultCountry()
            && form.getSchoolLevel().isHigherEducation()) {
        if (form.getRaidesDegreeDesignation() == null) {
            addErrorMessage(BundleUtil.getString(BUNDLE, "error.degreeDesignation.required"), model);
            return false;
        }
    } else {
        if (isInstitutionAndDegreeRequiredWhenNotDefaultCountryOrNotHigherLevel()) {
            if (StringUtils.isEmpty(form.getDegreeDesignation())) {
                addErrorMessage(BundleUtil.getString(BUNDLE, "error.degreeDesignation.required"), model);
                return false;
            }
        }
    }

    /* ----------------
     * CONCLUSION GRADE
     * ----------------
     */

    if (!StringUtils.isEmpty(form.getConclusionGrade()) && !form.getConclusionGrade().matches(GRADE_FORMAT)) {
        addErrorMessage(BundleUtil.getString(BUNDLE, "error.incorrect.conclusionGrade"), model);
        return false;
    }

    /* ---------------
     * CONCLUSION YEAR
     * ---------------
     */

    if (form.getConclusionYear() == null || !form.getConclusionYear().toString().matches(YEAR_FORMAT)) {
        addErrorMessage(BundleUtil.getString(BUNDLE, "error.incorrect.conclusionYear"), model);
        return false;
    }

    LocalDate now = new LocalDate();
    if (now.getYear() < form.getConclusionYear()) {
        addErrorMessage(BundleUtil.getString(BUNDLE, "error.personalInformation.year.after.current"), model);
        return false;
    }

    int birthYear = registration.getPerson().getDateOfBirthYearMonthDay().getYear();
    if (form.getConclusionYear() < birthYear) {
        addErrorMessage(BundleUtil.getString(BUNDLE, "error.personalInformation.year.before.birthday"), model);
        return false;
    }

    if (form.getSchoolLevel().isHighSchoolOrEquivalent()) {
        if (form.getHighSchoolType() == null) {
            addErrorMessage(BundleUtil.getString(BUNDLE, "error.highSchoolType.required"), model);
            return false;
        }
    }

    return true;
}

From source file:org.fornax.cartridges.sculptor.framework.richclient.databinding.JodaLocalDateObservableValue.java

License:Apache License

private void setLocalDateSelection(LocalDate date) {
    if (date == null) {
        // TODO how to handle null
        date = new LocalDate();
    }/*from  ww  w .j  av a 2s.c  om*/
    dateTime.setYear(date.getYear());
    dateTime.setMonth(date.getMonthOfYear() - 1);
    dateTime.setDay(date.getDayOfMonth());
}

From source file:org.gnucash.android.ui.transaction.TransactionsActivity.java

License:Apache License

/**
 * Formats the date to show the the day of the week if the {@code dateMillis} is within 7 days
 * of today. Else it shows the actual date formatted as short string. <br>
 * It also shows "today", "yesterday" or "tomorrow" if the date is on any of those days
 * @param dateMillis//from  w w w .java  2s. co m
 * @return
 */
@NonNull
public static String getPrettyDateFormat(Context context, long dateMillis) {
    LocalDate transactionTime = new LocalDate(dateMillis);
    LocalDate today = new LocalDate();
    String prettyDateText = null;
    if (transactionTime.compareTo(today.minusDays(1)) >= 0
            && transactionTime.compareTo(today.plusDays(1)) <= 0) {
        prettyDateText = DateUtils
                .getRelativeTimeSpanString(dateMillis, System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS)
                .toString();
    } else if (transactionTime.getYear() == today.getYear()) {
        prettyDateText = mDayMonthDateFormat.format(new Date(dateMillis));
    } else {
        prettyDateText = DateUtils.formatDateTime(context, dateMillis,
                DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_YEAR);
    }

    return prettyDateText;
}

From source file:org.goobi.production.model.bibliography.course.CourseToGerman.java

License:Open Source License

/**
 * The method appendManyDates() converts a lot of date objects into readable
 * text in German language.//from   ww w.ja v  a  2 s . co  m
 *
 * @param buffer
 *            StringBuilder to write to
 * @param dates
 *            Set of dates to convert to text
 * @param signum
 *            sign, i.e. true for additions, false for exclusions
 * @throws NoSuchElementException
 *             if dates has no elements
 * @throws NullPointerException
 *             if buffer or dates is null
 */
private static void appendManyDates(StringBuilder buffer, Set<LocalDate> dates, boolean signum) {
    if (signum) {
        buffer.append("zustzlich ");
    } else {
        buffer.append("nicht ");
    }

    TreeSet<LocalDate> orderedDates = dates instanceof TreeSet ? (TreeSet<LocalDate>) dates
            : new TreeSet<>(dates);

    Iterator<LocalDate> datesIterator = orderedDates.iterator();

    LocalDate current = datesIterator.next();
    LocalDate next = datesIterator.hasNext() ? datesIterator.next() : null;
    LocalDate overNext = datesIterator.hasNext() ? datesIterator.next() : null;
    int previousYear = Integer.MIN_VALUE;
    boolean nextInSameMonth = false;
    boolean nextBothInSameMonth = next != null && DateUtils.sameMonth(current, next);
    int lastMonthOfYear = DateUtils.lastMonthForYear(orderedDates, current.getYear());

    do {
        nextInSameMonth = nextBothInSameMonth;
        nextBothInSameMonth = DateUtils.sameMonth(next, overNext);

        if (previousYear != current.getYear()) {
            buffer.append("am ");
        }

        buffer.append(current.getDayOfMonth());
        buffer.append('.');

        if (!nextInSameMonth) {
            buffer.append(' ');
            buffer.append(MONTH_NAMES[current.getMonthOfYear()]);
        }

        if (!DateUtils.sameYear(current, next)) {
            buffer.append(' ');
            buffer.append(current.getYear());
            if (next != null) {
                if (!DateUtils.sameYear(next, orderedDates.last())) {
                    buffer.append(", ");
                } else {
                    buffer.append(" und ebenfalls ");
                    if (!signum) {
                        buffer.append("nicht ");
                    }
                }
            }
            if (next != null) {
                lastMonthOfYear = DateUtils.lastMonthForYear(orderedDates, next.getYear());
            }
        } else if (next != null) {
            if (nextInSameMonth && nextBothInSameMonth
                    || !nextInSameMonth && next.getMonthOfYear() != lastMonthOfYear) {
                buffer.append(", ");
            } else {
                buffer.append(" und ");
            }
        }

        previousYear = current.getYear();
        current = next;
        next = overNext;
        overNext = datesIterator.hasNext() ? datesIterator.next() : null;
    } while (current != null);
}

From source file:org.goobi.production.model.bibliography.course.CourseToGerman.java

License:Open Source License

/**
 * The method appendDate() writes a date to the buffer.
 *
 * @param buffer//from  ww w .j a  va2  s  .  co m
 *            Buffer to write to
 * @param date
 *            Date to write
 */
private static void appendDate(StringBuilder buffer, LocalDate date) {
    buffer.append(date.getDayOfMonth());
    buffer.append(". ");
    buffer.append(MONTH_NAMES[date.getMonthOfYear()]);
    buffer.append(' ');
    buffer.append(date.getYear());
    return;
}

From source file:org.gravidence.gravifon.util.DateTimeUtils.java

License:Open Source License

/**
 * Converts local date object to array of date fields.<p>
 * Resulting array content is as follows: <code>[yyyy,MM,dd]</code>.
 * /*from   www  .  j  ava  2 s  .c o  m*/
 * @param value date object
 * @return array of date fields
 */
public static int[] localDateToArray(LocalDate value) {
    int[] result;

    if (value == null) {
        result = null;
    } else {
        result = new int[3];

        result[0] = value.getYear();
        result[1] = value.getMonthOfYear();
        result[2] = value.getDayOfMonth();
    }

    return result;
}