Example usage for org.joda.time LocalDate dayOfMonth

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

Introduction

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

Prototype

public Property dayOfMonth() 

Source Link

Document

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

Usage

From source file:org.egov.ptis.web.controller.dashboard.CMDashboardController.java

License:Open Source License

/**
 * Provides citywise DCB details across all ULBs for MIS Reports
 * @return response JSON//  www .  j av  a2s . c  om
 * @throws IOException
 */
@RequestMapping(value = "/citywisedcb", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public MISDCBDetails getDCBDetailsForMIS(CollectionDetailsRequest collectionDetailsRequest) {
    MISDCBDetails misDCBDetails = new MISDCBDetails();
    List<WeeklyDCB> weekwiseDCBDetails;
    List<MonthlyDCB> monthwiseDCBDetails;
    if (StringUtils.isBlank(collectionDetailsRequest.getIntervalType()))
        misDCBDetails.setDcbDetails(propTaxDashboardService.getDCBDetails(collectionDetailsRequest));
    else {
        String startDate;
        String endDate;
        if (WEEK.equalsIgnoreCase(collectionDetailsRequest.getIntervalType())) {
            String monthStartDateStr = collectionDetailsRequest.getYear().concat("-")
                    .concat(collectionDetailsRequest.getMonth()).concat("-").concat("01");
            LocalDate monthStDate = new LocalDate(monthStartDateStr);
            // Fetch the start date of the 1st week of the month and the last day of the month
            LocalDate weekStart = monthStDate.dayOfWeek().withMinimumValue();
            LocalDate endOfMonth = monthStDate.dayOfMonth().withMaximumValue();
            startDate = weekStart.toString(PropertyTaxConstants.DATE_FORMAT_YYYYMMDD);
            endDate = endOfMonth.toString(PropertyTaxConstants.DATE_FORMAT_YYYYMMDD);
            collectionDetailsRequest.setFromDate(startDate);
            collectionDetailsRequest.setToDate(endDate);
        }
    }
    if (WEEK.equalsIgnoreCase(collectionDetailsRequest.getIntervalType())) {
        weekwiseDCBDetails = propTaxDashboardService.getWeekwiseDCBDetails(collectionDetailsRequest,
                collectionDetailsRequest.getIntervalType());
        misDCBDetails.setWeeklyDCBDetails(weekwiseDCBDetails);
    } else if (MONTH.equalsIgnoreCase(collectionDetailsRequest.getIntervalType())) {
        monthwiseDCBDetails = propTaxDashboardService.getMonthwiseDCBDetails(collectionDetailsRequest,
                collectionDetailsRequest.getIntervalType());
        misDCBDetails.setMonthlyDCBDetails(monthwiseDCBDetails);
    }
    return misDCBDetails;
}

From source file:org.egov.ptis.web.controller.dashboard.CMDashboardController.java

License:Open Source License

/**
 * Provides collection analysis data across all ULBs for MIS Reports
 * @return response JSON/*from   w  w  w .  ja  v a2 s .  co m*/
 * @throws IOException
 */
@RequestMapping(value = "/collectionanalysis", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public CollectionAnalysis getCollectionAnalysisForMIS(CollectionDetailsRequest collectionDetailsRequest) {
    if (StringUtils.isNotBlank(collectionDetailsRequest.getIntervalType())) {
        String startDate = StringUtils.EMPTY;
        String endDate = StringUtils.EMPTY;
        if (WEEK.equalsIgnoreCase(collectionDetailsRequest.getIntervalType())) {
            // Prepare the start date based on the month number and year
            String monthStartDateStr = collectionDetailsRequest.getYear().concat("-")
                    .concat(collectionDetailsRequest.getMonth()).concat("-").concat("01");
            LocalDate monthStDate = new LocalDate(monthStartDateStr);
            // Fetch the start date of the 1st week of the month and the last day of the month
            LocalDate weekStart = monthStDate.dayOfWeek().withMinimumValue();
            LocalDate endOfMonth = monthStDate.dayOfMonth().withMaximumValue();
            startDate = weekStart.toString(PropertyTaxConstants.DATE_FORMAT_YYYYMMDD);
            endDate = endOfMonth.toString(PropertyTaxConstants.DATE_FORMAT_YYYYMMDD);
        } else if (DAY.equalsIgnoreCase(collectionDetailsRequest.getIntervalType())) {
            // Prepare the first and last days of the week based on the month, year and week of month values
            DateTime date = new DateTime().withYear(Integer.parseInt(collectionDetailsRequest.getYear()))
                    .withMonthOfYear(Integer.parseInt(collectionDetailsRequest.getMonth()));
            Calendar cal = date.toCalendar(Locale.getDefault());
            cal.set(Calendar.DAY_OF_WEEK, 2);
            cal.set(Calendar.WEEK_OF_MONTH, Integer.parseInt(collectionDetailsRequest.getWeek()));
            DateTime weekStartDate = new DateTime(cal).withMillisOfDay(0);
            startDate = weekStartDate.toString(PropertyTaxConstants.DATE_FORMAT_YYYYMMDD);
            Date weekEndDate = DateUtils.addDays(weekStartDate.toDate(), 6);
            endDate = PropertyTaxConstants.DATEFORMATTER_YYYY_MM_DD.format(weekEndDate);
        }
        if (WEEK.equalsIgnoreCase(collectionDetailsRequest.getIntervalType())
                || DAY.equalsIgnoreCase(collectionDetailsRequest.getIntervalType())) {
            collectionDetailsRequest.setFromDate(startDate);
            collectionDetailsRequest.setToDate(endDate);
        }
    }
    return propTaxDashboardService.getCollectionAnalysisData(collectionDetailsRequest,
            collectionDetailsRequest.getIntervalType());
}

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  ww w.ja  va 2 s. c  o  m*/
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//from   w  ww .  ja v a  2s  .c  om
 * @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.killbill.billing.invoice.generator.BillingIntervalDetail.java

License:Apache License

public static LocalDate alignProposedBillCycleDate(final LocalDate proposedDate, final int billingCycleDay) {
    final int lastDayOfMonth = proposedDate.dayOfMonth().getMaximumValue();
    int proposedBillCycleDate = proposedDate.getDayOfMonth();
    if (proposedBillCycleDate < billingCycleDay && billingCycleDay <= lastDayOfMonth) {
        proposedBillCycleDate = billingCycleDay;
    }//from  w  w w  .ja  v a 2  s.  co  m
    return new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), proposedBillCycleDate,
            proposedDate.getChronology());
}

From source file:org.killbill.billing.util.bcd.BillCycleDayCalculator.java

License:Apache License

public static LocalDate alignProposedBillCycleDate(final LocalDate proposedDate, final int billingCycleDay,
        final BillingPeriod billingPeriod) {
    // billingCycleDay alignment only makes sense for month based BillingPeriod (MONTHLY, QUARTERLY, BIANNUAL, ANNUAL)
    final boolean isMonthBased = (billingPeriod.getPeriod().getMonths()
            | billingPeriod.getPeriod().getYears()) > 0;
    if (!isMonthBased) {
        return proposedDate;
    }/*from  www .j av a 2s. c  o m*/
    final int lastDayOfMonth = proposedDate.dayOfMonth().getMaximumValue();
    int proposedBillCycleDate = proposedDate.getDayOfMonth();
    if (proposedBillCycleDate < billingCycleDay) {
        if (billingCycleDay <= lastDayOfMonth) {
            proposedBillCycleDate = billingCycleDay;
        } else {
            proposedBillCycleDate = lastDayOfMonth;
        }
    }
    return new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), proposedBillCycleDate,
            proposedDate.getChronology());
}

From source file:org.kuali.kpme.core.accrualcategory.rule.service.AccrualCategoryRuleServiceImpl.java

License:Educational Community License

public AccrualCategoryRule getAccrualCategoryRuleForDate(AccrualCategory accrualCategory, LocalDate currentDate,
        LocalDate serviceDate) {/*from  w w  w .jav a2s.c o  m*/
    if (serviceDate == null) {
        return null;
    }
    List<AccrualCategoryRule> acrList = this
            .getActiveAccrualCategoryRules(accrualCategory.getLmAccrualCategoryId());
    for (AccrualCategoryRule acr : acrList) {
        String uot = acr.getServiceUnitOfTime();
        int startTime = acr.getStart().intValue();
        int endTime = acr.getEnd().intValue();

        LocalDate startDate = serviceDate;
        LocalDate endDate = serviceDate;
        if (uot.equals("M")) { // monthly
            startDate = startDate.plusMonths(startTime);
            endDate = endDate.plusMonths(endTime).minusDays(1);
        } else if (uot.endsWith("Y")) { // yearly
            startDate = startDate.plusYears(startTime);
            endDate = endDate.plusYears(endTime).minusDays(1);
        }

        // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
        if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
            startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
        }
        if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
            endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
        }

        if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
            return acr;
        }
    }
    return null;
}

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;//from  www.  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;
}

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

License:Educational Community License

@Override
public void calculateFutureAccrualUsingPlanningMonth(String principalId, LocalDate asOfDate,
        String runAsPrincipalId) {
    PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService()
            .getPrincipalCalendar(principalId, asOfDate);
    if (phra != null) {
        // use the date from pay period to get the leave plan
        LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(phra.getLeavePlan(), asOfDate);
        if (lp != null && StringUtils.isNotEmpty(lp.getPlanningMonths())) {
            // go back a year 
            LocalDate startDate = asOfDate.minusYears(1);
            if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
            }//  www  .j  a  va2 s  .  c  o  m
            // go forward using planning months
            LocalDate endDate = asOfDate.plusMonths(Integer.parseInt(lp.getPlanningMonths()));
            // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
            if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
            }
            runAccrual(principalId, startDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay(), true,
                    runAsPrincipalId);

        }
    }
}

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

License:Educational Community License

public List<AccrualCategoryRule> getAccrualCategoryRulesForDate(List<AccrualCategoryRule> acrList,
        String accrualCategoryId, LocalDate currentDate, LocalDate serviceDate) {
    List<AccrualCategoryRule> aList = new ArrayList<AccrualCategoryRule>();
    if (CollectionUtils.isNotEmpty(acrList)) {
        for (AccrualCategoryRule acr : acrList) {
            if (acr.getLmAccrualCategoryId().equals(accrualCategoryId)) {
                String uot = acr.getServiceUnitOfTime();
                int startTime = acr.getStart().intValue();
                int endTime = acr.getEnd().intValue();

                LocalDate startDate = serviceDate;
                LocalDate endDate = serviceDate;
                if (uot.equals("M")) { // monthly
                    startDate = startDate.plusMonths(startTime);
                    endDate = endDate.plusMonths(endTime).minusDays(1);
                } else if (uot.endsWith("Y")) { // yearly
                    startDate = startDate.plusYears(startTime);
                    endDate = endDate.plusYears(endTime).minusDays(1);
                }/*from  www .  j  av a2  s . c o m*/

                // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
                if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                    startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
                }
                if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                    endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
                }

                if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
                    aList.add(acr);
                }
            }
        }
    }
    return aList;
}