Example usage for org.joda.time LocalDate dayOfYear

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

Introduction

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

Prototype

public Property dayOfYear() 

Source Link

Document

Get the day of year property which provides access to advanced functionality.

Usage

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

/**
 * Get the day of year from the encodedDate,
 * 1-366./*from  ww w  . j a va 2  s  .  c  om*/
 *
 * @param encodedDate   the encoded date
 * @return             week day name.
 */
static int getDayOfYear(int encodedDate) {
    LocalDate date = new LocalDate(getYear(encodedDate), getMonth(encodedDate), getDay(encodedDate));
    return date.dayOfYear().get();
}

From source file:net.objectlab.kit.datecalc.joda.LocalDatePeriodCountCalculator.java

License:Apache License

public double yearDiff(final LocalDate start, final LocalDate end, final PeriodCountBasis basis) {
    double diff = 0.0;

    switch (basis) {
    case ACT_ACT:
        final int startYear = start.getYear();
        final int endYear = end.getYear();
        if (startYear != endYear) {
            final LocalDate endOfStartYear = start.dayOfYear().withMaximumValue();
            final LocalDate startOfEndYear = end.withDayOfYear(1);

            final int diff1 = new Period(start, endOfStartYear, PeriodType.days()).getDays();
            final int diff2 = new Period(startOfEndYear, end, PeriodType.days()).getDays();
            diff = (diff1 + 1.0) / start.dayOfYear().getMaximumValue() + (endYear - startYear - 1.0)
                    + (double) diff2 / (double) end.dayOfYear().getMaximumValue();
        }// w  w w  . jav  a 2s .  c  o  m
        break;

    case CONV_30_360:
    case CONV_360E_ISDA:
    case CONV_360E_ISMA:
    case ACT_360:
        diff = dayDiff(start, end, basis) / YEAR_360_0;
        break;

    case ACT_365:
        diff = dayDiff(start, end, basis) / YEAR_365_0;
        break;

    default:
        throw new UnsupportedOperationException("Sorry ACT_UST is not supported");
    }

    return diff;
}

From source file:nl.surfnet.coin.selfservice.control.StatisticsController.java

License:Apache License

private LocalDate getEndDate(String intervalType, LocalDate startDate) {
    LocalDate endDate;//from w  w  w  .  j a va 2 s . c  o  m
    switch (intervalType) {
    case "week":
        endDate = startDate.dayOfWeek().withMaximumValue();
        break;
    case "month":
        endDate = startDate.dayOfMonth().withMaximumValue();
        break;
    case "year":
        endDate = startDate.dayOfYear().withMaximumValue();
        break;
    default:
        throw new IllegalArgumentException(intervalType);
    }
    return endDate;
}

From source file:org.egov.lcms.transactions.service.LegalCommonReportService.java

License:Open Source License

private BoolQueryBuilder getFilterQuery(final LegalCommonReportResult searchRequest, final String reportType)
        throws ParseException {
    final SimpleDateFormat formatter = new SimpleDateFormat(LcmsConstants.DATE_FORMAT);
    final SimpleDateFormat newFormat = new SimpleDateFormat(ApplicationConstant.ES_DATE_FORMAT);
    final Map<String, Integer> monthValuesMapnumber = LegalCaseUtil.getAllMonthsInNumber();

    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    boolQuery.filter(QueryBuilders.termQuery("cityName", ApplicationThreadLocals.getCityName()));
    if (StringUtils.isNotBlank(searchRequest.getAggregatedByValue())) {

        if (searchRequest.getAggregatedBy().equals(LcmsConstants.COURTNAME))
            boolQuery.filter(QueryBuilders.matchQuery(COURTNAME, searchRequest.getAggregatedByValue()));
        if (searchRequest.getAggregatedBy().equals(LcmsConstants.PETITIONTYPE))
            boolQuery.filter(QueryBuilders.matchQuery(PETITIONTYPE, searchRequest.getAggregatedByValue()));
        else if (searchRequest.getAggregatedBy().equals(LcmsConstants.CASECATEGORY))
            boolQuery.filter(QueryBuilders.matchQuery(CASETYPE, searchRequest.getAggregatedByValue()));
        else if (searchRequest.getAggregatedBy().equals(LcmsConstants.CASESTATUS))
            boolQuery.filter(QueryBuilders.matchQuery(CASESTATUS, searchRequest.getAggregatedByValue()));
        else if (searchRequest.getAggregatedBy().equals(LcmsConstants.COURTTYPE))
            boolQuery.filter(QueryBuilders.matchQuery(COURTTYPE, searchRequest.getAggregatedByValue()));
        else if (searchRequest.getAggregatedBy().equals(LcmsConstants.OFFICERINCHRGE))
            boolQuery.filter(QueryBuilders.matchQuery(OFFICERINCHRGE,
                    searchRequest.getAggregatedByValue().split("@")[0]));
        else if (searchRequest.getAggregatedBy().equals(LcmsConstants.STANDINGCOUNSEL))
            boolQuery.filter(QueryBuilders.matchQuery(STANDINGCOUNSEL, searchRequest.getAggregatedByValue()));
        else if (searchRequest.getAggregatedBy().equals(LcmsConstants.JUDGEMENTOUTCOME))
            boolQuery.filter(QueryBuilders.matchQuery(JUDGEMENTOUTCOME, searchRequest.getAggregatedByValue()));
    }// ww w  .  ja v a  2 s.c  o  m
    if (StringUtils.isNotBlank(searchRequest.getMonth()) && StringUtils.isNotBlank(searchRequest.getYear())) {
        final Integer monthName = monthValuesMapnumber.get(searchRequest.getMonth());
        // Prepare the start date based on the month number and year
        final String monthYearStartDateStr = searchRequest.getYear().concat("-").concat(monthName.toString())
                .concat("-").concat("01");
        final LocalDate monthYearStDate = new LocalDate(monthYearStartDateStr);
        // Fetch the start date of the 1st week of the month and the last day of the month
        if (MONTH.equalsIgnoreCase(searchRequest.getPeriod())) {
            final LocalDate weekStart = monthYearStDate.dayOfWeek().withMinimumValue();
            final LocalDate endOfMonth = monthYearStDate.dayOfMonth().withMaximumValue();
            final String startDate = weekStart.toString(LcmsConstants.DATE_FORMAT);
            final String endDate = endOfMonth.toString(LcmsConstants.DATE_FORMAT);
            boolQuery = boolQuery.filter(
                    QueryBuilders.rangeQuery(CASE_DATE).gte(newFormat.format(formatter.parse(startDate)))
                            .lte(new DateTime(newFormat.format(formatter.parse(endDate)))));
        }
        if (YEAR.equalsIgnoreCase(searchRequest.getPeriod())) {
            final LocalDate monthStart = monthYearStDate.dayOfMonth().withMinimumValue();
            final LocalDate endOfYear = monthYearStDate.dayOfYear().withMaximumValue();
            final String startDate = monthStart.toString(LcmsConstants.DATE_FORMAT);
            final String endDate = endOfYear.toString(LcmsConstants.DATE_FORMAT);
            boolQuery = boolQuery.filter(
                    QueryBuilders.rangeQuery(CASE_DATE).gte(newFormat.format(formatter.parse(startDate)))
                            .lte(new DateTime(newFormat.format(formatter.parse(endDate)))));
        }

    }
    if (reportType != null) {
        if (reportType.equals(LcmsConstants.DUEPWRREPORT))
            boolQuery.mustNot(QueryBuilders.existsQuery("pwrDueDate"));
        else if (reportType.equals(LcmsConstants.DUECAREPORT))
            boolQuery.must(QueryBuilders.existsQuery("caDueDate"));

        else if (reportType.equals(LcmsConstants.DUEJUDGEMENTIMPLPREPORT))
            boolQuery.mustNot(QueryBuilders.matchQuery("status", LcmsConstants.LEGALCASE_STATUS_CLOSED_DESC));

        if (reportType.equals(LcmsConstants.DUEJUDGEMENTIMPLPREPORT)
                && StringUtils.isNotBlank(searchRequest.getCaseFromDate()))
            boolQuery = boolQuery.filter(QueryBuilders.rangeQuery("judgmentImplDate")
                    .gte(newFormat.format(formatter.parse(searchRequest.getCaseFromDate())))
                    .lte(new DateTime(newFormat.format(formatter.parse(searchRequest.getCaseToDate())))));

        if (reportType.equals(LcmsConstants.DUEEMPLOYEEHEARINGREPORT)) {
            final List<String> statusCodeList = new ArrayList<>();
            statusCodeList.add(LcmsConstants.LEGALCASE_STATUS_HEARING_DESC);
            statusCodeList.add(LcmsConstants.LEGALCASE_INTERIMSTAY_STATUS_DESC);
            boolQuery.must(QueryBuilders.termsQuery(CASESTATUS, statusCodeList));
            if (searchRequest.getLcNumber() != null)
                boolQuery = boolQuery.filter(QueryBuilders.matchQuery("lcNumber", searchRequest.getLcNumber()));

            if (StringUtils.isNotBlank(searchRequest.getCaseFromDate()))
                boolQuery = boolQuery.filter(QueryBuilders.rangeQuery(CASE_DATE)
                        .gte(newFormat.format(formatter.parse(searchRequest.getCaseFromDate())))
                        .lte(new DateTime(newFormat.format(formatter.parse(searchRequest.getCaseToDate())))));

        }
    } else if (StringUtils.isNotBlank(searchRequest.getCaseFromDate()))
        boolQuery = boolQuery.filter(QueryBuilders.rangeQuery(CASE_DATE)
                .gte(newFormat.format(formatter.parse(searchRequest.getCaseFromDate())))
                .lte(new DateTime(newFormat.format(formatter.parse(searchRequest.getCaseToDate())))));

    if (StringUtils.isNotBlank(searchRequest.getOfficerIncharge()))
        boolQuery = boolQuery.filter(
                QueryBuilders.termQuery(OFFICERINCHRGE, searchRequest.getOfficerIncharge().split("@")[0]));
    if (StringUtils.isNotBlank(searchRequest.getCaseCategory()))
        boolQuery = boolQuery.filter(QueryBuilders.termQuery(CASETYPE, searchRequest.getCaseCategory()));
    if (StringUtils.isNotBlank(searchRequest.getCourtName()))
        boolQuery = boolQuery.filter(QueryBuilders.termQuery(COURTNAME, searchRequest.getCourtName()));
    if (StringUtils.isNotBlank(searchRequest.getCaseStatus()))
        boolQuery = boolQuery.filter(QueryBuilders.termQuery(CASESTATUS, searchRequest.getCaseStatus()));
    if (StringUtils.isNotBlank(searchRequest.getCourtType()))
        boolQuery = boolQuery.filter(QueryBuilders.termQuery(COURTTYPE, searchRequest.getCourtType()));
    if (StringUtils.isNotBlank(searchRequest.getPetitionType()))
        boolQuery = boolQuery.filter(QueryBuilders.termQuery(PETITIONTYPE, searchRequest.getPetitionType()));
    if (StringUtils.isNotBlank(searchRequest.getJudgmentType()))
        boolQuery = boolQuery
                .filter(QueryBuilders.termQuery(JUDGEMENTOUTCOME, searchRequest.getJudgmentType()));
    if (StringUtils.isNotBlank(searchRequest.getStandingCounsel()))
        boolQuery = boolQuery
                .filter(QueryBuilders.termQuery("advocateName", searchRequest.getStandingCounsel()));
    if (StringUtils.isNotBlank(searchRequest.getReportStatus()))
        boolQuery = boolQuery.filter(QueryBuilders.termQuery("subStatus", searchRequest.getReportStatus()));

    return boolQuery;
}

From source file:org.gnucash.android.model.Recurrence.java

License:Apache License

/**
 * Return the number of days left in this period
 * @return Number of days left in period
 *///from  www . j  a  v  a2s  .  c  om
public int getDaysLeftInCurrentPeriod() {
    LocalDate startDate = new LocalDate(System.currentTimeMillis());
    int interval = mPeriodType.getMultiplier() - 1;
    LocalDate endDate = null;
    switch (mPeriodType) {
    case DAY:
        endDate = new LocalDate(System.currentTimeMillis()).plusDays(interval);
        break;
    case WEEK:
        endDate = startDate.dayOfWeek().withMaximumValue().plusWeeks(interval);
        break;
    case MONTH:
        endDate = startDate.dayOfMonth().withMaximumValue().plusMonths(interval);
        break;
    case YEAR:
        endDate = startDate.dayOfYear().withMaximumValue().plusYears(interval);
        break;
    }

    return Days.daysBetween(startDate, endDate).getDays();
}

From source file:org.gnucash.android.model.Recurrence.java

License:Apache License

/**
 * Returns the number of periods from the start date of this recurrence until the end of the
 * interval multiplier specified in the {@link PeriodType}
 * //fixme: Improve the documentation// w  ww. j a  v a 2  s .c  o m
 * @return Number of periods in this recurrence
 */
public int getNumberOfPeriods(int numberOfPeriods) {
    LocalDate startDate = new LocalDate(mPeriodStart.getTime());
    LocalDate endDate;
    int interval = mPeriodType.getMultiplier();
    //// TODO: 15.08.2016 Why do we add the number of periods. maybe rename method or param
    switch (mPeriodType) {

    case DAY:
        return 1;
    case WEEK:
        endDate = startDate.dayOfWeek().withMaximumValue().plusWeeks(numberOfPeriods);
        return Weeks.weeksBetween(startDate, endDate).getWeeks() / interval;
    case MONTH:
        endDate = startDate.dayOfMonth().withMaximumValue().plusMonths(numberOfPeriods);
        return Months.monthsBetween(startDate, endDate).getMonths() / interval;
    case YEAR:
        endDate = startDate.dayOfYear().withMaximumValue().plusYears(numberOfPeriods);
        return Years.yearsBetween(startDate, endDate).getYears() / interval;
    }

    return 0;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public boolean isDateAtEarnInterval(LocalDate aDate, String earnInterval) {
    boolean atEarnInterval = false;
    if (HrConstants.ACCRUAL_EARN_INTERVAL_MAP.containsKey(earnInterval)) {
        if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) {
            atEarnInterval = true;//w  w  w  .  j  a v a2  s.c  o m
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) {
            // figure out if the day is a Saturday
            if (aDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) {
            // either the 15th or the last day of the month
            if (aDate.getDayOfMonth() == 15 || aDate.getDayOfMonth() == aDate.dayOfMonth().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) {
            // the last day of the month
            if (aDate.getDayOfMonth() == aDate.dayOfMonth().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) {
            // the last day of the year
            if (aDate.getDayOfYear() == aDate.dayOfYear().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) {
            // no calculation
        }
    }
    return atEarnInterval;
}