/** * Parses the given date query term into a date representation * * @param dateQueryTerm the date query term as string * @return the milliseconds since 1970 of the given dateQueryTerm * @throws ParseException if the term could not be parsed */ private long parseDate(String dateQueryTerm) throws ParseException { return new DateMathParser().parseMath(dateQueryTerm).getTime(); }
/** * NOTE: declared as a method to allow for extensibility * @lucene.experimental * @return the result of evaluating a string */ protected Date evaluateString(String datemathfmt, Locale locale, TimeZone tz) { // note: DMP does not use the locale but perhaps a subclass might use it, for e.g. parsing a date in a custom // string that doesn't necessarily have date math? //TODO refactor DateMathParser.parseMath a bit to have a static method for this logic. if (datemathfmt.startsWith("NOW")) { datemathfmt = datemathfmt.substring("NOW".length()); } try { DateMathParser parser = new DateMathParser(tz); parser.setNow(new Date());// thus do *not* use SolrRequestInfo return parser.parseMath(datemathfmt); } catch (ParseException e) { throw wrapAndThrow(SEVERE, e, "Invalid expression for date"); } }
final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE); if (null != now) p.setNow(now); try { p.setNow(parseDate(val.substring(0,zz+1))); } catch (ParseException e) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, return p.getNow(); return p.parseMath(math); } catch (ParseException e) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
SuggesionResultInterval intervalResult = new SuggesionResultInterval(limit, limitType); for (String intervalName : intervals.keySet()) { final Date start = DateMathParser.parseMath(new Date(), (String) intervals.get(intervalName).get("start")); final LocalDateTime dateTimeStart = start.toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime(); final Date end = DateMathParser.parseMath(new Date(),(String) intervals.get(intervalName).get("end")); final LocalDateTime dateTimeEnd = end.toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime();
/** * @param tz The TimeZone used for rounding (to determine when hours/days begin) * @param l The Locale used for rounding (to determine when weeks begin) * @see Calendar#getInstance(TimeZone,Locale) */ public DateMathParser(TimeZone tz, Locale l) { zone = tz; loc = l; setNow(new Date()); }
final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE); if (null != now) p.setNow(now); try { p.setNow(parseDateLenient(val.substring(0,zz+1), req)); } catch (ParseException e) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, return p.getNow(); return p.parseMath(math); } catch (ParseException e) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
/** * Parses the timeSeriesAge term with solr date math * * @return the end date for the range query * @throws ParseException if the term is not a solr date math expression */ private Date parseEndDate() throws ParseException { return new DateMathParser().parseMath(String.format("+0MILLISECOND-%s", timeSeriesAge)); }
final DateMathParser dmp = new DateMathParser(ft.UTC, Locale.US); dmp.setNow(NOW); dmp.setNow(low); String label = ft.toExternal(low); Date high = dmp.parseMath(gap); if (end.before(high)) { if (params.getFieldBool(f,FacetParams.FACET_DATE_HARD_END,false)) {
private static boolean intervalDateFacetMatcher(String query) { Matcher dateMatcher = INTERVAL_DATE_FACET.matcher(query); if (dateMatcher.matches()) { DateMathParser solrDateMathParser = new DateMathParser(); try { String startDateMath = dateMatcher.group("dateMathStart"); if (startDateMath != null) { solrDateMathParser.parseMath(startDateMath); } String endDateMath = dateMatcher.group("dateMathStart"); if (endDateMath != null) { solrDateMathParser.parseMath(endDateMath); } } catch (ParseException e) { return false; } String startDate = dateMatcher.group("dateStart"); if (startDate != null) { DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(Long.valueOf(startDate))); } String endDate = dateMatcher.group("dateEnd"); if (endDate != null) { DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(Long.valueOf(endDate))); } return true; } else { return false; } }
return new DateMathParser(TimeZone.getDefault()).parseMath(expr); } catch (ParseException exp) { throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
if (maxCommitAge != null) { if (maxCommitAgeTimeStamp==-1) { DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US); maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();
public static <T> Interval<DateMathExpression> intervalDateFacetMapper(String name, String query) { final Matcher dateMatcher = INTERVAL_DATE_FACET.matcher(query); if (dateMatcher.matches()) { final DateMathParser solrDateMathParser = new DateMathParser(); String startDateMathText = dateMatcher.group("dateMathStart"); if (startDateMathText != null) { solrDateMathParser.parseMath(startDateMathText); String endMath = dateMatcher.group("dateMathEnd"); if (endMath != null) { solrDateMathParser.parseMath(endMath);