Example usage for org.joda.time LocalDate getMonthOfYear

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

Introduction

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

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:org.agatom.springatom.data.hades.model.appointment.NAppointment.java

License:Open Source License

public NAppointment setEndDate(final LocalDate localDate) {
    this.requireEndDate();
    final MutableDateTime mutableDateTime = this.end.toMutableDateTime();
    mutableDateTime.setDate(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth());
    this.end = mutableDateTime.toDateTime();
    return this;
}

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   www.  j  a  va2 s. c  o m*/
 * @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.controllers.AccountController.java

License:Open Source License

/**
 * Build categories summary for each month from startDate
 * to previous nbPrevMonth/*from w w w .j  a va  2  s.c om*/
 * @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.controllers.MonthOps.java

License:Open Source License

/**
 * Add an operation into the set.//  www.j  a  v  a2s.c om
 * @param op Operation to add.
 */
public void addOp(Operation op) {
    //checking month
    if (op.getOperationDate() == null)
        throw new IllegalArgumentException("Operation date null");
    LocalDate opDate = new LocalDate(op.getOperationDate());
    if (opDate.getMonthOfYear() != lastDay.getMonthOfYear()) {
        throw new IllegalArgumentException("Invalid month in operation date");
    }
    if (op.getPlanned() == null)
        throw new IllegalArgumentException("Planned amount cannot be null");
    ops.add(op);
    amount = amount.add(op.getPlanned());
    balance = balance.add(op.getPlanned());
    dirtyTotals = true;
}

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  ww.  ja v a  2s .  c  o  m*/
 * 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   ww  w. j ava  2s  . c o  m*/
    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  .ja va  2 s  . c om
    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");
    }/*  ww  w .j  a  va2s . c om*/
    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)} ()}.
 *//*w w w.  j a  v a 2s  .co  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());/*w  w  w  .ja v  a 2  s .c o m*/
    xgc.setMonth(dateTime.getMonthOfYear());
    xgc.setDay(dateTime.getDayOfMonth());

    return xgc;
}