/** * @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()); }
/** * 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"); } }