@Test public void testHttpSourceDateRegexpPattern000() throws ParseException { String dateRegexp = "By.*on (.*) Tweet"; String dateString = "By Scott Simkin on February 14, 2017 Tweet"; String expectedDateString = "2017-02-14T00:00:00"; MatchedDate matchedDate = new MatchedDate(dateString, null); HttpSource httpSource = new HttpSource(); httpSource.setDateRegexps(Arrays.asList(dateRegexp)); MatchedDate parse = DateParser.parse(matchedDate, httpSource); assertNotNull(parse.getDate()); assertEquals(expectedDateString, DataUtils.formatInUTC(matchedDate.getDate())); }
public static MatchedDate parse(MatchedDate matchedText, HttpSource source) { String value = Strings.nullToEmpty(matchedText.getValue()).trim(); for (String regexp : source.getDateRegexps()) { Pattern pattern = Pattern.compile(regexp); Matcher matcher = pattern.matcher(value); if (matcher.matches() && matcher.groupCount() > 0) { value = matcher.group(1); } } matchedText.setValue(value.replace("ET", "EST")); List<SimpleDateFormat> customFormatters = formatsToFormatters(source.getDateFormats()); MatchedDate md = Stream.concat(customFormatters.stream(), FORMATTERS.stream()) .map(dateFormat -> parse(matchedText, dateFormat)) .filter(matchedDate -> matchedDate.getDate() != null) .findFirst().orElse(matchedText); if (md.getDate() == null && md.getValue() != null) { md = parseWithTimewords(md, source); } return md; }
DateParser { public static MatchedDate parse(MatchedDate matchedText, HttpSource source) { String value = Strings.nullToEmpty(matchedText.getValue()).trim(); for (String regexp : source.getDateRegexps()) { Pattern pattern = Pattern.compile(regexp); Matcher matcher = pattern.matcher(value); if (matcher.matches() && matcher.groupCount() > 0) { value = matcher.group(1); } } matchedText.setValue(value.replace("ET", "EST")); List<SimpleDateFormat> customFormatters = formatsToFormatters(source.getDateFormats()); MatchedDate md = Stream.concat(customFormatters.stream(), FORMATTERS.stream()) .map(dateFormat -> parse(matchedText, dateFormat)) .filter(matchedDate -> matchedDate.getDate() != null) .findFirst().orElse(matchedText); if (md.getDate() == null && md.getValue() != null) { md = parseWithTimewords(md, source); } return md; } }
DateParser { public static MatchedDate parse(MatchedDate matchedText, HttpSource source) { String value = Strings.nullToEmpty(matchedText.getValue()).trim(); for (String regexp : source.getDateRegexps()) { Pattern pattern = Pattern.compile(regexp); Matcher matcher = pattern.matcher(value); if (matcher.matches() && matcher.groupCount() > 0) { value = matcher.group(1); } } matchedText.setValue(value.replace("ET", "EST")); List<SimpleDateFormat> customFormatters = formatsToFormatters(source.getDateFormats()); MatchedDate md = Stream.concat(customFormatters.stream(), FORMATTERS.stream()) .map(dateFormat -> parse(matchedText, dateFormat)) .filter(matchedDate -> matchedDate.getDate() != null) .findFirst().orElse(matchedText); if (md.getDate() == null && md.getValue() != null) { md = parseWithTimewords(md, source); } return md; }  }
DateParser { public static MatchedDate parse(MatchedDate matchedText, HttpSource source) { String value = Strings.nullToEmpty(matchedText.getValue()).trim(); for (String regexp : source.getDateRegexps()) { Pattern pattern = Pattern.compile(regexp); Matcher matcher = pattern.matcher(value); if (matcher.matches() && matcher.groupCount() > 0) { value = matcher.group(1); } } matchedText.setValue(value.replace("ET", "EST")); List<SimpleDateFormat> customFormatters = formatsToFormatters(source.getDateFormats()); MatchedDate md = Stream.concat(customFormatters.stream(), FORMATTERS.stream()) .map(dateFormat -> parse(matchedText, dateFormat)) .filter(matchedDate -> matchedDate.getDate() != null) .findFirst().orElse(matchedText); if (md.getDate() == null && md.getValue() != null) { md = parseWithTimewords(md, source); } return md; }  static MatchedDate parse(MatchedDate matchedText, HttpSource source); static List<MatchedDate> extractFromMeta(Document document); static List<MatchedDate> extractFromProperties(Document document); }
DateParser { public static MatchedDate parse(MatchedDate matchedText, HttpSource source) { String value = Strings.nullToEmpty(matchedText.getValue()).trim(); for (String regexp : source.getDateRegexps()) { Pattern pattern = Pattern.compile(regexp); Matcher matcher = pattern.matcher(value); if (matcher.matches() && matcher.groupCount() > 0) { value = matcher.group(1); } } matchedText.setValue(value.replace("ET", "EST")); List<SimpleDateFormat> customFormatters = formatsToFormatters(source.getDateFormats()); MatchedDate md = Stream.concat(customFormatters.stream(), FORMATTERS.stream()) .map(dateFormat -> parse(matchedText, dateFormat)) .filter(matchedDate -> matchedDate.getDate() != null) .findFirst().orElse(matchedText); if (md.getDate() == null && md.getValue() != null) { md = parseWithTimewords(md, source); } return md; }  static MatchedDate parse(MatchedDate matchedText, HttpSource source); static List<MatchedDate> extractFromMeta(Document document); static List<MatchedDate> extractFromProperties(Document document);  }