From ce39a0b12f4b8ee180cffe1a198784f0991d1297 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Mon, 8 Feb 2010 06:57:53 +0000 Subject: [PATCH] SOLR-1762: DateFormatTransformer does not work correctly with non-default locale dates git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@907562 13f79535-47bb-0310-9956-ffa450edef68 --- contrib/dataimporthandler/CHANGES.txt | 2 ++ .../handler/dataimport/DateFormatTransformer.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/contrib/dataimporthandler/CHANGES.txt b/contrib/dataimporthandler/CHANGES.txt index d55ae8cd8f8..82b294d4f64 100644 --- a/contrib/dataimporthandler/CHANGES.txt +++ b/contrib/dataimporthandler/CHANGES.txt @@ -55,6 +55,8 @@ Bug Fixes * SOLR-1759: $skipDoc was not working correctly (Gian Marco Tagliani via noble) +* SOLR-1762: DateFormatTransformer does not work correctly with non-default locale dates (tommy chheng via noble) + Other Changes ---------------------- diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DateFormatTransformer.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DateFormatTransformer.java index 0d71464b831..aaccadc22bc 100644 --- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DateFormatTransformer.java +++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DateFormatTransformer.java @@ -47,7 +47,14 @@ public class DateFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map aRow, Context context) { + for (Map map : context.getAllEntityFields()) { + Locale locale = Locale.getDefault(); + String customLocale = map.get("locale"); + if(customLocale != null){ + locale = new Locale(customLocale); + } + String fmt = map.get(DATE_TIME_FMT); if (fmt == null) continue; @@ -61,12 +68,12 @@ public class DateFormatTransformer extends Transformer { List inputs = (List) o; List results = new ArrayList(); for (Object input : inputs) { - results.add(process(input, fmt)); + results.add(process(input, fmt, locale)); } aRow.put(column, results); } else { if (o != null) { - aRow.put(column, process(o, fmt)); + aRow.put(column, process(o, fmt, locale)); } } } catch (ParseException e) { @@ -76,14 +83,14 @@ public class DateFormatTransformer extends Transformer { return aRow; } - private Date process(Object value, String format) throws ParseException { + private Date process(Object value, String format, Locale locale) throws ParseException { if (value == null) return null; String strVal = value.toString().trim(); if (strVal.length() == 0) return null; SimpleDateFormat fmt = fmtCache.get(format); if (fmt == null) { - fmt = new SimpleDateFormat(format); + fmt = new SimpleDateFormat(format, locale); fmtCache.put(format, fmt); } return fmt.parse(strVal);