Example usage for org.joda.time DateTime dayOfMonth

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

Introduction

In this page you can find the example usage for org.joda.time DateTime 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.wtms.web.controller.application.MeterDemandNoticeController.java

License:Open Source License

/**
 * @param waterConnectionDetails/*from   ww w  .ja va2s .c om*/
 * @param session
 * @param formatter
 * @param assessmentDetails
 * @param ownerName
 * @param billObj
 * @param meterReadingpriviousObj
 * @param monthName
 * @param yearName
 */
private Map<String, Object> prepareReportParams(final WaterConnectionDetails waterConnectionDetails,
        final HttpSession session, final AssessmentDetails assessmentDetails, final String ownerName,
        final EgBill billObj, final MeterReadingConnectionDetails meterReadingPreviousObj) {
    final Format formatterMonth = new SimpleDateFormat("MMMM");
    final Format formatterYear = new SimpleDateFormat("YYYY");
    DateTime dateTime = new DateTime();
    final String monthName;
    final String yearName;
    if (!waterConnectionDetails.getMeterConnection().isEmpty()) {
        final Date currentReadingDate = waterConnectionDetails.getMeterConnection().get(0)
                .getCurrentReadingDate();
        dateTime = new DateTime(currentReadingDate);
        if (dateTime != null) {
            final int currentMidday = dateTime.dayOfMonth().getMaximumValue() / 2;
            final DateTime currentMidDate = new DateTime(currentReadingDate).withDayOfMonth(currentMidday);
            if (currentReadingDate.before(currentMidDate.toDate()))
                dateTime = dateTime.minusMonths(1);
        }
    }
    monthName = formatterMonth.format(dateTime.toDate());
    yearName = formatterYear.format(dateTime.toDate());
    final Map<String, Object> reportParams = new HashMap<>();
    if (WaterTaxConstants.NEWCONNECTION.equalsIgnoreCase(waterConnectionDetails.getApplicationType().getCode())
            || WaterTaxConstants.ADDNLCONNECTION
                    .equalsIgnoreCase(waterConnectionDetails.getApplicationType().getCode()))
        reportParams.put("applicationType",
                WordUtils.capitalize(waterConnectionDetails.getApplicationType().getName()));

    reportParams.put("municipality", session.getAttribute("citymunicipalityname"));
    reportParams.put("district", session.getAttribute("districtName"));
    reportParams.put("waterCharges", waterConnectionDetails.getConnectionType().name());
    reportParams.put("propertyassesmentNumber", waterConnectionDetails.getConnection().getPropertyIdentifier());
    reportParams.put("consumerNumber", waterConnectionDetails.getConnection().getConsumerCode());
    reportParams.put("pipeSize", waterConnectionDetails.getPipeSize().getSizeInInch());
    reportParams.put("mterSerialNumber", waterConnectionDetails.getConnection().getMeterSerialNumber());
    reportParams.put("applicantName", ownerName);
    reportParams.put("demandNoticeNumber",
            billObj != null && billObj.getBillNo() != null ? billObj.getBillNo() : "");
    reportParams.put("billMonth", monthName + "-" + yearName);
    reportParams.put("demandNoticeDate", billObj == null || billObj.getCreateDate() == null ? null
            : toDefaultDateFormat(billObj.getCreateDate()));
    reportParams.put("previousReading", meterReadingPreviousObj.getCurrentReading());
    if (meterReadingPreviousObj.getCurrentReadingDate() == null)
        reportParams.put("previousReadingDate", "");
    else
        reportParams.put("previousReadingDate",
                toDefaultDateFormat(meterReadingPreviousObj.getCurrentReadingDate()));

    reportParams.put("currentReading", waterConnectionDetails.getMeterConnection().get(0).getCurrentReading());
    reportParams.put("currrentReadingDate",
            toDefaultDateFormat(waterConnectionDetails.getMeterConnection().get(0).getCurrentReadingDate()));
    if (meterReadingPreviousObj.getCurrentReading() != null
            && !waterConnectionDetails.getMeterConnection().isEmpty()
            && waterConnectionDetails.getMeterConnection().get(0).getCurrentReading() != null)
        reportParams.put("noofunitsconsume",
                waterConnectionDetails.getMeterConnection().get(0).getCurrentReading()
                        - meterReadingPreviousObj.getCurrentReading());
    reportParams.put("totalBilltoCollect",
            waterConnectionDetailsService.getTotalAmount(waterConnectionDetails));
    reportParams.put("currentMonthCharges",
            getCurrentMonthDemandAmount(waterConnectionDetails, dateTime.toDate()));
    reportParams.put("totalDueAmount", getTotalDue(waterConnectionDetails, dateTime.toDate()));

    reportParams.put("address", assessmentDetails.getPropertyAddress());
    return reportParams;
}

From source file:org.egov.wtms.web.controller.application.MeterReadingController.java

License:Open Source License

@RequestMapping(value = "/meterentry/{consumerCode}", method = RequestMethod.POST)
public String updateMeterEntry(@ModelAttribute final WaterConnectionDetails waterConnectionDetails,
        final BindingResult errors, final RedirectAttributes redirectAttrs, final Model model,
        final HttpServletRequest request) {
    Date givenDate = null;/* ww  w.j  a va2s  .c o  m*/
    if (request.getParameter(METER_CURRENT_READING_DATE) != null)
        givenDate = toDateUsingDefaultPattern(request.getParameter(METER_CURRENT_READING_DATE));
    if (connectionDemandService.meterEntryAllReadyExistForCurrentMonth(waterConnectionDetails, givenDate))
        return REDIRECT_TO_METERDEMANDNOTICE + waterConnectionDetails.getConnection().getConsumerCode();
    final MeterReadingConnectionDetails meterReadingConnectionDetailObj = new MeterReadingConnectionDetails();
    Long previousReading = 0l;
    Long currentReadingValue = null;
    Boolean meterDamaged;
    Boolean currentMonthIncluded = false;
    if ("true".equals(request.getParameter("waterConnectionDetails.meterConnection.isMeterDamaged"))) {
        meterDamaged = true;
        meterReadingConnectionDetailObj.setMeterDamaged(meterDamaged);
    }
    Date currentDate = null;
    Date previousDate = null;
    currentDate = toDateUsingDefaultPattern(request.getParameter(METER_CURRENT_READING_DATE));
    if (request.getParameter("previousreadingDate") != null)
        previousDate = toDateUsingDefaultPattern(request.getParameter("previousreadingDate"));
    if (currentDate != null) {
        final DateTime currentDateTime = new DateTime(currentDate);
        final int midday = currentDateTime.dayOfMonth().getMaximumValue() / 2;
        final DateTime midDate = new DateTime(currentDate).withDayOfMonth(midday);
        final DateTime previousMonthStartDate = new DateTime(currentDate).minusMonths(1).withDayOfMonth(1);

        if (currentDate.before(midDate.toDate())
                && isPreviousMonthDemandExist(previousMonthStartDate, waterConnectionDetails))
            errors.reject("err.invalid.meter.reading.date",
                    new String[] { getFormattedDate(previousMonthStartDate.toDate(), "MMMM YYYY"),
                            getFormattedDate(midDate.toDate(), "dd MMMM YYYY") },
                    "err.invalid.meter.reading.date");
        else if (!currentDate.before(midDate.toDate()))
            currentMonthIncluded = true;
    }

    if (errors.hasErrors()) {
        loadViewData(model, waterConnectionDetails);
        return NEWCONNECTIONMETERENTRY;
    }

    if (isNotBlank(request.getParameter(PREVIOUSREADING)))
        previousReading = Long.valueOf(request.getParameter(PREVIOUSREADING));

    if (isNotBlank(request.getParameter(METERCURRENTREADING)))
        currentReadingValue = Long.valueOf(request.getParameter(METERCURRENTREADING));

    if (currentReadingValue != null && currentReadingValue < previousReading)
        throw new ValidationException("err.invalid.meter.reading");
    final WaterConnectionDetails waterconnectionDetails = billCalculationAndDemandUpdate(waterConnectionDetails,
            request, meterReadingConnectionDetailObj, previousReading, currentDate, previousDate,
            currentMonthIncluded);
    final WaterConnectionDetails savedWaterConnectionDetails = waterConnectionDetailsRepository
            .save(waterconnectionDetails);
    waterConnectionDetailsService.updateIndexes(savedWaterConnectionDetails);
    return REDIRECT_TO_METERDEMANDNOTICE + savedWaterConnectionDetails.getConnection().getConsumerCode();
}

From source file:org.egov.wtms.web.controller.application.MeterReadingController.java

License:Open Source License

private WaterConnectionDetails billCalculationAndDemandUpdate(
        final WaterConnectionDetails waterConnectionDetails, final HttpServletRequest request,
        final MeterReadingConnectionDetails meterReadingConnectionDetailObj, final Long previousReading,
        final Date currentDate, final Date previousDate, final Boolean currentMonthIncluded) {
    int noOfMonths;
    Date previousReadingDate = null;
    if (previousDate != null)
        previousReadingDate = previousDate;
    BigDecimal noOfUnitsPerMonth = BigDecimal.ZERO;
    if (isNotBlank(request.getParameter(METERCURRENTREADING)))
        meterReadingConnectionDetailObj//from w  w  w. j  a va 2s .c om
                .setCurrentReading(Long.valueOf(request.getParameter(METERCURRENTREADING)));
    meterReadingConnectionDetailObj.setCurrentReadingDate(currentDate);
    DateTime previousMidDate = null;
    if (previousReadingDate != null) {
        final DateTime previousDateTime = new DateTime(previousReadingDate);
        final int previousMidday = previousDateTime.dayOfMonth().getMaximumValue() / 2;
        previousMidDate = new DateTime(previousDateTime).withDayOfMonth(previousMidday);
    }
    final DateTime currentDateTime = new DateTime(currentDate);
    final int currentMidday = currentDateTime.dayOfMonth().getMaximumValue() / 2;
    final DateTime currentMidDate = new DateTime(currentDate).withDayOfMonth(currentMidday);

    populateMeterReadingDetails(meterReadingConnectionDetailObj, waterConnectionDetails);
    if (previousReadingDate == null) {
        noOfMonths = noOfMonthsBetween(waterConnectionDetails.getExecutionDate(), currentDate);
        previousReadingDate = waterConnectionDetails.getExecutionDate();
    } else
        noOfMonths = noOfMonthsBetween(previousReadingDate, currentDate);

    if (previousReadingDate != null && previousMidDate != null
            && previousReadingDate.before(previousMidDate.toDate())
            && !currentDate.before(currentMidDate.toDate()))
        noOfMonths++;

    if (!meterReadingConnectionDetailObj.isMeterDamaged()) {
        final Long currentToPreviousDiffOfUnits = Long.valueOf(request.getParameter(METERCURRENTREADING))
                - previousReading;
        if (noOfMonths > 0)
            noOfUnitsPerMonth = BigDecimal.valueOf(currentToPreviousDiffOfUnits)
                    .divide(BigDecimal.valueOf(noOfMonths), 0, BigDecimal.ROUND_HALF_UP);
        else
            noOfUnitsPerMonth = BigDecimal.valueOf(currentToPreviousDiffOfUnits);
    }
    WaterConnectionDetails waterconnectionDetails = null;
    if (meterReadingConnectionDetailObj.isMeterDamaged())
        waterconnectionDetails = calculateDemandForDamagedMeter(waterConnectionDetails, previousReadingDate,
                noOfMonths, currentMonthIncluded);
    else {
        final BigDecimal finalAmountToBePaid = calculateAmountTobePaid(waterConnectionDetails,
                noOfUnitsPerMonth).setScale(0, BigDecimal.ROUND_HALF_UP);

        if (finalAmountToBePaid.compareTo(BigDecimal.ZERO) > 0)
            waterconnectionDetails = connectionDemandService.updateDemandForMeteredConnection(
                    waterConnectionDetails, finalAmountToBePaid, currentDate, previousReadingDate, noOfMonths,
                    currentMonthIncluded);
        else
            throw new ApplicationRuntimeException("err.no.amount.due");
    }
    return waterconnectionDetails;
}

From source file:org.fenixedu.spaces.domain.occupation.config.MonthlyConfig.java

License:Open Source License

private DateTime getNextNthdayOfWeek(DateTime when, int nthdayOfTheWeek, int dayOfTheWeek) {
    DateTime checkpoint = when;
    int month = checkpoint.getMonthOfYear();
    checkpoint = checkpoint.withDayOfMonth(1);
    checkpoint = checkpoint.plusWeeks(month - checkpoint.getMonthOfYear());
    int i = nthdayOfTheWeek;
    if (i > 3) {
        DateTime lastDayOfMonth = checkpoint.dayOfMonth().withMaximumValue();
        lastDayOfMonth = lastDayOfMonth.withDayOfWeek(dayOfTheWeek);
        return lastDayOfMonth.plusWeeks(month - lastDayOfMonth.getMonthOfYear());
    } else {/*w w  w  .jav a2  s  . co  m*/
        return checkpoint.plusWeeks(nthdayOfTheWeek);
    }
}

From source file:org.hawkular.metrics.core.impl.DateTimeService.java

License:Apache License

public DateTime getTimeSlice(DateTime dt, Duration duration) {
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }/*from  w  ww  . j  ava2 s.c  om*/
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.hawkular.metrics.datetime.DateTimeService.java

License:Apache License

public static DateTime getTimeSlice(DateTime dt, Duration duration) {
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }/*ww  w.j ava 2s.  c  o m*/
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.hawkular.metrics.tasks.api.AbstractTrigger.java

License:Apache License

protected DateTime getExecutionTime(long time, Duration duration) {
    DateTime dt = new DateTime(time);
    Period p = duration.toPeriod();

    if (p.getYears() != 0) {
        return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears());
    } else if (p.getMonths() != 0) {
        return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths());
    } else if (p.getWeeks() != 0) {
        return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks());
    } else if (p.getDays() != 0) {
        return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays());
    } else if (p.getHours() != 0) {
        return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours());
    } else if (p.getMinutes() != 0) {
        return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes());
    } else if (p.getSeconds() != 0) {
        return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds());
    }/*from www . j a  v  a 2s .co  m*/
    return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis());
}

From source file:org.itechkenya.leavemanager.api.DateTimeUtil.java

License:Open Source License

/**
 * @param year the year/*  w  ww .  j  a  va  2  s.  c  om*/
 * @param month the month of the year
 * @param day the day of the month
 * 
 * @return a date object representing the year, month and day supplied. If the day is greater than the maximum
 * for the given month, that maximum is used. E.g. 2014,02,31 yields the same result as 2014,02,28.
 */
public static Date createDate(int year, int month, int day) {
    DateTime firstDateTime = new DateTime(year, month, 1, DEFAULT_HOUR, DEFAULT_MINUTE);
    int maxDay = firstDateTime.dayOfMonth().withMaximumValue().getDayOfMonth();
    return new DateTime(year, month, maxDay <= day ? maxDay : day, DEFAULT_HOUR, DEFAULT_MINUTE).toDate();
}

From source file:org.jevis.commons.driver.DataSourceHelper.java

License:Open Source License

private static DateTime getFolderTime(String name, String[] pathStream) {
    String compactDateString = getCompactDateString(name, pathStream);
    String compactDataFormatString = getCompactDateFormatString(name, pathStream);

    DateTimeFormatter dtf = DateTimeFormat.forPattern(compactDataFormatString);

    DateTime parseDateTime = dtf.parseDateTime(compactDateString);
    if (parseDateTime.year().get() == parseDateTime.year().getMinimumValue()) {
        parseDateTime = parseDateTime.year().withMaximumValue();
    }/*from  w  w  w . jav a  2s .  c o m*/
    if (parseDateTime.monthOfYear().get() == parseDateTime.monthOfYear().getMinimumValue()) {
        parseDateTime = parseDateTime.monthOfYear().withMaximumValue();
    }
    if (parseDateTime.dayOfMonth().get() == parseDateTime.dayOfMonth().getMinimumValue()) {
        parseDateTime = parseDateTime.dayOfMonth().withMaximumValue();
    }
    if (parseDateTime.hourOfDay().get() == parseDateTime.hourOfDay().getMinimumValue()) {
        parseDateTime = parseDateTime.hourOfDay().withMaximumValue();
    }
    if (parseDateTime.minuteOfHour().get() == parseDateTime.minuteOfHour().getMinimumValue()) {
        parseDateTime = parseDateTime.minuteOfHour().withMaximumValue();
    }
    if (parseDateTime.secondOfMinute().get() == parseDateTime.secondOfMinute().getMinimumValue()) {
        parseDateTime = parseDateTime.secondOfMinute().withMaximumValue();
    }
    if (parseDateTime.millisOfSecond().get() == parseDateTime.millisOfSecond().getMinimumValue()) {
        parseDateTime = parseDateTime.millisOfSecond().withMaximumValue();
    }
    return parseDateTime;
}

From source file:org.jpos.qi.components.DateRange.java

License:Open Source License

private static Map<String, Date> createStartDateMap() {
    QI app = (QI) UI.getCurrent();/*from   w  ww .j  a  v  a  2  s .co m*/
    DateTime dt = DateTime.now().millisOfDay().withMinimumValue();
    Map<String, Date> map = new HashMap<>();
    map.put(LAST_HOUR, DateTime.now().minusHours(1).toDate());
    map.put(TODAY, dt.toDate());
    map.put(YESTERDAY, dt.minusDays(1).toDate());
    map.put(THIS_WEEK, dt.dayOfWeek().withMinimumValue().toDate());
    map.put(LAST_WEEK, dt.dayOfWeek().withMinimumValue().minusWeeks(1).toDate());
    map.put(THIS_MONTH, dt.dayOfMonth().withMinimumValue().toDate());
    map.put(LAST_MONTH, dt.dayOfMonth().withMinimumValue().minusMonths(1).toDate());
    map.put(THIS_YEAR, dt.dayOfYear().withMinimumValue().toDate());
    map.put(ALL_TIME, null);
    return map;
}