mirror of https://github.com/apache/lucene.git
SOLR-4086: fix residual problems with DateFormatEvaluator
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1411366 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
064741fe36
commit
7d67fc2dc8
|
@ -129,15 +129,15 @@ public class DateFormatEvaluator extends Evaluator {
|
|||
String datemathfmt = o.toString();
|
||||
datemathfmt = datemathfmt.replaceAll("NOW", "");
|
||||
try {
|
||||
date = getDateMathParser().parseMath(datemathfmt);
|
||||
date = getDateMathParser(locale).parseMath(datemathfmt);
|
||||
} catch (ParseException e) {
|
||||
wrapAndThrow(SEVERE, e, "Invalid expression for date");
|
||||
}
|
||||
}
|
||||
return sdf.format(date);
|
||||
}
|
||||
static DateMathParser getDateMathParser() {
|
||||
return new DateMathParser(TimeZone.getDefault(), Locale.getDefault()) {
|
||||
static DateMathParser getDateMathParser(Locale l) {
|
||||
return new DateMathParser(TimeZone.getDefault(), l) {
|
||||
@Override
|
||||
public Date getNow() {
|
||||
return new Date();
|
||||
|
|
|
@ -157,7 +157,7 @@ public class FileListEntityProcessor extends EntityProcessorBase {
|
|||
String expr = null;
|
||||
expr = m.group(1).replaceAll("NOW", "");
|
||||
try {
|
||||
return DateFormatEvaluator.getDateMathParser().parseMath(expr);
|
||||
return DateFormatEvaluator.getDateMathParser(Locale.ROOT).parseMath(expr);
|
||||
} catch (ParseException exp) {
|
||||
throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
|
||||
"Invalid expression for date", exp);
|
||||
|
|
|
@ -96,26 +96,20 @@ public class TestVariableResolver extends AbstractDataImportHandlerTestCase {
|
|||
vri.replaceTokens("${dataimporter.functions.formatDate(A.dt,'yyyy-MM-dd HH:mm:ss')}"));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void dateNamespaceWithExpr() throws Exception {
|
||||
VariableResolver vri = new VariableResolver();
|
||||
vri.setEvaluators(new DataImporter().getEvaluators(Collections.<Map<String,String>> emptyList()));
|
||||
vri.setEvaluators(new DataImporter().getEvaluators(Collections
|
||||
.<Map<String,String>> emptyList()));
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
DateMathParser dmp = new DateMathParser(TimeZone.getTimeZone("UTC"), Locale.ROOT);
|
||||
DateMathParser dmp = new DateMathParser(TimeZone.getDefault(), Locale.ROOT);
|
||||
|
||||
/* Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.ROOT);
|
||||
cal.set(Calendar.HOUR, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);*/
|
||||
|
||||
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ROOT);
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
String s = vri.replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd HH:mm')}");
|
||||
assertEquals(format1.format(dmp.parseMath("/DAY")), s);
|
||||
String s = vri
|
||||
.replaceTokens("${dataimporter.functions.formatDate('NOW/DAY','yyyy-MM-dd HH:mm')}");
|
||||
assertEquals(
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ROOT).format(dmp.parseMath("/DAY")),
|
||||
s);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue