Example usage for org.joda.time LocalDate LocalDate

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

Introduction

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

Prototype

public LocalDate(int year, int monthOfYear, int dayOfMonth) 

Source Link

Document

Constructs an instance set to the specified date and time using ISOChronology.

Usage

From source file:com.accounted4.money.loan.JasperReportDataSourceAmortizationSchedule.java

License:Apache License

public static Collection<ScheduledPayment> getSamplePaymentCollection() {

    List<ScheduledPayment> paymentList = new ArrayList<>();

    AmortizationAttributes amAttrs = new AmortizationAttributes();
    amAttrs.setLoanAmount(new Money("20000.00"));
    amAttrs.setRegularPayment(new Money("0")); // monthly payment to be made, assumed monthly
    amAttrs.setStartDate(new LocalDate(2013, 1, 8));
    amAttrs.setAdjustmentDate(new LocalDate(2013, 1, 15));
    amAttrs.setTermInMonths(12);/*from ww  w  . jav a2s  .  c  om*/
    amAttrs.setInterestOnly(false);
    amAttrs.setAmortizationPeriodMonths(25 * 12);
    amAttrs.setCompoundingPeriodsPerYear(2);
    amAttrs.setInterestRate(12.);

    Iterator<ScheduledPayment> payments = AmortizationCalculator.getPayments(amAttrs);
    while (payments.hasNext()) {
        paymentList.add(payments.next());
    }

    return paymentList;

}

From source file:com.adamdubiel.smartparam.DiscountCalculatorDemo.java

License:Apache License

@Test
public void demonstrateDiscountCalculationForPrzemek() {
    // given//from w  ww .  j  a  va2  s  .  c om
    dateProvider.servedDate(2013, 12, 17);

    User user = new User(new UserLogin("przemek"), new LocalDate(2013, 11, 23), UserAccountType.PREMIUM);

    // when
    Discount discount = discountCalculator.calculateForUser(user);

    // then
    assertThat(discount.value()).isEqualTo(70);
}

From source file:com.adamdubiel.smartparam.DiscountCalculatorDemo.java

License:Apache License

@Test
public void demonstrateDiscountCalculationForAdam() {
    // given/*  w w w  .java2  s.c  o  m*/
    dateProvider.servedDate(2013, 12, 17);

    User user = new User(new UserLogin("adam"), new LocalDate(2013, 11, 23), UserAccountType.REGULAR);

    // when
    Discount discount = discountCalculator.calculateForUser(user);

    // then
    assertThat(discount.value()).isEqualTo(10);
}

From source file:com.ajah.spring.jdbc.AbstractAjahDao.java

License:Apache License

/**
 * Will automatically fill in properties from the result set. Currently
 * supports:/*from ww w.  j a v a  2  s.  co  m*/
 * 
 * <ul>
 * <li>{@link String}</li>
 * <ul>
 * 
 * @throws SQLException
 *             If the {@link ResultSet} throws it.
 * 
 * @see com.ajah.spring.jdbc.AjahDao#autoPopulate(Identifiable, ResultSet)
 */
@Override
public void autoPopulate(final T entity, final ResultSet rs) throws SQLException {
    try {
        final BeanInfo componentBeanInfo = Introspector.getBeanInfo(entity.getClass());
        final PropertyDescriptor[] props = componentBeanInfo.getPropertyDescriptors();
        for (final PropertyDescriptor prop : props) {
            log.finest("PropertyDescriptor: " + prop.getName() + ", Setter: "
                    + (prop.getWriteMethod() == null ? null : prop.getWriteMethod().getName()) + " Getter: "
                    + (prop.getReadMethod() == null ? null : prop.getReadMethod().getName()));
        }
        for (final String column : getColumns()) {
            final Field field = this.colMap.get(column);
            if (field == null) {
                log.warning("No field mapped for column: " + column);
            } else if (rs.getObject(column) == null) {
                propSet(entity, getProp(field, props), null);
            } else if (IntrospectionUtils.isString(field)) {
                propSet(entity, getProp(field, props), rs.getString(column));
            } else if (IntrospectionUtils.isDate(field)) {
                propSet(entity, getProp(field, props), new Date(rs.getLong(column)));
            } else if (IntrospectionUtils.isFromStringable(field)) {
                propSet(entity, getProp(field, props),
                        field.getType().getConstructor(String.class).newInstance(rs.getString(column)));
            } else if (IntrospectionUtils.isIdentifiableEnum(field)) {
                propSet(entity, getProp(field, props),
                        ReflectionUtils.findEnumById(field, rs.getString(column)));
            } else if (IntrospectionUtils.isInt(field)) {
                if (rs.getObject(column) == null && IntrospectionUtils.isPrimitive(field)) {
                    log.warning("Attempting to set a null value on a primitive int field, using zero");
                    propSet(entity, getProp(field, props), Integer.valueOf(0));
                } else {
                    propSet(entity, getProp(field, props), Integer.valueOf(rs.getInt(column)));
                }
            } else if (IntrospectionUtils.isLong(field)) {
                if (rs.getObject(column) == null && IntrospectionUtils.isPrimitive(field)) {
                    log.warning("Attempting to set a null value on a primitive long field, using zero");
                    propSet(entity, getProp(field, props), Long.valueOf(0));
                } else {
                    propSet(entity, getProp(field, props), Long.valueOf(rs.getLong(column)));
                }
            } else if (IntrospectionUtils.isBoolean(field)) {
                propSet(entity, getProp(field, props), Boolean.valueOf(rs.getBoolean(column)));
            } else if (IntrospectionUtils.isEnum(field)) {
                log.warning("Can't handle non-Identifiable enum for column " + column + " [" + field.getType()
                        + "]");
            } else if (BigDecimal.class.isAssignableFrom(field.getType())) {
                final BigDecimal bigDecimal = rs.getBigDecimal(column);
                propSet(entity, getProp(field, props), bigDecimal);
            } else if (LocalDate.class.isAssignableFrom(field.getType())) {
                if (!StringUtils.isBlank(rs.getString(column))) {
                    final int[] parts = ArrayUtils.parseInt(rs.getString(column).split("-"));
                    final LocalDate localDate = new LocalDate(parts[0], parts[1], parts[2]);
                    propSet(entity, getProp(field, props), localDate);
                }
            } else {
                log.warning("Can't handle auto-populating of column " + column + " of type " + field.getType());
            }
        }
    } catch (final IntrospectionException e) {
        log.log(Level.SEVERE, entity.getClass().getName() + ": " + e.getMessage(), e);
    } catch (final SecurityException e) {
        log.log(Level.SEVERE, entity.getClass().getName() + ": " + e.getMessage(), e);
    } catch (final InstantiationException e) {
        log.log(Level.SEVERE, entity.getClass().getName() + ": " + e.getMessage(), e);
    } catch (final IllegalAccessException e) {
        log.log(Level.SEVERE, entity.getClass().getName() + ": " + e.getMessage(), e);
    } catch (final InvocationTargetException e) {
        log.log(Level.SEVERE, entity.getClass().getName() + ": " + e.getMessage(), e);
    } catch (final NoSuchMethodException e) {
        log.log(Level.SEVERE, entity.getClass().getName() + ": " + e.getMessage(), e);
    }
}

From source file:com.alliander.osgp.domain.core.valueobjects.smartmetering.CosemDate.java

License:Open Source License

/**
 * Returns this {@link CosemDate} as {@link LocalDate} if {@code year},
 * {@code month} and {@code dayOfMonth} do not contain wildcard values.
 *
 * @return this {@link CosemDate} as {@link LocalDate}, or {@code null} if
 *         not {@link #isLocalDateSpecified()}.
 *
 * @see #isLocalDateSpecified()/* ww  w.j av a2s .  c om*/
 */
public LocalDate asLocalDate() {
    if (this.isLocalDateSpecified()) {
        return new LocalDate(this.year, this.month, this.dayOfMonth);
    }
    return null;
}

From source file:com.aperigeek.gotadate.parser.DateParser.java

License:Open Source License

/**
 * Parse a date and store it in the parsed dates list
 * /*from   ww  w.  jav a2s.  c  o m*/
 * A date is defined by the following syntax:
 * Date:
 *     number "/" number "/" number
 * 
 * The interpretation of this string depends on the value of each number.
 * The parser tries to determine which value is the day, the month and
 * the year.
 */
protected LocalDate parseDate() throws DateParseException, UnexpectedTokenException {
    int[] ls = new int[3];

    ls[0] = getInt();
    if (isOrdinal(token)) {
        next();
    }

    if (isToken('/')) {
        check('/');
        ls[1] = getInt();
        check('/');
        ls[2] = getInt();
    } else if (isMonthName(token)) {
        ls[1] = getMonth();
        if (isTokenType(TokenType.NUMBER)) {
            ls[2] = getInt();
        }
    } else {
        throw new UnexpectedTokenException();
    }

    if (ls[1] > 12 && ls[0] <= 12) {
        int tmp = ls[1];
        ls[1] = ls[0];
        ls[0] = tmp;
    }

    if (ls[2] == 0) {
        ls[2] = now.getYear();
    }

    LocalDate date = new LocalDate(ls[2], ls[1], ls[0]);
    return date;
}

From source file:com.aperigeek.gotadate.parser.DateParser.java

License:Open Source License

protected LocalDate parseDateMonthFirst() throws DateParseException, UnexpectedTokenException {

    int[] ls = new int[3];

    ls[1] = MONTHS_MAP.get(token.getValue());
    next();/*from  ww  w  .j  a v a  2  s.  c o  m*/

    ls[0] = getInt();

    if (isOrdinal(token)) {
        next();
    }
    if (isToken(',')) {
        next();
    }

    if (isTokenType(TokenType.NUMBER)) {
        ls[2] = getInt();
    }

    if (ls[2] == 0) {
        ls[2] = now.getYear();
    }

    LocalDate date = new LocalDate(ls[2], ls[1], ls[0]);
    return date;
}

From source file:com.axelor.apps.account.service.RejectImportService.java

License:Open Source License

/**
 * Mthode permettant de construire une date de rejet depuis le texte rcupr du fichier CFONB
 * @param dateReject/*from   ww w.j a  v  a2 s  .  co  m*/
 * @return
 */
public LocalDate createRejectDate(String dateReject) {
    return new LocalDate(Integer.parseInt(dateReject.substring(4, 6)) + 2000,
            Integer.parseInt(dateReject.substring(2, 4)), Integer.parseInt(dateReject.substring(0, 2)));
}

From source file:com.axelor.apps.hr.service.PayrollPreparationService.java

License:Open Source License

public List<PayrollLeave> fillInLeaves(PayrollPreparation payrollPreparation) throws AxelorException {
    List<PayrollLeave> payrollLeaveList = new ArrayList<PayrollLeave>();
    LocalDate fromDate = new LocalDate(payrollPreparation.getYearPeriod(), payrollPreparation.getMonthSelect(),
            1);//from  ww  w.j  ava 2 s .  c  om
    LocalDate toDate = new LocalDate(fromDate);
    toDate = toDate.dayOfMonth().withMaximumValue();
    Employee employee = payrollPreparation.getEmployee();
    if (employee.getPublicHolidayPlanning() == null) {
        throw new AxelorException(
                String.format(I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY), employee.getName()),
                IException.CONFIGURATION_ERROR);
    }
    if (employee.getPlanning() == null) {
        throw new AxelorException(
                String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName()),
                IException.CONFIGURATION_ERROR);
    }

    List<LeaveRequest> leaveRequestList = leaveRequestRepo.all().filter(
            "self.statusSelect = 3 AND self.user.employee = ?3 AND self.dateFrom <= ?1 AND self.dateTo >= ?2",
            toDate, fromDate, employee).fetch();
    for (LeaveRequest leaveRequest : leaveRequestList) {
        PayrollLeave payrollLeave = new PayrollLeave();
        if (leaveRequest.getDateFrom().isBefore(fromDate)) {
            payrollLeave.setFromDate(fromDate);
        } else {
            payrollLeave.setFromDate(leaveRequest.getDateFrom());
        }
        if (leaveRequest.getDateTo().isAfter(toDate)) {
            payrollLeave.setToDate(toDate);
        } else {
            payrollLeave.setToDate(leaveRequest.getDateTo());
        }

        payrollLeave.setDuration(
                leaveService.computeLeaveDaysByLeaveRequest(fromDate, toDate, leaveRequest, employee));
        payrollLeave.setReason(leaveRequest.getReason());
        payrollLeave.setLeaveRequest(leaveRequest);
        payrollLeaveList.add(payrollLeave);
    }
    return payrollLeaveList;
}

From source file:com.axelor.apps.hr.service.PayrollPreparationService.java

License:Open Source License

public BigDecimal computeWorkingDaysNumber(PayrollPreparation payrollPreparation,
        List<PayrollLeave> payrollLeaveList) {
    LocalDate fromDate = new LocalDate(payrollPreparation.getYearPeriod(), payrollPreparation.getMonthSelect(),
            1);/*from  ww  w .  ja  va 2 s .c  om*/
    LocalDate toDate = new LocalDate(fromDate);
    toDate = toDate.dayOfMonth().withMaximumValue();
    LocalDate itDate = new LocalDate(fromDate);
    BigDecimal workingDays = BigDecimal.ZERO;
    while (!itDate.isAfter(toDate)) {
        workingDays = workingDays.add(new BigDecimal(
                weeklyPlanningService.workingDayValue(payrollPreparation.getEmployee().getPlanning(), itDate)));
        itDate = itDate.plusDays(1);
    }
    if (payrollLeaveList != null) {
        for (PayrollLeave payrollLeave : payrollLeaveList) {
            workingDays = workingDays.subtract(payrollLeave.getDuration());
        }
    }

    return workingDays;
}