List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:org.opennms.newts.stress.TimestampOptionHandler.java
License:Apache License
@Override protected Timestamp parse(String argument) throws NumberFormatException, CmdLineException { DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser(); DateTime dateTime = parser.parseDateTime(argument); return Timestamp.fromEpochMillis(dateTime.getMillis()); }
From source file:org.opennms.protocols.http.collector.HttpCollectionHandler.java
License:Open Source License
/** * Gets the time stamp.//from w w w . j a va2s. c o m * * @param document the JSoup document * @param group the group * @return the time stamp */ protected Date getTimeStamp(Document doc, XmlGroup group) { if (group.getTimestampXpath() == null) { return null; } String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat(); LOG.debug( "getTimeStamp: retrieving custom timestamp to be used when updating RRDs using selector {} and pattern {}", group.getTimestampXpath(), pattern); Elements el = doc.select(group.getTimestampXpath()); if (el == null) { return null; } String value = el.html(); Date date = null; try { DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern); DateTime dateTime = dtf.parseDateTime(value); date = dateTime.toDate(); } catch (Exception e) { LOG.warn("getTimeStamp: can't convert custom timetime {} using pattern {}", value, pattern); } return date; }
From source file:org.opennms.protocols.json.collector.AbstractJsonCollectionHandler.java
License:Open Source License
/** * Gets the time stamp.//w ww .j av a 2 s . co m * * @param context the JXPath context * @param group the group * @return the time stamp */ protected Date getTimeStamp(JXPathContext context, XmlGroup group) { if (group.getTimestampXpath() == null) { return null; } String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat(); LOG.debug( "getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH {} and pattern {}", group.getTimestampXpath(), pattern); Date date = null; String value = (String) context.getValue(group.getTimestampXpath()); try { DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern); DateTime dateTime = dtf.parseDateTime(value); date = dateTime.toDate(); } catch (Exception e) { LOG.warn("getTimeStamp: can't convert custom timestamp {} using pattern {}", value, pattern); } return date; }
From source file:org.opennms.protocols.sftp.Sftp3gppUrlConnection.java
License:Open Source License
/** * Gets the time stamp from 3GPP XML file name. * * @param fileName the 3GPP XML file name * @return the time stamp from file/*from w ww. ja v a2s . c o m*/ */ public long getTimeStampFromFile(String fileName) { Pattern p = Pattern.compile("\\w(\\d+)\\.(\\d+)-(\\d+)-(\\d+)-(\\d+)_.+"); Matcher m = p.matcher(fileName); if (m.find()) { String value = m.group(1) + '-' + m.group(4); // Using end date as a reference try { DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMdd-HHmm"); DateTime dateTime = dtf.parseDateTime(value); return dateTime.getMillis(); } catch (Exception e) { LOG.warn("getTimeStampFromFile: malformed 3GPP file {}, because {}", fileName, e.getMessage()); return 0; } } return 0; }
From source file:org.opennms.protocols.xml.collector.AbstractXmlCollectionHandler.java
License:Open Source License
/** * Gets the time stamp.// w w w . j a va 2s . com * * @param doc the doc * @param xpath the xpath * @param group the group * @return the time stamp * @throws XPathExpressionException the x path expression exception */ protected Date getTimeStamp(Document doc, XPath xpath, XmlGroup group) throws XPathExpressionException { if (group.getTimestampXpath() == null) { return null; } String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat(); LOG.debug( "getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH {} and pattern {}", group.getTimestampXpath(), pattern); Node tsNode = (Node) xpath.evaluate(group.getTimestampXpath(), doc, XPathConstants.NODE); if (tsNode == null) { LOG.warn("getTimeStamp: can't find the custom timestamp using XPATH {}", group.getTimestampXpath()); return null; } Date date = null; String value = tsNode.getNodeValue() == null ? tsNode.getTextContent() : tsNode.getNodeValue(); LOG.debug("getTimeStamp: time stamp value is {}", value); try { DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern); DateTime dateTime = dtf.parseDateTime(value); date = dateTime.toDate(); } catch (Exception e) { LOG.warn("getTimeStamp: can't convert custom timetime {} using pattern {}", value, pattern); } return date; }
From source file:org.opennms.protocols.xml.vtdxml.AbstractVTDXmlCollectionHandler.java
License:Open Source License
/** * Gets the time stamp./*from www . ja v a2 s . c o m*/ * * @param document the document * @param group the group * @return the time stamp * @throws XPathParseException the x-path parse exception */ protected Date getTimeStamp(VTDNav document, XmlGroup group) throws XPathParseException { if (group.getTimestampXpath() == null) { return null; } String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat(); LOG.debug( "getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH {} and pattern {}", group.getTimestampXpath(), pattern); document.push(); AutoPilot ap = new AutoPilot(); ap.bind(document); ap.selectXPath(group.getTimestampXpath()); String value = ap.evalXPathToString(); document.pop(); if (value == null || value.isEmpty()) { LOG.warn("getTimeStamp: can't find the custom timestamp using XPATH {}", group.getTimestampXpath()); return null; } Date date = null; try { DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern); DateTime dateTime = dtf.parseDateTime(value); date = dateTime.toDate(); } catch (Exception e) { LOG.warn("getTimeStamp: can't convert custom timetime {} using pattern {}", value, pattern); date = DateTime.now().toDate(); } return date; }
From source file:org.openpplsoft.types.PTDateTime.java
License:MIT License
public PTDateTime(final String initialValue) { super(dateTimeTc); if (initialValue == null) { throw new OPSVMachRuntimeException("Failed to initialize new PTDateTime; " + "initial value is null."); }// ww w . j a va 2s . co m try { final DateTimeFormatter dtf = DateTimeFormat.forPattern(PS_DATE_TIME_FMT1); this.value = dtf.parseDateTime(initialValue); } catch (final java.lang.IllegalArgumentException iae) { final DateTimeFormatter dtf = DateTimeFormat.forPattern(PS_DATE_TIME_FMT2); this.value = dtf.parseDateTime(initialValue); } }
From source file:org.opensextant.mapreduce.XponentsTaggerDemo.java
License:Apache License
/** * /*from w ww . j a va 2s.c o m*/ * @param key * @param cfg * @return * @throws IOException */ public static DateRange parseDateRange(String key, Configuration cfg) throws IOException { String d = cfg.get(key); if (d == null) { return null; } String[] dates = d.split(":"); DateTimeFormatter DATEFMT = DateTimeFormat.forPattern("yyyyMMdd"); DateRange r = new DateRange(); r.startDate = DATEFMT.parseDateTime(dates[0]).getMillis(); r.endDate = DATEFMT.parseDateTime(dates[1]).getMillis(); if (r.isValid()) { return r; } throw new IOException("Date Range is incorrect"); }
From source file:org.opentestsystem.delivery.testreg.domain.constraintvalidators.BirthDateFormatValidator.java
License:Open Source License
@Override public boolean processValidateWithVetoing(String value, ConstraintValidatorContext context) { try {//from w ww .j a va 2 s . c o m DateTimeFormatter dateFormat = DateTimeFormat.forPattern(datePattern); DateTime date = dateFormat.parseDateTime(value); String[] values = value.split("-"); // check if year is 4 digits, month is 2 digits and day is 2 digits if (values[0].length() != 4 || values[1].length() != 2 || values[2].length() != 2) { return false; } if (date.getYear() < 0 || date.getYear() > 9999) { return false; } } catch (IllegalFieldValueException ifve) { return false; } catch (IllegalArgumentException iae) { return false; } return true; }
From source file:org.opentestsystem.delivery.testreg.domain.constraintvalidators.DateFormatValidator.java
License:Open Source License
@Override public boolean processValidateWithVetoing(final String value, final ConstraintValidatorContext context) { try {/* ww w . ja v a2s .com*/ final DateTimeFormatter dateFormat = DateTimeFormat.forPattern(this.datePattern); final DateTime date = dateFormat.parseDateTime(value); // check if year is 4 digits if (String.valueOf(date.getYear()).length() != 4) { return false; } } catch (final IllegalArgumentException e) { return false; } return true; }