浏览代码

Use Locale.ROOT by default to parse dates instead of the system locale.

Closes #3852.
Adrien Grand 12 年之前
父节点
当前提交
7674f1edd4
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java

+ 4 - 3
src/main/java/org/elasticsearch/index/mapper/core/DateFieldMapper.java

@@ -70,7 +70,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
     public static final String CONTENT_TYPE = "date";
 
     public static class Defaults extends NumberFieldMapper.Defaults {
-        public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern("dateOptionalTime");
+        public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern("dateOptionalTime", Locale.ROOT);
 
         public static final FieldType FIELD_TYPE = new FieldType(NumberFieldMapper.Defaults.FIELD_TYPE);
 
@@ -97,6 +97,8 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
         public Builder(String name) {
             super(name, new FieldType(Defaults.FIELD_TYPE));
             builder = this;
+            // do *NOT* rely on the default locale
+            locale = Locale.ROOT;
         }
 
         public Builder timeUnit(TimeUnit timeUnit) {
@@ -121,8 +123,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
                 parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE);
             }
             fieldType.setOmitNorms(fieldType.omitNorms() && boost == 1.0f);
-            if (locale != null && !locale.equals(dateTimeFormatter.locale())) {
-                // this sucks we should use the root local by default and not be dependent on the node if it is null?
+            if (!locale.equals(dateTimeFormatter.locale())) {
                 dateTimeFormatter = new FormatDateTimeFormatter(dateTimeFormatter.format(), dateTimeFormatter.parser(), dateTimeFormatter.printer(), locale);
             }
             DateFieldMapper fieldMapper = new DateFieldMapper(buildNames(context), dateTimeFormatter,