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:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

private static int days360Between(LocalDate startDate, LocalDate endDate) {

    int nbDayOfFirstMonth = 0;
    int nbDayOfOthersMonths = 0;
    int nbDayOfLastMonth = 0;

    LocalDate start = startDate;//from  ww  w. j a v a 2  s.  co  m

    if (endDate.getMonthOfYear() != startDate.getMonthOfYear() || endDate.getYear() != startDate.getYear()) {

        // First month :: if the startDate is not the last day of the month
        if (!startDate.isEqual(startDate.dayOfMonth().withMaximumValue())) {
            nbDayOfFirstMonth = 30 - startDate.getDayOfMonth();
        }

        // The startDate is included
        nbDayOfFirstMonth = nbDayOfFirstMonth + 1;

        // Months between the first one and the last one
        LocalDate date1 = startDate.plusMonths(1).dayOfMonth().withMinimumValue();
        while (endDate.getMonthOfYear() != date1.getMonthOfYear() || endDate.getYear() != date1.getYear()) {

            nbDayOfOthersMonths = nbDayOfOthersMonths + 30;
            date1 = date1.plusMonths(1);

        }

        // Last Month
        start = endDate.dayOfMonth().withMinimumValue();
    }

    if (endDate.isEqual(endDate.dayOfMonth().withMaximumValue())) {
        nbDayOfLastMonth = 30 - start.getDayOfMonth();
    } else {
        nbDayOfLastMonth = endDate.getDayOfMonth() - start.getDayOfMonth();
    }

    // The endDate is included
    nbDayOfLastMonth = nbDayOfLastMonth + 1;

    return nbDayOfFirstMonth + nbDayOfOthersMonths + nbDayOfLastMonth;
}

From source file:com.axelor.apps.tool.date.DateTool.java

License:Open Source License

/**
 * Procdure permettant de tester si aujourd'hui nous sommes dans une priode particulire
 * //from w  w w. ja  va  2  s  .co  m
 * @param date
 *       La date  tester
 * @param dayBegin
 *       Le jour du dbut de la priode
 * @param monthBegin
 *       Le mois de dbut de la priode
 * @param dayEnd
 *       Le jour de fin de la priode
 * @param monthEnd
 *       Le mois de fin de la priode
 * @return
 *       Sommes-nous dans la priode?
 */
public static boolean dateInPeriod(LocalDate date, int dayBegin, int monthBegin, int dayEnd, int monthEnd) {

    if (monthBegin > monthEnd) {

        if ((date.getMonthOfYear() == monthBegin && date.getDayOfMonth() >= dayBegin)
                || (date.getMonthOfYear() > monthBegin) || (date.getMonthOfYear() < monthEnd)
                || (date.getMonthOfYear() == monthEnd && date.getDayOfMonth() <= dayEnd)) {
            return true;
        } else {
            return false;
        }
    } else if (monthBegin == monthEnd) {

        if ((date.getMonthOfYear() == monthBegin && date.getDayOfMonth() >= dayBegin
                && date.getDayOfMonth() <= dayEnd)) {
            return true;
        } else {
            return false;
        }
    } else {

        if ((date.getMonthOfYear() == monthBegin && date.getDayOfMonth() >= dayBegin)
                || (date.getMonthOfYear() > monthBegin && date.getMonthOfYear() < monthEnd)
                || (date.getMonthOfYear() == monthEnd && date.getDayOfMonth() <= dayEnd)) {
            return true;
        } else {
            return false;
        }
    }
}

From source file:com.creditcloud.wealthproduct.model.utils.WealthProductCalculator.java

/**
 * @deprecated analyze???/*from w  ww . j av  a  2 s .c om*/
 *
 * @param asOfDate
 * @param nextKMonth
 * @return
 */
public static LocalDate countDueDate(final LocalDate asOfDate, int nextKMonth) {
    final int[][] leap = { { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
            { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };
    int year = asOfDate.getYear();
    int month = asOfDate.getMonthOfYear();
    int day = asOfDate.getDayOfMonth();
    int i = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 0 : 1;
    int nextYear = year + (month + nextKMonth - 1) / 12;
    int nextMonth = (month + nextKMonth - 1) % 12;
    int j = ((nextYear % 4 == 0 && nextYear % 100 != 0) || (nextYear % 400 == 0)) ? 0 : 1;
    int maxNextDay = leap[j][nextMonth];
    int maxCurrentDay = leap[i][month - 1];
    LocalDate local;
    if (day < maxCurrentDay && day < maxNextDay) {
        local = new LocalDate(nextYear, nextMonth + 1, day);
    } else {
        local = new LocalDate(nextYear, nextMonth + 1, maxNextDay);
    }
    return local;
}

From source file:com.creditcloud.wealthproduct.model.utils.WealthProductCalculator.java

/**
 * ???.// www .ja v  a 2 s . co m
 *
 * @param amount
 * @param duration
 * @param rate             2400 means 24.00%
 * @param method
 * @param asOfDate         ?131?: 228(29)?331?430
 * @param period           
 * @param repayDateOfMonth 
 * @return
 */
public static WealthProductRepaymentDetail analyze(final BigDecimal amount, final Duration duration,
        final int rate, final RepaymentMethod method, final LocalDate asOfDate, final RepaymentPeriod period,
        final int repayDateOfMonth) {
    if (period == null) {
        return analyze(amount, duration, rate, method, asOfDate);
    }
    if (repayDateOfMonth == 0) {
        return analyze(amount, duration, rate, method, asOfDate, period);
    }
    if (!method.isExtensible()) {
        throw new IllegalArgumentException(method + "is not extensible repayment.");
    }
    if (!method.equals(BulletRepayment)) {//???
        //periodRepaymentMethod???
        ValidateResult validateResult = validatePeriodAndDuration(period, duration);
        if (!validateResult.isSuccess()) {
            throw new IllegalArgumentException(validateResult.getMessage());
        }
    }
    WealthProductRepaymentDetail result = null;

    //principal
    BigDecimal principal = amount;
    //now get rates
    BigDecimal rateYear = new BigDecimal(rate).divide(rateScale, mc);
    BigDecimal rateMonth = rateYear.divide(monthsPerYear, mc);
    BigDecimal ratePeriod = rateMonth.multiply(new BigDecimal(period.getMonthsOfPeriod()));

    //??
    int fixDays = repayDateOfMonth - asOfDate.getDayOfMonth();
    int fixMonth = asOfDate.getMonthOfYear() - 1;
    //31??31?
    LocalDate fixAsOfDate = new LocalDate(asOfDate.getYear(), 1, repayDateOfMonth);
    if (fixDays < 0) {
        fixAsOfDate = fixAsOfDate.plusMonths(1);
    }

    //dealing with different methods
    BigDecimal interest, amortizedInterest, amortizedPrincipal, outstandingPrincipal;

    int tenure;
    switch (method) {
    case BulletRepayment:
        //???
        analyze(amount, duration, rate, method, asOfDate);
        break;
    case MonthlyInterest: //period?
        tenure = duration.getTotalMonths() / period.getMonthsOfPeriod();
        amortizedInterest = principal.multiply(ratePeriod).setScale(2, NumberConstant.ROUNDING_MODE);
        interest = amortizedInterest.multiply(new BigDecimal(tenure));
        //create result
        result = new WealthProductRepaymentDetail(principal, interest, duration, method,
                new ArrayList<Repayment>());

        //add amortized items
        for (int i = 0; i < tenure; i++) {
            if (i < tenure - 1) { //only interest, no principal
                result.getRepayments()
                        .add(new Repayment(ZERO, amortizedInterest, principal, DateUtils.offset(fixAsOfDate,
                                new Duration(0, (i + 1) * period.getMonthsOfPeriod() + fixMonth, 0))));
            } else { //last ONE we pay off the principal as well as interest
                result.getRepayments().add(new Repayment(principal, amortizedInterest, ZERO,
                        DateUtils.offset(asOfDate, new Duration(0, (i + 1) * period.getMonthsOfPeriod(), 0))));
            }
        }
        break;
    case EqualInstallment: //period??
        //times of repayments in months
        tenure = (duration.getYears() * 12 + duration.getMonths()) / period.getMonthsOfPeriod();
        BigDecimal[] is = new BigDecimal[tenure + 1];
        for (int i = 0; i <= tenure; i++) {
            is[i] = ratePeriod.add(ONE).pow(i);
        }
        BigDecimal baseInterest = principal.multiply(ratePeriod);
        //calc installment
        BigDecimal installment = baseInterest.multiply(is[tenure]).divide(is[tenure].subtract(ONE), mc);
        installment = installment.setScale(2, NumberConstant.ROUNDING_MODE);
        //reset total interest
        interest = ZERO;
        //create WealthProductRepaymentDetail
        result = new WealthProductRepaymentDetail(principal, interest, duration, method,
                new ArrayList<Repayment>());
        //deal with amortized items
        outstandingPrincipal = principal;
        for (int i = 0; i < tenure; i++) {
            amortizedInterest = baseInterest.subtract(installment, mc).multiply(is[i]).add(installment, mc)
                    .setScale(2, NumberConstant.ROUNDING_MODE);
            amortizedPrincipal = installment.subtract(amortizedInterest);
            outstandingPrincipal = outstandingPrincipal.subtract(amortizedPrincipal);
            if (i == tenure - 1) { //last ONE we need to fix the rounding error and let the oustanding principal be ZERO
                result.getRepayments().add(new Repayment(amortizedPrincipal.add(outstandingPrincipal),
                        amortizedInterest, ZERO,
                        DateUtils.offset(asOfDate, new Duration(0, (i + 1) * period.getMonthsOfPeriod(), 0))));
            } else {
                result.getRepayments()
                        .add(new Repayment(amortizedPrincipal, amortizedInterest, outstandingPrincipal,
                                DateUtils.offset(fixAsOfDate,
                                        new Duration(0, (i + 1) * period.getMonthsOfPeriod() + fixMonth, 0))));
            }
            interest = interest.add(amortizedInterest);
        }
        //fix interest
        result.setInterest(interest);
        break;
    case EqualPrincipal: //period?
        //times of repayments in months
        tenure = (duration.getYears() * 12 + duration.getMonths()) / period.getMonthsOfPeriod();
        //calc amortized principal first
        amortizedPrincipal = principal.divide(new BigDecimal(tenure), mc).setScale(2,
                NumberConstant.ROUNDING_MODE);
        //calc by each month
        BigDecimal[] interests = new BigDecimal[tenure];
        BigDecimal[] outstandingPrincipals = new BigDecimal[tenure];
        outstandingPrincipal = principal;
        interest = ZERO;
        for (int i = 0; i < tenure; i++) {
            interests[i] = outstandingPrincipal.multiply(ratePeriod, mc).setScale(2,
                    NumberConstant.ROUNDING_MODE);
            interest = interest.add(interests[i]);
            outstandingPrincipal = outstandingPrincipal.subtract(amortizedPrincipal);
            outstandingPrincipals[i] = outstandingPrincipal;
        }
        //create WealthProductRepaymentDetail
        result = new WealthProductRepaymentDetail(principal, interest, duration, method,
                new ArrayList<Repayment>());
        //deal with amortized items
        for (int i = 0; i < tenure; i++) {
            if (i == tenure - 1) {
                result.getRepayments().add(new Repayment(amortizedPrincipal.add(outstandingPrincipals[i]),
                        interests[i], ZERO,
                        DateUtils.offset(asOfDate, new Duration(0, (i + 1) * period.getMonthsOfPeriod(), 0))));
            } else {
                result.getRepayments()
                        .add(new Repayment(amortizedPrincipal, interests[i], outstandingPrincipals[i],
                                DateUtils.offset(fixAsOfDate,
                                        new Duration(0, (i + 1) * period.getMonthsOfPeriod() + fixMonth, 0))));
            }
        }
        break;
    case EqualInterest: //period?
        //times of repayments in months
        tenure = (duration.getYears() * 12 + duration.getMonths()) / period.getMonthsOfPeriod();
        //calc amortized principal and interest
        amortizedPrincipal = principal.divide(new BigDecimal(tenure), mc).setScale(2,
                NumberConstant.ROUNDING_MODE);
        amortizedInterest = principal.multiply(ratePeriod).setScale(2, NumberConstant.ROUNDING_MODE);
        interest = amortizedInterest.multiply(new BigDecimal(tenure), mc).setScale(2,
                NumberConstant.ROUNDING_MODE);
        //create WealthProductRepaymentDetail
        result = new WealthProductRepaymentDetail(principal, interest, duration, method,
                new ArrayList<Repayment>());
        //deal with amortized items
        outstandingPrincipal = principal;
        for (int i = 0; i < tenure; i++) {
            outstandingPrincipal = outstandingPrincipal.subtract(amortizedPrincipal);
            if (i == tenure - 1) {
                result.getRepayments().add(new Repayment(amortizedPrincipal.add(outstandingPrincipal),
                        amortizedInterest, ZERO,
                        DateUtils.offset(asOfDate, new Duration(0, (i + 1) * period.getMonthsOfPeriod(), 0))));
            } else {
                result.getRepayments()
                        .add(new Repayment(amortizedPrincipal, amortizedInterest, outstandingPrincipal,
                                DateUtils.offset(fixAsOfDate,
                                        new Duration(0, (i + 1) * period.getMonthsOfPeriod() + fixMonth, 0))));
            }
        }
        break;
    }

    return result;
}

From source file:com.fourmob.datetimepicker.date.SimpleMonthView.java

License:Open Source License

public void setMonthParams(final HashMap<String, Integer> monthParams) {
    if (!monthParams.containsKey("month") && !monthParams.containsKey("year")) {
        throw new InvalidParameterException("You must specify the month and year for this view");
    }/*from ww w  .  j ava  2s  . c  o m*/
    setTag(monthParams);
    if (monthParams.containsKey("height")) {
        this.mRowHeight = monthParams.get("height").intValue();
        if (this.mRowHeight < MIN_HEIGHT) {
            this.mRowHeight = MIN_HEIGHT;
        }
    }
    if (monthParams.containsKey("selected_day")) {
        this.mSelectedDay = monthParams.get("selected_day").intValue();
    }
    this.mMonth = monthParams.get("month").intValue();
    this.mYear = monthParams.get("year").intValue();
    this.mHasToday = false;
    this.mToday = -1;
    mCalendar = mCalendar.withYear(mYear).withMonthOfYear(mMonth).withDayOfMonth(1);
    this.mDayOfWeekStart = this.mCalendar.getDayOfWeek();
    this.mWeekStart = ((Calendar.getInstance(Helpers.getLocale(getContext())).getFirstDayOfWeek() + 5)
            % SimpleMonthView.mNumDays) + 1;
    this.mNumCells = Utils.getDaysInMonth(this.mMonth, this.mYear);
    final LocalDate now = new LocalDate();
    if (mMonth == now.getMonthOfYear()) {
        for (int day = 0; day < this.mNumCells; day++) {
            if (now.getDayOfMonth() == day + 1) {
                this.mHasToday = true;
                this.mToday = now.getDayOfMonth();
            }
        }
    }
    this.mNumRows = calculateNumRows();
}

From source file:com.github.cassandra.jdbc.provider.datastax.CassandraPreparedStatement.java

License:Apache License

@Override
protected void setParameter(int paramIndex, Object paramValue) throws SQLException {
    String typeName = parameterMetaData.getParameterTypeName(paramIndex);
    Class javaClass = getDataTypeMappings().javaTypeFor(typeName);

    boolean replaceNullValue = this.cqlStmt.getConfiguration().replaceNullValue();

    if (javaClass != null) {
        paramValue = getDataTypeConverters().convert(paramValue, javaClass, replaceNullValue);
        // time is mapped by the driver to a primitive long, representing the number of nanoseconds since midnight
        if (CassandraDataType.TIME.getTypeName().equals(typeName) && paramValue instanceof Time) {
            Time time = (Time) paramValue;
            paramValue = new LocalTime(time).getMillisOfDay() * 1000000L;
        } else if (CassandraDataType.DATE.getTypeName().equals(typeName) && paramValue instanceof Date) {
            LocalDate localDate = LocalDate.fromDateFields((Date) paramValue);
            paramValue = com.datastax.driver.core.LocalDate.fromYearMonthDay(localDate.getYear(),
                    localDate.getMonthOfYear(), localDate.getDayOfMonth());
        } else if (CassandraDataType.BLOB.getTypeName().equals(typeName) && paramValue instanceof byte[]) {
            paramValue = ByteBuffer.wrap((byte[]) paramValue);
        }/*  w w  w .j a v a 2  s  .c o m*/

        parameters.put(paramIndex, paramValue);
    } else {
        super.setParameter(paramIndex, paramValue);
    }
}

From source file:com.google.ical.compat.jodatime.LocalDateIteratorFactory.java

License:Apache License

static DateValue localDateToDateValue(LocalDate date) {
    return new DateValueImpl(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
}

From source file:com.google.walkaround.wave.server.googleimport.FindRemoteWavesProcessor.java

License:Open Source License

private String getQueryDateRestriction(String facet, long dateDays) {
    LocalDate date = DaysSinceEpoch.toLocalDate(dateDays);
    return String.format("%s:%04d/%02d/%02d", facet, date.getYear(), date.getMonthOfYear(),
            date.getDayOfMonth());
}

From source file:com.gst.infrastructure.core.api.JodaLocalDateAdapter.java

License:Apache License

@SuppressWarnings("unused")
@Override//from  www  .  j  a v  a2 s  . co  m
public JsonElement serialize(final LocalDate src, final Type typeOfSrc,
        final JsonSerializationContext context) {

    JsonArray array = null;
    if (src != null) {
        array = new JsonArray();
        array.add(new JsonPrimitive(src.getYearOfEra()));
        array.add(new JsonPrimitive(src.getMonthOfYear()));
        array.add(new JsonPrimitive(src.getDayOfMonth()));
    }

    return array;
}

From source file:com.gst.infrastructure.dataqueries.service.GenericDataServiceImpl.java

License:Apache License

@Override
public String generateJsonFromGenericResultsetData(final GenericResultsetData grs) {

    final StringBuffer writer = new StringBuffer();

    writer.append("[");

    final List<ResultsetColumnHeaderData> columnHeaders = grs.getColumnHeaders();

    final List<ResultsetRowData> data = grs.getData();
    List<String> row;
    Integer rSize;/*ww  w.  j  a  va  2  s  .c om*/
    final String doubleQuote = "\"";
    final String slashDoubleQuote = "\\\"";
    String currColType;
    String currVal;

    for (int i = 0; i < data.size(); i++) {
        writer.append("\n{");

        row = data.get(i).getRow();
        rSize = row.size();
        for (int j = 0; j < rSize; j++) {

            writer.append(doubleQuote + columnHeaders.get(j).getColumnName() + doubleQuote + ": ");
            currColType = columnHeaders.get(j).getColumnDisplayType();
            final String colType = columnHeaders.get(j).getColumnType();
            if (currColType == null && colType.equalsIgnoreCase("INT")) {
                currColType = "INTEGER";
            }
            if (currColType == null && colType.equalsIgnoreCase("VARCHAR")) {
                currColType = "VARCHAR";
            }
            if (currColType == null && colType.equalsIgnoreCase("DATE")) {
                currColType = "DATE";
            }
            currVal = row.get(j);
            if (currVal != null && currColType != null) {
                if (currColType.equals("DECIMAL") || currColType.equals("INTEGER")) {
                    writer.append(currVal);
                } else {
                    if (currColType.equals("DATE")) {
                        final LocalDate localDate = new LocalDate(currVal);
                        writer.append("[" + localDate.getYear() + ", " + localDate.getMonthOfYear() + ", "
                                + localDate.getDayOfMonth() + "]");
                    } else if (currColType.equals("DATETIME")) {
                        final LocalDateTime localDateTime = new LocalDateTime(currVal);
                        writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthOfYear()
                                + ", " + localDateTime.getDayOfMonth() + " " + localDateTime.getHourOfDay()
                                + ", " + localDateTime.getMinuteOfHour() + ", "
                                + localDateTime.getSecondOfMinute() + ", " + localDateTime.getMillisOfSecond()
                                + "]");
                    } else {
                        writer.append(
                                doubleQuote + replace(currVal, doubleQuote, slashDoubleQuote) + doubleQuote);
                    }
                }
            } else {
                writer.append("null");
            }
            if (j < (rSize - 1)) {
                writer.append(",\n");
            }
        }

        if (i < (data.size() - 1)) {
            writer.append("},");
        } else {
            writer.append("}");
        }
    }

    writer.append("\n]");
    return writer.toString();

}