Example usage for org.joda.time LocalDate getDayOfMonth

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

Introduction

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

Prototype

public int getDayOfMonth() 

Source Link

Document

Get the day of month 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

/**
 * Calculate the first day of the history. If the current day is after the 7th day of the month,
 * the return date will be the 1st of the current month. Otherwise, the return date
 * will be the 1st of the previous month.
 * @return First history day/*from   w ww. jav a2 s.  c o m*/
 */
protected LocalDate calculateFirstHistoDay() {
    LocalDate date = new LocalDate();
    if (date.getDayOfMonth() > 7) {
        return date.withDayOfMonth(1);
    } else {
        return date.minusMonths(1).withDayOfMonth(1);
    }
}

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./* ww w .j av  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.calendar.domain.Calendar.java

License:Apache License

public Map<String, Object> updateStartDateAndDerivedFeilds(final LocalDate newMeetingStartDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(9);

    final LocalDate currentDate = DateUtils.getLocalDateOfTenant();

    if (newMeetingStartDate.isBefore(currentDate)) {
        final String defaultUserMessage = "New meeting effective from date cannot be in past";
        throw new CalendarDateException("new.start.date.cannot.be.in.past", defaultUserMessage,
                newMeetingStartDate, getStartDateLocalDate());
    } else if (isStartDateAfter(newMeetingStartDate) && isStartDateBeforeOrEqual(currentDate)) {
        // new meeting date should be on or after start date or current
        // date//  w  w w.  j  a  v a  2s .  c  om
        final String defaultUserMessage = "New meeting effective from date cannot be a date before existing meeting start date";
        throw new CalendarDateException("new.start.date.before.existing.date", defaultUserMessage,
                newMeetingStartDate, getStartDateLocalDate());
    } else {

        actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.START_DATE.getValue(), newMeetingStartDate.toString());
        this.startDate = newMeetingStartDate.toDate();

        /*
         * If meeting start date is changed then there is possibilities of
         * recurring day may change, so derive the recurring day and update
         * it if it is changed. For weekly type is weekday and for monthly
         * type it is day of the month
         */

        CalendarFrequencyType calendarFrequencyType = CalendarUtils.getFrequency(this.recurrence);
        Integer interval = CalendarUtils.getInterval(this.recurrence);
        Integer repeatsOnDay = null;

        /*
         * Repeats on day, need to derive based on the start date
         */

        if (calendarFrequencyType.isWeekly()) {
            repeatsOnDay = newMeetingStartDate.getDayOfWeek();
        } else if (calendarFrequencyType.isMonthly()) {
            repeatsOnDay = newMeetingStartDate.getDayOfMonth();
        }

        // TODO cover other recurrence also

        this.recurrence = constructRecurrence(calendarFrequencyType, interval, repeatsOnDay);

    }

    return actualChanges;

}

From source file:org.apache.fineract.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static String getRRuleReadable(final LocalDate startDate, final String recurringRule) {

    String humanReadable = "";

    RRule rrule;//w w w.  ja  v a 2s  . co m
    Recur recur = null;
    try {
        rrule = new RRule(recurringRule);
        rrule.validate();
        recur = rrule.getRecur();
    } catch (final ValidationException e) {
        throw new PlatformDataIntegrityException("error.msg.invalid.recurring.rule",
                "The Recurring Rule value: " + recurringRule + " is not valid.", "recurrence", recurringRule);
    } catch (final ParseException e) {
        throw new PlatformDataIntegrityException("error.msg.recurring.rule.parsing.error",
                "Error in pasring the Recurring Rule value: " + recurringRule, "recurrence", recurringRule);
    }

    if (recur == null) {
        return humanReadable;
    }

    if (recur.getFrequency().equals(Recur.DAILY)) {
        if (recur.getInterval() == 1) {
            humanReadable = "Daily";
        } else {
            humanReadable = "Every " + recur.getInterval() + " days";
        }
    } else if (recur.getFrequency().equals(Recur.WEEKLY)) {
        if (recur.getInterval() == 1 || recur.getInterval() == -1) {
            humanReadable = "Weekly";
        } else {
            humanReadable = "Every " + recur.getInterval() + " weeks";
        }

        humanReadable += " on ";
        final WeekDayList weekDayList = recur.getDayList();

        for (@SuppressWarnings("rawtypes")
        final Iterator iterator = weekDayList.iterator(); iterator.hasNext();) {
            final WeekDay weekDay = (WeekDay) iterator.next();
            humanReadable += DayNameEnum.from(weekDay.getDay()).getCode();
        }

    } else if (recur.getFrequency().equals(Recur.MONTHLY)) {
        if (recur.getInterval() == 1) {
            humanReadable = "Monthly on day " + startDate.getDayOfMonth();
        } else {
            humanReadable = "Every " + recur.getInterval() + " months on day " + startDate.getDayOfMonth();
        }
    } else if (recur.getFrequency().equals(Recur.YEARLY)) {
        if (recur.getInterval() == 1) {
            humanReadable = "Annually on " + startDate.toString("MMM") + " " + startDate.getDayOfMonth();
        } else {
            humanReadable = "Every " + recur.getInterval() + " years on " + startDate.toString("MMM") + " "
                    + startDate.getDayOfMonth();
        }
    }

    if (recur.getCount() > 0) {
        if (recur.getCount() == 1) {
            humanReadable = "Once";
        }
        humanReadable += ", " + recur.getCount() + " times";
    }

    final Date endDate = recur.getUntil();
    final LocalDate date = new LocalDate(endDate);
    final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MMMM YY");
    final String formattedDate = date.toString(fmt);
    if (endDate != null) {
        humanReadable += ", until " + formattedDate;
    }

    return humanReadable;
}

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

    return xgc;
}

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;/*from   ww w  .j a v a 2  s .c o m*/
}