Example usage for java.time LocalDate parse

List of usage examples for java.time LocalDate parse

Introduction

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

Prototype

public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) 

Source Link

Document

Obtains an instance of LocalDate from a text string using a specific formatter.

Usage

From source file:no.kantega.openaksess.search.searchlog.action.ViewSearchLogAction.java

private LocalDate getFromDate(String fromDateParam) {
    return java.util.Optional.ofNullable(defaultIfBlank(fromDateParam, null))
            .map(s -> LocalDate.parse(s, formatter)).orElseGet(() -> LocalDate.now().minusMonths(1));
}

From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingServiceTypeCalendar.java

private void parseCalendarFile(final Reader calendarReader, final Multimap<LocalDate, String> serviceTypesMap)
        throws IOException {

    final CSVParser calendarParser = new CSVParser(calendarReader, CSVFormat.DEFAULT.withHeader());
    final List<CSVRecord> calendarRecords = calendarParser.getRecords();

    LocalDate earliestDate = null;
    LocalDate latestDate = null;/*from   w  ww.  j a  va  2s .  c o m*/
    for (final CSVRecord record : calendarRecords) {
        final String serviceType = record.get("service_id");

        final LocalDate start = LocalDate.parse(record.get("start_date"), DateTimeFormatter.BASIC_ISO_DATE);
        if (earliestDate == null || start.isBefore(earliestDate)) {
            earliestDate = start;
        }

        final LocalDate end = LocalDate.parse(record.get("end_date"), DateTimeFormatter.BASIC_ISO_DATE);
        if (latestDate == null || end.isAfter(latestDate)) {
            latestDate = end;
        }

        final EnumSet<DayOfWeek> daysOfWeek = EnumSet.noneOf(DayOfWeek.class);
        if (record.get("monday").equals("1")) {
            daysOfWeek.add(DayOfWeek.MONDAY);
        }
        if (record.get("tuesday").equals("1")) {
            daysOfWeek.add(DayOfWeek.TUESDAY);
        }
        if (record.get("wednesday").equals("1")) {
            daysOfWeek.add(DayOfWeek.WEDNESDAY);
        }
        if (record.get("thursday").equals("1")) {
            daysOfWeek.add(DayOfWeek.THURSDAY);
        }
        if (record.get("friday").equals("1")) {
            daysOfWeek.add(DayOfWeek.FRIDAY);
        }
        if (record.get("saturday").equals("1")) {
            daysOfWeek.add(DayOfWeek.SATURDAY);
        }
        if (record.get("sunday").equals("1")) {
            daysOfWeek.add(DayOfWeek.SUNDAY);
        }

        LocalDate targetDate = start;
        while (!targetDate.isAfter(end)) {
            if (daysOfWeek.contains(targetDate.getDayOfWeek())) {
                serviceTypesMap.put(targetDate, serviceType);
            }
            targetDate = targetDate.plusDays(1);
        }
    }
}

From source file:no.kantega.openaksess.search.searchlog.action.ViewSearchLogAction.java

private LocalDate getToDate(String toDateParam) {
    return java.util.Optional.ofNullable(defaultIfBlank(toDateParam, null))
            .map(s -> LocalDate.parse(s, formatter)).orElseGet(LocalDate::now);
}

From source file:svc.managers.SMSManagerTest.java

@Test
public void licenseReadMessageGetsGenerated() throws TwiMLException, ParseException {
    setStageInSession(session, SMS_STAGE.READ_LICENSE);
    session.setAttribute("dob", "06/01/1963");
    Citation citation = new Citation();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    citation.citation_date = LocalDate.parse("02/03/1990", formatter);
    List<Citation> citations = new ArrayList<Citation>();
    citations.add(citation);/*from w  ww .  j  a v a 2s . c  om*/

    when(citationManagerMock.findCitations((CitationSearchCriteria) notNull())).thenReturn(citations);

    TwimlMessageRequest twimlMessageRequest = new TwimlMessageRequest();
    twimlMessageRequest.setBody("F917801962");
    String message = "1 ticket was found\n1) ticket from: 02/03/1990\nReply with the ticket number you want to view.";
    MessagingResponse twimlResponse = manager.getTwimlResponse(twimlMessageRequest, requestMock, session);
    assertEquals(createTwimlResponse(message).toXml(), twimlResponse.toXml());
}

From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java

public static LocalDate getLocalDate(final String date, final DateTimeFormatter formatter) {
    return date != null ? LocalDate.parse(date, formatter) : null;
}

From source file:net.straylightlabs.archivo.net.MindCommandRecordingSearch.java

public Recording getRecording() {
    failOnInvalidState();/*from  w  w  w.  jav a  2s  .  c om*/
    Recording.Builder builder = new Recording.Builder();
    logger.trace("Response: {}", response);
    if (response.has("recording")) {
        JSONArray recordingsJSON = response.getJSONArray("recording");
        for (Object obj : recordingsJSON) {
            JSONObject recordingJSON = (JSONObject) obj;
            if (recordingJSON.has(RECORDING_ID))
                builder.recordingId(recordingJSON.getString(RECORDING_ID));
            if (recordingJSON.has(BODY_ID))
                builder.bodyId(recordingJSON.getString(BODY_ID));
            if (recordingJSON.has("title"))
                builder.seriesTitle(recordingJSON.getString("title"));
            if (recordingJSON.has("collectionType"))
                builder.collectionType(recordingJSON.getString("collectionType"));
            if (recordingJSON.has("subtitle"))
                builder.episodeTitle(recordingJSON.getString("subtitle"));
            if (recordingJSON.has("seasonNumber"))
                builder.seriesNumber(recordingJSON.getInt("seasonNumber"));
            if (recordingJSON.has("episodeNum"))
                builder.episodeNumbers(parseEpisodeNumbers(recordingJSON));
            if (recordingJSON.has("duration"))
                builder.secondsLong(recordingJSON.getInt("duration"));
            if (recordingJSON.has("startTime"))
                builder.recordedOn(parseUTCDateTime(recordingJSON.getString("startTime")));
            if (recordingJSON.has("description"))
                builder.description(recordingJSON.getString("description"));
            if (recordingJSON.has("image"))
                builder.image(parseImages(recordingJSON));
            if (recordingJSON.has("channel"))
                builder.channel(parseChannel(recordingJSON));
            if (recordingJSON.has("originalAirdate"))
                builder.originalAirDate(LocalDate.parse(recordingJSON.getString("originalAirdate"),
                        DateTimeFormatter.ofPattern("uuuu-MM-dd")));
            if (recordingJSON.has("state"))
                builder.state(RecordingState.parse(recordingJSON.getString("state")));
            if (recordingJSON.has("subscriptionIdentifier"))
                builder.reason(parseReason(recordingJSON.getJSONArray("subscriptionIdentifier")));
            if (recordingJSON.has("drm"))
                builder.copyable(parseCopyable(recordingJSON.getJSONObject("drm")));
            if (recordingJSON.has("expectedDeletion"))
                builder.expectedDeletion(parseUTCDateTime(recordingJSON.getString("expectedDeletion")));
        }
    }
    return builder.build();
}

From source file:svc.data.citations.datasources.mock.MockCitationDataSourceTest.java

@SuppressWarnings("unchecked")
@Test/*from   ww w .j ava2  s  . c o  m*/
public void returnsCitationsWhenGivenDOBLastNameAndMultipleMunicipalities() throws ParseException, IOException {
    final Violation VIOLATION = new Violation();
    VIOLATION.id = 4;
    final List<Violation> VIOLATIONS = Lists.newArrayList(VIOLATION);

    final Citation CITATION = new Citation();
    CITATION.id = 3;

    final List<Citation> CITATIONS = Lists.newArrayList(CITATION);

    Resource resource = mock(Resource.class);
    when(resource.getInputStream()).thenReturn(null);
    when(resourceLoader.getResource(CLASSPATH_URL_PREFIX + "sql/citation/get-by-location.sql"))
            .thenReturn(resource);

    when(jdbcTemplate.query(Matchers.anyString(), Matchers.anyMap(), Matchers.<RowMapper<Citation>>any()))
            .thenReturn(CITATIONS);

    String dateString = "08/05/1965";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    LocalDate date = LocalDate.parse(dateString, formatter);

    List<Citation> citations = mockCitationDataSource.getByNameAndMunicipalitiesAndDOB("someLastName",
            Lists.newArrayList(19L, 20L), date);
    when(violationManagerMock.getViolationsByCitationNumber(Matchers.anyString())).thenReturn(VIOLATIONS);

    assertThat(citations.get(0).id, is(3));
}

From source file:de.mg.stock.server.logic.StockFacade.java

private Optional<LocalDate> toDate(String dateStr) {
    LocalDate since = null;/*w ww  . jav  a  2s .  c  o  m*/
    if (!isEmpty(dateStr)) {
        since = LocalDate.parse(dateStr, ofPattern("ddMMyyyy", Locale.ENGLISH));
    }
    return Optional.ofNullable(since);
}

From source file:mesclasses.model.EleveData.java

public void setDate(String date) {

    this.date.set(LocalDate.parse(date, Constants.DATE_FORMATTER));
}

From source file:svc.managers.SMSManagerTest.java

@Test
public void citationDetailMessageGetsGenerated() throws TwiMLException, ParseException {
    setStageInSession(session, SMS_STAGE.VIEW_CITATION);
    session.setAttribute("dob", "06/01/1963");
    session.setAttribute("license_number", "F917801962");

    Citation citation = new Citation();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    citation.citation_date = LocalDate.parse("02/03/1990", formatter);
    citation.citation_number = "a1234";
    DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm");
    citation.court_dateTime = LocalDateTime.parse("11/20/2015 04:22", formatter2);
    citation.court_id = new HashableEntity<Court>(Court.class, 1L);
    List<Citation> citations = new ArrayList<Citation>();
    citations.add(citation);/*www.  j  a v a 2s. c o m*/

    Court court = new Court();
    court.address = "1 Anystreet";
    court.city = "myCity";
    court.state = "myState";
    court.zip = "myZip";

    Violation violation = new Violation();
    violation.violation_number = "Y246";
    violation.violation_description = "myDescription";
    violation.status = VIOLATION_STATUS.CONT_FOR_PAYMENT;
    violation.fine_amount = new BigDecimal(200.54);
    violation.court_cost = new BigDecimal(22.34);
    List<Violation> violations = new ArrayList<Violation>();
    violations.add(violation);

    when(citationManagerMock.findCitations((CitationSearchCriteria) notNull())).thenReturn(citations);
    when(courtManagerMock.getCourtById(citations.get(0).court_id.getValue())).thenReturn(court);
    when(violationManagerMock.getViolationsByCitationNumber(anyString())).thenReturn(violations);
    TwimlMessageRequest twimlMessageRequest = new TwimlMessageRequest();
    twimlMessageRequest.setBody("1");
    String message = "Ticket Date: 02/03/1990\nCourt Date: 11/20/2015\nCourt Time: 04:22 AM\nTicket #: "
            + citation.citation_number;
    message += "\nCourt Address: " + court.address + " " + court.city + ", " + court.state + " " + court.zip;
    message += "\nViolation #: " + violation.violation_number + "\nViolation: "
            + violation.violation_description;
    message += "\nStatus: " + violation.status.toString();
    message += "\nFine Amount: $" + violation.fine_amount;
    message += "\nCourt Costs: $" + violation.court_cost;
    message += "\nReply with '1' to view another ticket";
    message += "\nReply with '2' for payment options";
    message += "\nReply with '3' to receive text message reminders about this court date";
    message += "\nReply with '4' to remove text message reminders about this court date";
    MessagingResponse twimlResponse = manager.getTwimlResponse(twimlMessageRequest, requestMock, session);
    assertEquals(createTwimlResponse(message).toXml(), twimlResponse.toXml());
}