Example usage for java.time LocalDate getDayOfMonth

List of usage examples for java.time LocalDate getDayOfMonth

Introduction

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

Prototype

public int getDayOfMonth() 

Source Link

Document

Gets the day-of-month field.

Usage

From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java

/**
 * Generate a year's worth of dates//from  w w  w . j  av a 2 s  .  com
 *
 * @return All the dates for the year
 */
private static List<LocalDate> getYearsDates(final int year) {
    final List<LocalDate> dates = new ArrayList<LocalDate>();
    LocalDate date = LocalDate.of(year, 1, 1);
    do {
        dates.add(date);
        date = date.plusDays(1);
    } while (!(date.getMonthValue() == 1 && date.getDayOfMonth() == 1));
    return dates;
}

From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java

@SuppressWarnings("boxing")
private static RawRiseSet calculateRiseSet(final Location location, final LocalDate date,
        final boolean useDaylightTime, final boolean inDaylightSavings, final TwilightType twilight) {
    if (location != null) {
        sunAlgorithm.setLocation(location.getDescription(),
                location.getPointLocation().getLatitude().getDegrees(),
                location.getPointLocation().getLongitude().getDegrees());
        sunAlgorithm/*w w  w.j  a v a 2 s .  co m*/
                .setTimeZoneOffset(DefaultTimezones.getStandardTimeZoneOffsetHours(location.getTimeZoneId()));
    }
    sunAlgorithm.setDate(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
    final double[] sunriseSunset = sunAlgorithm.calcRiseSet(twilight.getHorizon());

    if (useDaylightTime && inDaylightSavings) {
        if (!Double.isInfinite(sunriseSunset[0])) {
            sunriseSunset[0] = sunriseSunset[0] + 1;
        }
        if (!Double.isInfinite(sunriseSunset[1])) {
            sunriseSunset[1] = sunriseSunset[1] + 1;
        }
    }

    final RawRiseSet riseSet = new RawRiseSet(location, date, useDaylightTime && inDaylightSavings,
            sunriseSunset[0], sunriseSunset[1]);
    return riseSet;

}

From source file:no.imr.stox.functions.acoustic.PgNapesIO.java

public static void convertPgNapesToLuf20(String path, String fileName, String outFileName) {
    try {//from w  w w  . j a  v  a2  s  . co  m
        List<String> acList = Files.readAllLines(Paths.get(path + "/" + fileName + ".txt"));
        List<String> acVList = Files.readAllLines(Paths.get(path + "/" + fileName + "Values.txt"));
        if (acList.isEmpty() || acVList.isEmpty()) {
            return;
        }
        acList.remove(0);
        acVList.remove(0);
        List<DistanceBO> dList = acList.stream().map(s -> {
            DistanceBO d = new DistanceBO();
            String[] str = s.split("\t", 14);
            d.setNation(str[0]);
            d.setPlatform(str[1]);
            d.setCruise(str[2]);
            d.setLog_start(Conversion.safeStringtoDoubleNULL(str[3]));
            d.setStart_time(Date.from(LocalDateTime.of(Conversion.safeStringtoIntegerNULL(str[4]),
                    Conversion.safeStringtoIntegerNULL(str[5]), Conversion.safeStringtoIntegerNULL(str[6]),
                    Conversion.safeStringtoIntegerNULL(str[7]), Conversion.safeStringtoIntegerNULL(str[8]), 0)
                    .toInstant(ZoneOffset.UTC)));
            d.setLat_start(Conversion.safeStringtoDoubleNULL(str[9]));
            d.setLon_start(Conversion.safeStringtoDoubleNULL(str[10]));
            d.setIntegrator_dist(Conversion.safeStringtoDoubleNULL(str[11]));
            FrequencyBO freq = new FrequencyBO();
            d.getFrequencies().add(freq);
            freq.setTranceiver(1); // implicit in pgnapes
            freq.setUpper_interpret_depth(0d);
            freq.setUpper_integrator_depth(0d);
            freq.setDistance(d);
            freq.setFreq(Conversion.safeStringtoIntegerNULL(str[12]));
            freq.setThreshold(Conversion.safeStringtoDoubleNULL(str[13]));
            return d;
        }).collect(Collectors.toList());
        // Fill in sa values
        acVList.forEach(s -> {
            String[] str = s.split("\t", 11);
            String cruise = str[2];
            Double log = Conversion.safeStringtoDoubleNULL(str[3]);
            Integer year = Conversion.safeStringtoIntegerNULL(str[4]);
            Integer month = Conversion.safeStringtoIntegerNULL(str[5]);
            Integer day = Conversion.safeStringtoIntegerNULL(str[6]);
            if (log == null || year == null || month == null || day == null) {
                return;
            }
            DistanceBO d = dList.parallelStream().filter(di -> {
                if (di.getCruise() == null || di.getLog_start() == null || di.getStart_time() == null) {
                    return false;
                }
                LocalDate ld = di.getStart_time().toInstant().atZone(ZoneOffset.UTC).toLocalDate();
                return cruise.equals(di.getCruise()) && log.equals(di.getLog_start())
                        && year.equals(ld.getYear()) && month.equals(ld.getMonthValue())
                        && day.equals(ld.getDayOfMonth());
            }).findFirst().orElse(null);
            if (d == null) {
                return;
            }
            FrequencyBO freq = d.getFrequencies().get(0);

            String species = str[7];
            Integer acocat = PgNapesEchoConvert.getAcoCatFromPgNapesSpecies(species);
            Double chUppDepth = Conversion.safeStringtoDoubleNULL(str[8]);
            Double chLowDepth = Conversion.safeStringtoDoubleNULL(str[9]);
            Double sa = Conversion.safeStringtoDoubleNULL(str[10]);
            if (acocat == null || sa == null || sa == 0d || chLowDepth == null || chUppDepth == null) {
                return;
            }
            if (d.getPel_ch_thickness() == null) {
                d.setPel_ch_thickness(chLowDepth - chUppDepth);
            }
            Integer ch = (int) (chLowDepth / d.getPel_ch_thickness() + 0.5);
            SABO sabo = new SABO();
            sabo.setFrequency(freq);
            freq.getSa().add(sabo);
            sabo.setAcoustic_category(acocat + "");
            sabo.setCh_type("P");
            sabo.setCh(ch);
            sabo.setSa(sa);
        });
        // Calculate number of pelagic channels

        /*dList.stream().forEach(d -> {
        FrequencyBO f = d.getFrequencies().get(0);
        Integer minCh = f.getSa().stream().map(SABO::getCh).min(Integer::compare).orElse(null);
        Integer maxCh = f.getSa().stream().map(SABO::getCh).max(Integer::compare).orElse(null);
        if (maxCh != null && minCh != null) {
            f.setNum_pel_ch(maxCh - minCh + 1);
        }
        });*/

        if (dList.isEmpty()) {
            return;
        }
        DistanceBO d = dList.get(0);
        String cruise = d.getCruise();
        String nation = d.getNation();
        String pl = d.getPlatform();
        ListUser20Writer.export(cruise, nation, pl, path + "/" + cruise + outFileName + ".xml", dList);

    } catch (IOException ex) {
        Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Main.java

/**
 * The adjustInto method accepts a Temporal instance
 * and returns an adjusted LocalDate. If the passed in
 * parameter is not a LocalDate, then a DateTimeException is thrown.
 *//*from w w  w. j a v a 2 s .c o m*/
public Temporal adjustInto(Temporal input) {
    LocalDate date = LocalDate.from(input);
    int day;
    if (date.getDayOfMonth() < 15) {
        day = 15;
    } else {
        day = date.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
    }
    date = date.withDayOfMonth(day);
    if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY) {
        date = date.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY));
    }

    return input.with(date);
}

From source file:org.dozer.converters.LocalDateConverter.java

@Override
public Object convert(Class destClass, Object srcObj) {
    LocalDate convertedValue = null;
    try {//from  w  ww.  j  av  a2s  . c  o  m
        if (srcObj instanceof String) {
            convertedValue = LocalDate.parse((String) srcObj);
        } else {
            LocalDate srcObject = (LocalDate) srcObj;
            convertedValue = LocalDate.of(srcObject.getYear(), srcObject.getMonth(), srcObject.getDayOfMonth());
        }
    } catch (Exception e) {
        MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to LocalDate.", e);
    }
    return convertedValue;
}

From source file:io.sqp.core.types.SqpDateTest.java

@Test(dataProvider = "dateValues")
public void CanDecodeFromJson(byte[] content, DataFormat format) throws Exception {
    ObjectMapper mapper = JacksonObjectMapperFactory.objectMapper(format);

    Object dateObj = mapper.readValue(content, Object.class);
    SqpDate sqpDate = SqpDate.fromJsonFormatValue(dateObj);

    LocalDate localDate = sqpDate.asLocalDate();
    assertThat(localDate.getYear(), is(2015));
    assertThat(localDate.getMonth(), is(Month.JUNE));
    assertThat(localDate.getDayOfMonth(), is(28));
}

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());
        //Calendar calendar = new GregorianCalendar(2015,Calendar.DECEMBER,12);  
        fechasOcupadas.add(calendar);/*from  w  w  w .ja v  a2  s  . c  om*/
    }

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

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

/**
 * {@inheritDoc}/*from   w  w  w .  j a  va  2s.co  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.knime.ext.textprocessing.nodes.transformation.stringstodocument.StringsToDocumentCellFactory2.java

/**
 * {@inheritDoc}/*  ww w . j a va 2 s .  co 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: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);/* ww w  .j a  v  a 2 s. co  m*/

    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
    }
}