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.alexlg.bankit.controllers.AccountController.java

License:Open Source License

/**
 * Build categories summary for each month from startDate
 * to previous nbPrevMonth/*from   w ww.j  av a  2 s  . co m*/
 * @param startDate Start the summary for this month
 * @param endDate Stop the summary for this month
 * @return Map with the date of the month and a Map with Category
 *          and amount for this category for this month
 */
protected Map<Date, Map<Category, BigDecimal>> buildCategories(LocalDate startDate, LocalDate endDate) {
    Map<Date, Map<Category, BigDecimal>> categories = new LinkedHashMap<Date, Map<Category, BigDecimal>>();

    YearMonth curMonth = null; //month we start to retrieve
    YearMonth endMonth = null; //last month we have to retrieve
    if (startDate.isBefore(endDate)) {
        curMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear());
        endMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear());
    } else {
        curMonth = new YearMonth(endDate.getYear(), endDate.getMonthOfYear());
        endMonth = new YearMonth(startDate.getYear(), startDate.getMonthOfYear());
    }

    do {
        Map<Category, BigDecimal> monthSummary = categoryDao.getMonthSummary(curMonth);
        if (monthSummary.size() > 0) {
            categories.put(curMonth.toLocalDate(1).toDate(), monthSummary);
        }
        curMonth = curMonth.plusMonths(1);
    } while (curMonth.isBefore(endMonth) || curMonth.isEqual(endMonth));

    return categories;
}

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./*w  w w. j  av  a  2s  . 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.apache.fineract.portfolio.savings.domain.SavingsHelper.java

License:Apache License

private LocalDate determineInterestPostingPeriodEndDateFrom(final LocalDate periodStartDate,
        final SavingsPostingInterestPeriodType interestPostingPeriodType,
        final LocalDate interestPostingUpToDate, Integer financialYearBeginningMonth) {

    LocalDate periodEndDate = interestPostingUpToDate;
    final Integer monthOfYear = periodStartDate.getMonthOfYear();
    financialYearBeginningMonth--;//from  w  w  w.j a  v a2s  . c om
    if (financialYearBeginningMonth == 0)
        financialYearBeginningMonth = 12;

    final ArrayList<LocalDate> quarterlyDates = new ArrayList<>();
    quarterlyDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(3)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(9)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(quarterlyDates);

    final ArrayList<LocalDate> biannualDates = new ArrayList<>();
    biannualDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    biannualDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(biannualDates);

    boolean isEndDateSet = false;

    switch (interestPostingPeriodType) {
    case INVALID:
        break;
    case MONTHLY:
        // produce period end date on last day of current month
        periodEndDate = periodStartDate.dayOfMonth().withMaximumValue();
        break;
    case QUATERLY:
        for (LocalDate quarterlyDate : quarterlyDates) {
            if (quarterlyDate.isAfter(periodStartDate)) {
                periodEndDate = quarterlyDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = quarterlyDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case BIANNUAL:
        for (LocalDate biannualDate : biannualDates) {
            if (biannualDate.isAfter(periodStartDate)) {
                periodEndDate = biannualDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = biannualDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case ANNUAL:
        if (financialYearBeginningMonth < monthOfYear) {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
            periodEndDate = periodEndDate.plusYears(1);
        } else {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
        }
        periodEndDate = periodEndDate.dayOfMonth().withMaximumValue();
        break;
    }

    // interest posting always occurs on next day after the period end date.
    periodEndDate = periodEndDate.plusDays(1);

    return periodEndDate;
}

From source file:org.apache.isis.applib.fixturescripts.clock.ClockFixture.java

License:Apache License

@Override
protected void execute(ExecutionContext ec) {

    // can only be used in the context of integration tests
    if (!(Clock.getInstance() instanceof FixtureClock)) {
        throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
    }/*from  w  w  w .  j  av  a2  s  .com*/
    final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();

    // check that some value has been set
    checkParam("date", ec, String.class);

    // process if can be parsed as a LocalDateTime
    LocalDateTime ldt = parseAsLocalDateTime(date);
    if (ldt != null) {
        fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
        fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
        return;
    }

    // else process if can be parsed as a LocalDate
    LocalDate ld = parseAsLocalDate(date);
    if (ld != null) {
        fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
        return;
    }

    // else
    throw new IllegalArgumentException(
            String.format("'%s' could not be parsed as a local date/time or local date", date));
}

From source file:org.apache.isis.applib.fixturescripts.clock.TickingClockFixture.java

License:Apache License

private void setTo(final String date) {

    if (!(Clock.getInstance() instanceof FixtureClock)) {
        throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
    }//from  ww  w. ja  va  2 s.c o  m
    final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();

    // process if can be parsed as a LocalDateTime
    LocalDateTime ldt = parseAsLocalDateTime(date);
    if (ldt != null) {
        fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
        fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
        return;
    }

    // else process if can be parsed as a LocalDate
    LocalDate ld = parseAsLocalDate(date);
    if (ld != null) {
        fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
        return;
    }

    // else
    throw new IllegalArgumentException(
            String.format("'%s' could not be parsed as a local date/time or local date", date));

}

From source file:org.apache.isis.core.runtime.headless.HeadlessAbstract.java

License:Apache License

/**
 * To use instead of {@link #getFixtureClock()}'s {@link FixtureClock#setDate(int, int, int)} ()}.
 *//*from ww w  . j a v a  2  s.  c  o m*/
protected void setFixtureClockDate(final LocalDate date) {
    if (date == null) {
        return;
    }
    setFixtureClockDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
}

From source file:org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateXMLGregorianCalendarAdapter.java

License:Apache License

public static XMLGregorianCalendar print(final LocalDate dateTime) {
    if (dateTime == null)
        return null;

    final XMLGregorianCalendarImpl xgc = new XMLGregorianCalendarImpl();
    xgc.setYear(dateTime.getYear());
    xgc.setMonth(dateTime.getMonthOfYear());
    xgc.setDay(dateTime.getDayOfMonth());

    return xgc;//from   ww  w.j a  va  2s  .  c o  m
}

From source file:org.apache.isis.schema.utils.jaxbadapters.XmlCalendarFactory.java

License:Apache License

public static XMLGregorianCalendar create(LocalDate localDate) {
    return localDate != null
            ? withTypeFactoryDo(dtf -> dtf.newXMLGregorianCalendarDate(localDate.getYear(),
                    localDate.getMonthOfYear(), localDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED))
            : null;//  www  .ja  v a 2  s .com
}

From source file:org.fenixedu.academic.domain.accessControl.StudentsConcludedInExecutionYearGroup.java

License:Open Source License

@Override
public Stream<User> getMembers() {
    Set<User> users = new HashSet<User>();
    for (Registration registration : degree.getRegistrationsSet()) {
        if (registration.hasConcluded()) {
            LocalDate conclusionDate = getConclusionDate(degree, registration);
            if (conclusionDate != null && (conclusionDate.getYear() == conclusionYear.getEndCivilYear()
                    || conclusionDate.getYear() == conclusionYear.getBeginCivilYear())) {
                User user = registration.getPerson().getUser();
                if (user != null) {
                    users.add(user);/*  www. j  a  v  a 2 s. c om*/
                }
            }
        }
    }
    return users.stream();
}

From source file:org.fenixedu.academic.domain.candidacy.workflow.form.OriginInformationForm.java

License:Open Source License

@Override
public List<LabelFormatter> validate() {
    if (schoolLevel == SchoolLevelType.OTHER && StringUtils.isEmpty(otherSchoolLevel)) {
        return Collections.singletonList(new LabelFormatter().appendLabel(
                "error.candidacy.workflow.OriginInformationForm.otherSchoolLevel.must.be.filled",
                Bundle.CANDIDATE));//from   w w w . j a va 2s  .com
    }

    LocalDate now = new LocalDate();
    if (now.getYear() < conclusionYear) {
        return Collections.singletonList(new LabelFormatter()
                .appendLabel("error.personalInformation.year.after.current", Bundle.CANDIDATE));
    }

    if (conclusionYear < getBirthYear()) {
        return Collections.singletonList(new LabelFormatter()
                .appendLabel("error.personalInformation.year.before.birthday", Bundle.CANDIDATE));
    }

    return Collections.emptyList();

}