List of usage examples for java.time LocalDateTime parse
public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter)
From source file:org.millr.slick.servlets.item.EditItemServlet.java
private Date convertDate(String publishString) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm", Locale.ENGLISH); LocalDateTime dateTime = LocalDateTime.parse(publishString, formatter); Date publishDate = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()); return publishDate; }
From source file:com.objy.se.ClassAccessor.java
public Object getCorrectValue(String strValue, LogicalType logicalType) { Object retValue = null;/* w w w. j a va2 s . c o 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:at.ac.tuwien.qse.sepm.dao.repo.impl.JpegSerializer.java
private void readMetaData(JpegImageMetadata input, PhotoMetadata result) { String tags = ""; if (input.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_USER_COMMENT) != null) { tags = input.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_USER_COMMENT).getValueDescription(); // no tags from our programm if (!tags.contains("travelimg")) return; LOGGER.debug("Tags in exif found: " + tags); tags = tags.replace("'", ""); } else {// w ww. j a v a 2 s. c o m return; } String[] tagArray = tags.split("/"); for (String element : tagArray) { if (element.equals("travelimg")) continue; // journeys if (element.contains("journey")) { String[] tempJourney = element.split("\\|"); LocalDateTime startDate = LocalDateTime.parse(tempJourney[2], DATE_FORMATTER); LocalDateTime endDate = LocalDateTime.parse(tempJourney[3], DATE_FORMATTER); result.setJourney(new Journey(null, tempJourney[1], startDate, endDate)); continue; } // places if (element.contains("place")) { String[] tempPlace = element.split("\\|"); result.setPlace(new Place(0, tempPlace[1], tempPlace[2], Double.parseDouble(tempPlace[3]), Double.parseDouble(tempPlace[4]))); continue; } // rating if (element.contains("rating")) { String[] tempRating = element.split("\\|"); result.setRating(Rating.valueOf(tempRating[1])); continue; } // photographer if (element.contains("photographer")) { String[] tempPhotographer = element.split("\\|"); result.setPhotographer(new Photographer(null, tempPhotographer[1])); continue; } // tags if (!element.trim().isEmpty()) { result.getTags().add(new Tag(null, element)); } } }
From source file:de.elbe5.base.data.XmlData.java
public LocalDateTime getDateAttribute(Node node, String key) { LocalDateTime result = null;// w ww.ja va 2s . c o m if (node.hasAttributes()) { NamedNodeMap attrMap = node.getAttributes(); Node attr = attrMap.getNamedItem(key); if (attr != null) { try { result = LocalDateTime.parse(attr.getNodeValue(), datetimeFormatter); } catch (Exception ignored) { } } } return result; }
From source file:com.jernejerin.traffic.helper.TripOperations.java
/** * Parses passed date time of the pattern "yyyy-MM-dd HH:mm:ss". If the * string representation is malformed then it returns null. * * @param dateTime the string representation of date time * @param defaultValue the default value to return if parse fails * @return parsed date time or null if string representation was null *//*from w ww .j a v a 2 s .co m*/ public static LocalDateTime tryParseDateTime(String dateTime, LocalDateTime defaultValue) { if (dateTime == null) return defaultValue; try { return LocalDateTime.parse(dateTime, formatter); } catch (DateTimeParseException e) { return defaultValue; } }
From source file:com.fanniemae.ezpie.common.StringUtilities.java
public static LocalDateTime toDateTime(String s, LocalDateTime defaultValue) { if (StringUtilities.isNullOrEmpty(s)) return defaultValue; try {/*w w w .j a va 2 s . c om*/ DateTimeFormatter fmt = DateTimeFormatter.ISO_DATE_TIME; return LocalDateTime.parse(s, fmt); } catch (Exception ex) { ExceptionUtilities.goSilent(ex); return defaultValue; } }
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static TaskExecutionResult getTaskExecutionResult(JsonNode node) { JsonNode subTaskRunIdNode = node.get("subTaskRunId"); return new TaskExecutionResult(TaskExecutionStatus.valueOf(node.get("status").asText().toUpperCase()), node.get("message").asText(), getMap(node.get("resultData")), ((subTaskRunIdNode != null) && !subTaskRunIdNode.isNull()) ? new RunId(subTaskRunIdNode.asText()) : null,/*from w w w.jav a 2 s. co m*/ LocalDateTime.parse(node.get("completionTimeUtc").asText(), DateTimeFormatter.ISO_DATE_TIME)); }
From source file:com.github.mavogel.ilias.utils.IOUtils.java
/** * Reads and parses the registration period.<br> * Validates the format and that the start is after the end. * * @return the {@link RegistrationPeriod} *///from ww w . j a v a 2 s. c o m public static RegistrationPeriod readAndParseRegistrationDates() { LOG.info("Date need to be of the format 'yyyy-MM-ddTHH:mm'. E.g.: 2016-04-15T13:00"); // TODO get from the formatter LocalDateTime registrationStart = null, registrationEnd = null; boolean validStart = false, validEnd = false; Scanner scanner = new Scanner(System.in); while (!validStart) { LOG.info("Registration start: "); String line = StringUtils.deleteWhitespace(scanner.nextLine()); try { registrationStart = LocalDateTime.parse(line, Defaults.DATE_FORMAT); validStart = true; } catch (DateTimeParseException dtpe) { LOG.error("'" + line + "' is not a valid date"); } } while (!validEnd) { LOG.info("Registration end: "); String line = scanner.nextLine(); try { registrationEnd = LocalDateTime.parse(line, Defaults.DATE_FORMAT); validEnd = registrationStart.isBefore(registrationEnd); if (!validEnd) { LOG.error("End of registration has to be after the start'" + registrationStart + "'"); } } catch (DateTimeParseException dtpe) { LOG.error("'" + line + "' is not a valid date"); } } return new RegistrationPeriod(registrationStart, registrationEnd); }
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static StartedTask getStartedTask(JsonNode node) { return new StartedTask(node.get("instanceName").asText(), LocalDateTime.parse(node.get("startDateUtc").asText(), DateTimeFormatter.ISO_DATE_TIME)); }
From source file:com.streamsets.pipeline.stage.origin.jdbc.cdc.postgres.PostgresCDCSource.java
private Optional<List<ConfigIssue>> validatePostgresCDCConfigBean(PostgresCDCConfigBean configBean) { List<ConfigIssue> issues = new ArrayList<>(); if (configBean.minVersion == null) { this.getConfigBean().minVersion = PgVersionValues.NINEFOUR; }//from w w w. j a va2 s. co m if (configBean.decoderValue == null) { this.getConfigBean().decoderValue = DecoderValues.WAL2JSON; } if (configBean.replicationType == null) { this.getConfigBean().replicationType = "database"; } switch (configBean.startValue) { case LSN: //Validate startLSN if (configBean.startLSN == null || configBean.startLSN.isEmpty() || (LogSequenceNumber.valueOf(configBean.startLSN).equals(LogSequenceNumber.INVALID_LSN))) { issues.add(getContext().createConfigIssue(Groups.CDC.name(), configBean.startLSN + " is invalid LSN.", JdbcErrors.JDBC_408)); this.setOffset("0/0"); //Valid "non-LSN" LSN or set to latest. } else { this.setOffset(configBean.startLSN); } break; case DATE: //Validate startDate zoneId = ZoneId.of(configBean.dbTimeZone); dateTimeColumnHandler = new DateTimeColumnHandler(zoneId); try { startDate = LocalDateTime.parse(configBean.startDate, DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss")); /* Valid offset that should be as early as possible to get the most number of WAL records available for the date filter to process. */ this.setOffset(LogSequenceNumber.valueOf(1L).asString()); } catch (DateTimeParseException e) { issues.add(getContext().createConfigIssue(Groups.CDC.name(), configBean.startDate + " doesn't parse as DateTime.", JdbcErrors.JDBC_408)); } break; case LATEST: this.setOffset("0/0"); //Valid "non-LSN" LSN or set to latest. break; default: //Should never happen issues.add(getContext().createConfigIssue(Groups.CDC.name(), configBean.startValue.getLabel(), JdbcErrors.JDBC_408)); } return Optional.ofNullable(issues); }