Example usage for java.time LocalDate getMonthValue

List of usage examples for java.time LocalDate getMonthValue

Introduction

In this page you can find the example usage for java.time LocalDate getMonthValue.

Prototype

public int getMonthValue() 

Source Link

Document

Gets the month-of-year field from 1 to 12.

Usage

From source file:datojava.jcalendar.DJJCalendar.java

public void fechasOcupadas() throws IOException, ClientProtocolException, JSONException, ParseException {
    for (int i = 0; i < fechasOcupadasArray.length(); i++) {
        JSONObject obj = (JSONObject) fechasOcupadasArray.get(i);
        //Date date = formato.parse(obj.get("diasOcupados").toString());
        LocalDate date = LocalDate.parse(obj.get("diasOcupados").toString(), formatter);
        Calendar calendar = new GregorianCalendar(date.getYear(), date.getMonthValue() - 1,
                date.getDayOfMonth());/*  w w  w. ja  v a 2 s  .  c  o m*/
        //Calendar calendar = new GregorianCalendar(2015,Calendar.DECEMBER,12);  
        fechasOcupadas.add(calendar);
    }

    System.out.println("retorne el djj");
}

From source file:org.knime.ext.textprocessing.nodes.transformation.documentdataassigner.DocumentDataAssignerCellFactory.java

/**
 * {@inheritDoc}/*from  www .ja  v a  2  s.  c o  m*/
 */
@Override
public DataCell[] getCells(final DataRow row) {
    // check if cell contains missing value
    if (!row.getCell(m_conf.getDocumentColumnIndex()).isMissing()) {
        // get document content from incoming table
        Document doc = ((DocumentValue) row.getCell(m_conf.getDocumentColumnIndex())).getDocument();

        // create document builder and set sections from incoming document
        DocumentBuilder docBuilder = new DocumentBuilder(doc);
        docBuilder.setSections(doc.getSections());

        // set authors
        if (m_conf.getAuthorsColumnIndex() >= 0) {
            DataCell authorCell = row.getCell(m_conf.getAuthorsColumnIndex());
            if (!authorCell.isMissing() && authorCell.getType().isCompatible(StringValue.class)) {
                String authors[] = ((StringCell) authorCell).getStringValue()
                        .split(m_conf.getAuthorsSplitStr());
                for (String author : authors) {
                    final String[] names = author.split(" ");
                    if (names.length > 1) {
                        docBuilder.addAuthor(new Author(names[0], names[names.length - 1]));
                    } else {
                        docBuilder.addAuthor(new Author("", names[0]));
                    }
                }
            }
        }

        // set document source
        if (m_conf.getSourceColumnIndex() < 0) {
            if (!m_conf.getDocSource().isEmpty()) {
                docBuilder.addDocumentSource(new DocumentSource(m_conf.getDocSource()));
            }
        } else {
            DataCell sourceCell = row.getCell(m_conf.getSourceColumnIndex());
            if (!sourceCell.isMissing() && sourceCell.getType().isCompatible(StringValue.class)) {
                docBuilder.addDocumentSource(new DocumentSource(((StringCell) sourceCell).getStringValue()));
            }
        }

        // set document category
        if (m_conf.getCategoryColumnIndex() < 0) {
            if (!m_conf.getDocCategory().isEmpty()) {
                docBuilder.addDocumentCategory(new DocumentCategory(m_conf.getDocCategory()));
            }
        } else {
            DataCell categoryCell = row.getCell(m_conf.getCategoryColumnIndex());
            if (!categoryCell.isMissing() && categoryCell.getType().isCompatible(StringValue.class)) {
                docBuilder.addDocumentCategory(
                        new DocumentCategory(((StringCell) categoryCell).getStringValue()));
            }
        }

        // set document type
        docBuilder.setDocumentType(DocumentType.stringToDocumentType(m_conf.getDocType()));

        // set publication date
        if (m_conf.getPubDateColumnIndex() >= 0) {
            final DataCell pubDateCell = row.getCell(m_conf.getPubDateColumnIndex());
            if (!pubDateCell.isMissing()) {
                // new LocalDate type
                LocalDate date = ((LocalDateValue) pubDateCell).getLocalDate();
                setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth());
            }
        } else {
            LocalDate date = m_conf.getDocPubDate();
            setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth());
        }

        // return new data cell
        DataCellCache dataCellCache = getDataCellCache();
        return new DataCell[] { dataCellCache.getInstance(docBuilder.createDocument()) };
    } else {
        // return new missing value cell (if incoming document cell is missing)
        return new DataCell[] { DataType.getMissingCell() };
    }

}

From source file:org.primeframework.mvc.parameter.convert.converters.LocalDateConverterTest.java

@Test
public void fromStrings() {
    GlobalConverter converter = new LocalDateConverter(new MockConfiguration());
    LocalDate value = (LocalDate) converter.convertFromStrings(LocalDate.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(value);/*from  w ww. ja  va2s .  com*/

    value = (LocalDate) converter.convertFromStrings(Locale.class,
            MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr", ArrayUtils.toArray("07-08-2008"));
    assertEquals(value.getMonthValue(), 7);
    assertEquals(value.getDayOfMonth(), 8);
    assertEquals(value.getYear(), 2008);

    try {
        converter.convertFromStrings(Locale.class, MapBuilder.asMap("dateTimeFormat", "MM-dd-yyyy"), "testExpr",
                ArrayUtils.toArray("07/08/2008"));
        fail("Should have failed");
    } catch (ConversionException e) {
        // Expected
    }
}

From source file:org.knime.ext.textprocessing.nodes.transformation.stringstodocument.StringsToDocumentCellFactory2.java

/**
 * {@inheritDoc}/* w  ww  .  ja va  2s. c  o m*/
 */
@Override
public DataCell[] getCells(final DataRow row) {
    final DocumentBuilder docBuilder = new DocumentBuilder(m_tokenizerName);

    // Set title
    if (m_config.getUseTitleColumn()) {
        final DataCell titleCell = row.getCell(m_config.getTitleColumnIndex());
        if (!titleCell.isMissing()) {
            docBuilder.addTitle(((StringValue) titleCell).getStringValue());
        }
    } else if (m_config.getTitleMode().contentEquals(StringsToDocumentConfig2.TITLEMODE_ROWID)) {
        docBuilder.addTitle(row.getKey().toString());
    }

    //Set fulltext
    final DataCell textCell = row.getCell(m_config.getFulltextColumnIndex());
    if (!textCell.isMissing()) {
        docBuilder.addSection(((StringValue) textCell).getStringValue(), SectionAnnotation.UNKNOWN);
    }

    // Set authors
    if (m_config.getUseAuthorsColumn()) {
        final DataCell authorsCell = row.getCell(m_config.getAuthorsColumnIndex());
        if (!authorsCell.isMissing()) {
            final String authors = ((StringValue) authorsCell).getStringValue();
            final String[] authorsArr = authors.split(m_config.getAuthorsSplitChar());
            for (String author : authorsArr) {
                String firstName = "";
                String lastName = "";

                final String[] names = author.split(" ");
                if (names.length > 1) {
                    final StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < names.length - 1; i++) {
                        sb.append(names[i]);
                        sb.append(" ");
                    }
                    firstName = sb.toString();
                    lastName = names[names.length - 1];
                } else if (names.length == 1) {
                    lastName = names[0];
                }

                docBuilder.addAuthor(new Author(firstName.trim(), lastName.trim()));
            }
        }
    } else if (!m_config.getAuthorFirstName().isEmpty() || !m_config.getAuthorLastName().isEmpty()) {
        docBuilder.addAuthor(new Author(m_config.getAuthorFirstName(), m_config.getAuthorLastName()));
    }

    // set document source
    if (m_config.getUseSourceColumn()) {
        final DataCell sourceCell = row.getCell(m_config.getSourceColumnIndex());
        if (!sourceCell.isMissing()) {
            docBuilder.addDocumentSource(new DocumentSource(((StringValue) sourceCell).getStringValue()));
        }
    } else if (m_config.getDocSource().length() > 0) {
        docBuilder.addDocumentSource(new DocumentSource(m_config.getDocSource()));
    }

    // set document category
    if (m_config.getUseCatColumn()) {
        final DataCell catCell = row.getCell(m_config.getCategoryColumnIndex());
        if (!catCell.isMissing()) {
            docBuilder.addDocumentCategory(new DocumentCategory(((StringValue) catCell).getStringValue()));
        }
    } else if (m_config.getDocCat().length() > 0) {
        docBuilder.addDocumentCategory(new DocumentCategory(m_config.getDocCat()));
    }

    // set document type
    docBuilder.setDocumentType(DocumentType.stringToDocumentType(m_config.getDocType()));

    // set publication date
    if (m_config.getUsePubDateColumn()) {
        final DataCell pubDateCell = row.getCell(m_config.getPubDateColumnIndex());
        if (!pubDateCell.isMissing()) {
            LocalDate date = ((LocalDateValue) pubDateCell).getLocalDate();
            setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth());
        }
    } else {
        LocalDate date = m_config.getPublicationDate();
        setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth());
    }

    // return datacells cells
    return new DataCell[] { getDataCellCache().getInstance(docBuilder.createDocument()) };
}

From source file:de.jfachwert.rechnung.Rechnungsmonat.java

/**
 * Erzeugt einen gueltigen Rechnungsmonat anhand des uebergebenen
 * {@link LocalDate}s. Will man ein Rechnungsmonat ueber ein
 * {@link java.util.Date} anlegen, muss man es vorher mit
 * {@link java.sql.Date#toLocalDate()} in ein {@link LocalDate} wandeln.
 *
 * @param date Datum/*from  w  w  w . ja  v a 2s  .  co  m*/
 */
public Rechnungsmonat(LocalDate date) {
    this(date.getMonthValue(), date.getYear());
}

From source file:org.knime.ext.textprocessing.nodes.transformation.stringstodocument.StringsToDocumentCellFactory.java

/**
 * {@inheritDoc}//w  ww.j  a va2  s .co m
 */
@Override
public DataCell[] getCells(final DataRow row) {
    final DocumentBuilder docBuilder = new DocumentBuilder(m_tokenizerName);

    // Set title
    String title = m_config.getDocTitle();
    if (m_config.getUseTitleColumn()) {
        if (m_config.getTitleStringIndex() >= 0) {
            final DataCell titleCell = row.getCell(m_config.getTitleStringIndex());
            if (!titleCell.isMissing() && titleCell.getType().isCompatible(StringValue.class)) {
                title = ((StringValue) titleCell).getStringValue();
            } else {
                title = "";
            }
            docBuilder.addTitle(title);
        }
    } else {
        title = row.getKey().toString();
        docBuilder.addTitle(title);
    }

    //Set fulltext
    if (m_config.getFulltextStringIndex() >= 0) {
        final DataCell textCell = row.getCell(m_config.getFulltextStringIndex());
        String fulltext = "";
        if (!textCell.isMissing() && textCell.getType().isCompatible(StringValue.class)) {
            fulltext = ((StringValue) textCell).getStringValue();
        }
        docBuilder.addSection(fulltext, SectionAnnotation.UNKNOWN);
    }

    // Set authors
    if (m_config.getUseAuthorsColumn()) {
        if (m_config.getAuthorsStringIndex() >= 0) {
            final DataCell auhorsCell = row.getCell(m_config.getAuthorsStringIndex());
            if (!auhorsCell.isMissing() && auhorsCell.getType().isCompatible(StringValue.class)) {
                final String authors = ((StringValue) auhorsCell).getStringValue();
                final String[] authorsArr = authors.split(m_config.getAuthorsSplitChar());
                for (String author : authorsArr) {
                    String firstName = m_config.getAuthorFirstName();
                    String lastName = m_config.getAuthorLastName();

                    final String[] names = author.split(" ");
                    if (names.length > 1) {
                        final StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < names.length - 1; i++) {
                            sb.append(names[i]);
                            sb.append(" ");
                        }
                        firstName = sb.toString();
                        lastName = names[names.length - 1];
                    } else if (names.length == 1) {
                        lastName = names[0];
                    }

                    docBuilder.addAuthor(new Author(firstName.trim(), lastName.trim()));
                }
                // If check box is set to use author names from column
                // if author first/last name is not specified and both first and last name in the node dialog
                // component are empty return an empty string.
            } else if (auhorsCell.isMissing()
                    && (!m_config.getAuthorFirstName().isEmpty() || !m_config.getAuthorLastName().isEmpty())) {
                docBuilder.addAuthor(new Author(m_config.getAuthorFirstName(), m_config.getAuthorLastName()));
            }

        }
    } else if (!m_config.getAuthorFirstName().isEmpty() || !m_config.getAuthorLastName().isEmpty()) {
        // if no check box is set to use authors name from column, if both dialog components name are empty
        // return an empty string otherwise return "-" + the one specified.
        docBuilder.addAuthor(new Author(m_config.getAuthorFirstName(), m_config.getAuthorLastName()));
    }

    // set document source
    String docSource = m_config.getDocSource();
    if (m_config.getUseSourceColumn()) {
        if (m_config.getSourceStringIndex() >= 0) {
            final DataCell sourceCell = row.getCell(m_config.getSourceStringIndex());
            if (!sourceCell.isMissing() && sourceCell.getType().isCompatible(StringValue.class)) {
                docSource = ((StringValue) sourceCell).getStringValue();
            } else {
                docSource = "";
            }
        }
    }
    if (docSource.length() > 0) {
        docBuilder.addDocumentSource(new DocumentSource(docSource));
    }

    // set document category
    String docCat = m_config.getDocCat();
    if (m_config.getUseCatColumn()) {
        if (m_config.getCategoryStringIndex() >= 0) {
            final DataCell catCell = row.getCell(m_config.getCategoryStringIndex());
            if (!catCell.isMissing() && catCell.getType().isCompatible(StringValue.class)) {
                docCat = ((StringValue) catCell).getStringValue();
            } else {
                docCat = "";
            }
        }
    }
    if (docCat.length() > 0) {
        docBuilder.addDocumentCategory(new DocumentCategory(docCat));
    }

    // set document type
    docBuilder.setDocumentType(DocumentType.stringToDocumentType(m_config.getDocType()));

    // set publication date
    if (m_config.getUsePubDateColumn()) {
        if (m_config.getPubDateStringIndex() >= 0) {
            final DataCell pubDateCell = row.getCell(m_config.getPubDateStringIndex());
            if (!pubDateCell.isMissing()) {
                // new LocalDate type
                if (pubDateCell.getType().isCompatible(LocalDateValue.class)) {
                    LocalDate date = ((LocalDateValue) pubDateCell).getLocalDate();
                    setPublicationDate(docBuilder, date.getYear(), date.getMonthValue(), date.getDayOfMonth());
                } else if (pubDateCell.getType().isCompatible(DateAndTimeValue.class)) {
                    DateAndTimeValue dateTime = ((DateAndTimeValue) pubDateCell);
                    setPublicationDate(docBuilder, dateTime.getYear(), dateTime.getMonth() + 1,
                            dateTime.getDayOfMonth());
                } else if (pubDateCell.getType().isCompatible(StringValue.class)) {
                    extractAndSetPublicationDate(((StringValue) pubDateCell).getStringValue(), docBuilder);
                }
            }
        }
    } else {
        extractAndSetPublicationDate(m_config.getPublicationDate(), docBuilder);
    }
    DataCellCache dataCellCache = getDataCellCache();
    return new DataCell[] { dataCellCache.getInstance(docBuilder.createDocument()) };
}

From source file:de.jfachwert.rechnung.Rechnungsmonat.java

/**
 * Erzeugt einen gueltigen Rechnungsmonat. Normalerweise sollte der
 * Monat als "7/2017" angegeben werden, es werden aber auch andere
 * Formate wie "Jul-2017" oder "2017-07-14" unterstuetzt.
 * <p>/*w  w w  .  ja v a2 s .  c o  m*/
 * Auch wenn "Jul-2017" und andere Formate als gueltiger Rechnungsmonat
 * erkannt werden, sollte man dies nur vorsichtig einsetzen, da hier mit
 * Brute-Force einfach nur geraten wird, welches Format es sein koennte.
 * </p>
 * 
 * @param monat z.B. "7/2017" fuer Juli 2017
 */
public Rechnungsmonat(String monat) {
    String[] parts = monat.split("/");
    if ((parts.length == 2) && isDigit(parts[0]) && isDigit(parts[1])) {
        this.monate = asMonate(verify(MONTH, parts[0], VALID_MONTH_RANGE),
                verify(YEAR, parts[1], VALID_YEAR_RANGE));
    } else {
        LocalDate date = toLocalDate(monat);
        this.monate = asMonate(date.getMonthValue(), date.getYear());
    }
}

From source file:com.objy.se.ClassAccessor.java

public Object getCorrectValue(String strValue, LogicalType logicalType) {
    Object retValue = null;//w  w w  . j  a va2s  .  co  m
    switch (logicalType) {
    case INTEGER: {
        long attrValue = 0;
        try {
            if (!strValue.equals("")) {
                attrValue = Long.parseLong(strValue);
            }
        } catch (NumberFormatException nfEx) {
            //        System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey());
            nfEx.printStackTrace();
            throw nfEx;
        }
        retValue = Long.valueOf(attrValue);
    }
        break;
    case REAL: {
        double attrValue = 0;
        try {
            if (!strValue.equals("")) {
                attrValue = Double.parseDouble(strValue);
            }
        } catch (NumberFormatException nfEx) {
            //        System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey());
            nfEx.printStackTrace();
            throw nfEx;
        }
        retValue = Double.valueOf(attrValue);
    }
        break;
    case STRING:
        retValue = strValue;
        break;
    case BOOLEAN: {
        if (strValue.equalsIgnoreCase("TRUE") || strValue.equals("1")) {
            retValue = Boolean.valueOf(true);
        } else if (strValue.equalsIgnoreCase("FALSE") || strValue.equals("0")) {
            retValue = Boolean.valueOf(false);
        } else {
            LOG.error("Expected Boolean value but got: {}", strValue);
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;

    case CHARACTER: {
        if (strValue.length() == 1) {
            retValue = Character.valueOf(strValue.charAt(0));
        } else { /* not a char value... report that */
            LOG.error("Expected Character value but got: {}", strValue);
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case DATE: {
        try {
            LocalDate ldate = LocalDate.parse(strValue, dateFormatter);
            //            System.out.println("... ... year: " + ldate.getYear() + " - month:" + ldate.getMonthValue());
            retValue = new com.objy.db.Date(ldate.getYear(), ldate.getMonthValue(), ldate.getDayOfMonth());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case DATE_TIME: {
        try {
            //            System.out.println(".... formatter: " + mapper.getDateTimeFormat());
            LocalDateTime ldt = LocalDateTime.parse(strValue, dateTimeFormatter);
            //            System.out.println("... ... year: " + ldt.getYear() + 
            //                    " - month:" + ldt.getMonthValue() + " - day: " +
            //                    ldt.getDayOfMonth() + " - hour: " + ldt.getHour() +
            //                    " - min: " + ldt.getMinute() + " - sec: " + 
            //                    ldt.getSecond() + " - nsec: " + ldt.getNano() );
            //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL);
            retValue = new com.objy.db.DateTime(ldt.getYear(), ldt.getMonthValue(), ldt.getDayOfMonth(),
                    ldt.getHour(), ldt.getMinute(), ldt.getSecond(), ldt.getNano());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case TIME: {
        try {
            //            System.out.println(".... formatter: " + mapper.getTimeFormat());
            LocalDateTime ltime = LocalDateTime.parse(strValue, dateFormatter);
            //            System.out.println("... ... hour: " + ltime.getHour() +
            //                    " - min: " + ltime.getMinute() + " - sec: " + 
            //                    ltime.getSecond() + " - nsec: " + ltime.getNano() );
            //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL);
            retValue = new com.objy.db.Time(ltime.getHour(), ltime.getMinute(), ltime.getSecond(),
                    ltime.getNano());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
    default: {
        throw new UnsupportedOperationException("LogicalType: " + logicalType + " is not supported!!!");
    }
    }
    return retValue;
}

From source file:Pages.LandingPage.java

private String dateToString(LocalDate date) {
    String fixedDate;/* www  .j  av a 2 s .  c o m*/
    fixedDate = String.valueOf(date.getYear());
    fixedDate += "/" + String.valueOf(date.getDayOfMonth());
    fixedDate += "/" + String.valueOf(date.getMonthValue());
    return fixedDate;
}

From source file:ui.Analyze.java

private void fillPermintaanTgl(LocalDate ld1, LocalDate ld2) {
    thnAkhir.setValue(ld1.getYear());/*from   ww  w.  j av a2  s .c o  m*/
    blnAkhir.setValue(ld1.getMonthValue());
    tglAkhir.setValue(ld1.getDayOfMonth());
    thnAwal.setValue(ld2.getYear());
    blnAwal.setValue(ld2.getMonthValue());
    tglAwal.setValue(ld2.getDayOfMonth());
}