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:org.pentaho.metadata.query.model.util.DataTypeDetector.java

License:Open Source License

public static Object getValue(String valueAsString) {
    if (valueAsString != null) {
        DataType type = getDataType(valueAsString);
        switch (type) {
        case STRING:
            return valueAsString;
        case BOOLEAN:
            return BooleanComparator.parseBoolean(valueAsString);
        case NUMERIC:
            return Integer.parseInt(valueAsString);
        // case DOUBLE:
        // return Double.parseDouble(valueAsString);
        case DATE:
            LocalDate localDate = new LocalDate(valueAsString);
            return new Date(new DateTime(localDate.getYear(), localDate.getMonthOfYear(),
                    localDate.getDayOfMonth(), 0, 0, 0, 0).getMillis());
        /*/*from   w  w  w  .j  av  a  2 s. c  o  m*/
         * case TIME: LocalTime localTime = new LocalTime(valueAsString); return new Time(new DateTime(1970, 1, 1,
         * localTime .getHourOfDay(), localTime.getMinuteOfHour(), localTime .getSecondOfMinute(),
         * localTime.getMillisOfSecond()) .getMillis());
         */
        default:
            throw new IllegalStateException(
                    Messages.getErrorString("DataTypeDetector.ERROR_0001_UNSUPPORTED_COLUMN_TYPE", type)); //$NON-NLS-1$
        }
    }
    return null;
}

From source file:org.springframework.ws.samples.airline.schema.support.SchemaConversionUtils.java

License:Apache License

public static XMLGregorianCalendar toXMLGregorianCalendar(LocalDate localDate)
        throws DatatypeConfigurationException {
    DatatypeFactory factory = DatatypeFactory.newInstance();
    return factory.newXMLGregorianCalendarDate(localDate.getYear(), localDate.getMonthOfYear(),
            localDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED);
}

From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java

License:Apache License

protected CalendarItem[] buildDayItems() {

    LocalDate calendarFirstDay = getCalendarFirstDay();
    LocalDate calendarLastDay = getCalendarLastDay();

    LocalDate firstDayOfMonth = yearMonthDisplayed.toLocalDate(1);
    LocalDate lastDayOfMonth = yearMonthDisplayed.toLocalDate(1).dayOfMonth().withMaximumValue();

    LocalDate today = LocalDate.now();
    int numberOfDays = Days.daysBetween(calendarFirstDay, calendarLastDay).getDays() + 1;
    LocalDate date = calendarFirstDay;

    CalendarItem[] calendarItems = new CalendarItem[numberOfDays];
    LocalDate currentValue = getLocalDate();
    for (int i = 0; i < numberOfDays; i++, date = date.plusDays(1)) {
        calendarItems[i] = new CalendarItem();

        calendarItems[i].setIndex(i);//  w w w .j  av  a 2s. co m
        if (date.getMonthOfYear() == yearMonthDisplayed.getMonthOfYear()) {
            calendarItems[i].setRelativeDateIndex(date.getDayOfMonth());
        } else {
            calendarItems[i].setRelativeDateIndex(-date.getDayOfMonth());
        }

        String calendarItemContent = null;
        if (cellItemCustomizer != null) {
            calendarItemContent = cellItemCustomizer.renderDay(date, this);
        }

        // fallback to default value
        if (calendarItemContent == null) {
            calendarItemContent = Integer.toString(date.getDayOfMonth());
        }
        calendarItems[i].setText(calendarItemContent);

        StringBuilder style = new StringBuilder();

        if (date.equals(today)) {
            style.append("today ");
        }

        if (currentValue != null && date.equals(currentValue)) {
            style.append("selected ");
        }

        if (date.isBefore(firstDayOfMonth)) {
            style.append("previousmonth ");
            calendarItems[i].setEnabled(!isPreviousMonthDisabled());
        } else if (date.isAfter(lastDayOfMonth)) {
            style.append("nextmonth ");
            calendarItems[i].setEnabled(!isNextMonthDisabled());
        } else {
            style.append("currentmonth ");
            calendarItems[i].setEnabled(isDateEnabled(date));
        }

        if (isWeekend(date)) {
            style.append("weekend ");
        }

        if (cellItemCustomizer != null) {
            String generatedStyle = cellItemCustomizer.getStyle(date, this);
            if (generatedStyle != null) {
                style.append(generatedStyle);
                style.append(" ");
            }

            String tooltip = cellItemCustomizer.getTooltip(date, this);
            if (tooltip != null) {
                calendarItems[i].setTooltip(tooltip);
            }
        }

        String computedStyle = style.toString();
        if (!computedStyle.isEmpty()) {
            calendarItems[i].setStyle(computedStyle);
        }
    }
    return calendarItems;
}

From source file:org.zkoss.ganttz.timetracker.zoom.DetailFourTimeTrackerState.java

License:Open Source License

@Override
protected LocalDate round(LocalDate date, boolean down) {
    if (date.getDayOfMonth() == 1) {
        return date;
    }/*from  www. ja va2 s . c  om*/

    return down ? date.withDayOfMonth(1) : date.plusMonths(1).withDayOfMonth(1);
}

From source file:org.zkoss.ganttz.timetracker.zoom.DetailThreeTimeTrackerState.java

License:Open Source License

@Override
protected LocalDate round(LocalDate date, boolean down) {
    if ((date.getMonthOfYear() == 1 || date.getMonthOfYear() == 7) && date.getDayOfMonth() == 1) {
        return date;
    }//from w ww.j  av  a 2 s.c  o m

    date = date.withDayOfMonth(1);

    if (date.getMonthOfYear() < 7) {
        return down ? date.withMonthOfYear(1) : date.withMonthOfYear(7);
    } else {
        return down ? date.withMonthOfYear(7) : date.plusYears(1).withMonthOfYear(1);
    }
}

From source file:rabbit.data.internal.xml.DatatypeUtil.java

License:Apache License

/**
 * Converts a {@link LocalDate} to {@link XMLGregorianCalendar}. The
 * converted calendar is a date, which means only the year, month and day of
 * month fields are set.//w ww.j  ava  2 s. c o  m
 * 
 * @param cal The calendar to convert from.
 * @return The converted calendar.
 */
public static XMLGregorianCalendar toXmlDate(LocalDate cal) {
    return datatypeFactory.newXMLGregorianCalendarDate(cal.getYear(), cal.getMonthOfYear(), cal.getDayOfMonth(),
            DatatypeConstants.FIELD_UNDEFINED);
}

From source file:rabbit.ui.internal.decorators.RabbitDecorator.java

License:Apache License

private boolean isLastDayOfYear(LocalDate date) {
    return (date.getMonthOfYear() == 12) & (date.getDayOfMonth() == 31);
}

From source file:ru.codemine.ccms.router.SalesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/sales-pass", method = RequestMethod.GET)
public String getSalesPassReport(@RequestParam(required = false) String dateStartStr,
        @RequestParam(required = false) String dateEndStr, @RequestParam(required = false) String mode,
        ModelMap model) {/*from www  . ja  v a2 s  .  c  o m*/

    model.addAllAttributes(utils.prepareModel());

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    List<String> subgridColNames = new ArrayList<>();
    subgridColNames.add("?");

    if (dateStart.getMonthOfYear() == dateEnd.getMonthOfYear()) {
        for (int i = 1; i <= dateEnd.getDayOfMonth(); i++) {
            subgridColNames.add(String.valueOf(i) + dateStart.toString(".MM.YY"));
        }
    } else {
        LocalDate printDate = dateStart;
        while (printDate.isBefore(dateEnd)) {
            subgridColNames.add(printDate.toString("MMM YYYY"));
            printDate = printDate.plusMonths(1);
        }
    }

    subgridColNames.add("");

    model.addAttribute("subgridColNames", subgridColNames);

    return "print".equals(mode) ? "printforms/reports/salesAllFrm" : "reports/sales-pass";
}

From source file:ru.codemine.ccms.router.SalesRouter.java

License:Open Source License

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/sales-pass/details")
public @ResponseBody List<Map<String, Object>> getSalesPassReportDetails(@RequestParam String dateStartStr,
        @RequestParam String dateEndStr, @RequestParam String shopname, ModelMap model) {
    List<Map<String, Object>> recordsList = new ArrayList<>();

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    Integer daysCount = dateEnd.getDayOfMonth();
    Integer counterTotals = 0;/*from w ww  . ja  v  a2  s .  c  o m*/

    List<String> recordNames = new ArrayList<>();
    recordNames.add("?");
    recordNames.add("- ");
    recordNames.add(" ");
    recordNames.add("");
    recordNames.add("");
    recordNames.add(" ");

    Shop shop = shopService.getByName(shopname);

    if (dateStart.getMonthOfYear() == dateEnd.getMonthOfYear()) {
        SalesMeta salesMeta = salesService.getByShopAndDate(shop, dateStart, dateEnd);

        for (int row = 1; row <= recordNames.size(); row++) {
            Map<String, Object> record = new HashMap();
            record.put("info", recordNames.get(row - 1));

            for (int cell = 1; cell <= daysCount; cell++) {
                String cellname = "c" + String.valueOf(cell);
                Sales sale = salesMeta.getByDate(dateStart.withDayOfMonth(cell));
                switch (row) {
                case 1: //?
                    if (shop.isCountersEnabled()) {
                        Counter counter = counterService.getByShopAndDate(shop,
                                dateStart.withDayOfMonth(cell).toDateTime(LocalTime.MIDNIGHT));
                        Integer counterValue = counter == null ? 0 : counter.getIn();
                        record.put(cellname, counterValue);
                        counterTotals += counterValue;
                        if (cell == daysCount)
                            record.put("totals", counterTotals);
                    } else {
                        record.put(cellname, sale.getPassability());
                        counterTotals += sale.getPassability();
                        if (cell == daysCount)
                            record.put("totals", counterTotals);
                    }
                    break;
                case 2: //- 
                    record.put(cellname, sale.getChequeCount());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getChequeCountTotal());
                    break;
                case 3: // 
                    record.put(cellname, sale.getValue());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getValueTotal());
                    break;
                case 4: //
                    record.put(cellname, sale.getCashback());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getCashbackTotal());
                    break;
                case 5: //
                    record.put(cellname, sale.getDayTotal());
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getSalesTotal());
                    break;
                case 6: // 
                    Integer chequeCount = sale.getChequeCount();
                    Double midPrice = chequeCount == 0 ? 0 : sale.getMidPrice();
                    record.put(cellname, midPrice);
                    if (cell == daysCount)
                        record.put("totals", salesMeta.getPeriodMidPrice());
                    break;
                }
            }

            recordsList.add(record);
        }
    } else //    ??
    {
        List<SalesMeta> smList = new ArrayList<>();

        LocalDate tempStartDate = dateStart;
        while (tempStartDate.isBefore(dateEnd)) {
            smList.add(salesService.getByShopAndDate(shop, tempStartDate,
                    tempStartDate.dayOfMonth().withMaximumValue()));
            tempStartDate = tempStartDate.plusMonths(1);
        }

        for (int row = 1; row <= recordNames.size(); row++) {
            Map<String, Object> record = new HashMap();
            record.put("info", recordNames.get(row - 1));

            for (int cell = 1; cell <= smList.size(); cell++) {
                String cellname = "c" + String.valueOf(cell);
                SalesMeta sm = smList.get(cell - 1);
                switch (row) {
                case 1: //?
                    if (shop.isCountersEnabled()) {
                        record.put(cellname, counterService.getPassabilityValueByPeriod(shop, sm.getStartDate(),
                                sm.getEndDate()));
                        if (cell == smList.size())
                            record.put("totals",
                                    counterService.getPassabilityValueByPeriod(shop, dateStart, dateEnd));
                    } else {
                        record.put(cellname, sm.getPassabilityTotal());
                        if (cell == smList.size())
                            record.put("totals",
                                    salesService.getPassabilityValueByPeriod(shop, dateStart, dateEnd));
                    }
                    break;
                case 2: //- 
                    record.put(cellname, sm.getChequeCountTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getCqcountValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 3: // 
                    record.put(cellname, sm.getValueTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 4: //
                    record.put(cellname, sm.getCashbackTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getCashbackValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 5: //
                    record.put(cellname, sm.getSalesTotal());
                    if (cell == smList.size())
                        record.put("totals", salesService.getSalesValueByPeriod(shop, dateStart, dateEnd));
                    break;
                case 6: // 
                    record.put(cellname, sm.getPeriodMidPrice());
                    if (cell == smList.size())
                        record.put("totals", salesService.getMidPriceValueByPeriod(shop, dateStart, dateEnd));
                    break;
                }
            }

            recordsList.add(record);
        }
    }

    return recordsList;
}

From source file:utility.LocalDateSerializer.java

License:Apache License

@Override
public void serialize(LocalDate localDate, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException {

    //        jsonGenerator.writeStartObject();

    jsonGenerator.writeString(String.join("-", String.valueOf(localDate.getYear()),
            String.valueOf(localDate.getMonthOfYear()), String.valueOf(localDate.getDayOfMonth())));
    //        jsonGenerator.writeEndObject();
}