Mapper: Object mapper default 'date_formats' to also support 'yyyy/MM/dd HH:mm:ss' and 'yyyy/MM/dd', closes #159.

This commit is contained in:
kimchy 2010-05-05 19:45:54 +03:00
parent 71d4f1ce7a
commit db4afc8750
3 changed files with 12 additions and 1 deletions

View File

@ -90,6 +90,7 @@
<w>xcontent</w>
<w>xson</w>
<w>yaml</w>
<w>yyyy</w>
</words>
</dictionary>
</component>

View File

@ -25,6 +25,7 @@ import org.elasticsearch.util.Strings;
import org.elasticsearch.util.collect.ImmutableMap;
import org.elasticsearch.util.concurrent.ThreadSafe;
import org.elasticsearch.util.joda.FormatDateTimeFormatter;
import org.elasticsearch.util.joda.Joda;
import org.elasticsearch.util.xcontent.XContentParser;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
@ -52,7 +53,12 @@ public class XContentObjectMapper implements XContentMapper, XContentIncludeInAl
public static final boolean ENABLED = true;
public static final boolean DYNAMIC = true;
public static final ContentPath.Type PATH_TYPE = ContentPath.Type.FULL;
public static final FormatDateTimeFormatter[] DATE_TIME_FORMATTERS = new FormatDateTimeFormatter[]{XContentDateFieldMapper.Defaults.DATE_TIME_FORMATTER};
public static final FormatDateTimeFormatter[] DATE_TIME_FORMATTERS =
new FormatDateTimeFormatter[]{
XContentDateFieldMapper.Defaults.DATE_TIME_FORMATTER,
Joda.forPattern("yyyy/MM/dd HH:mm:ss"),
Joda.forPattern("yyyy/MM/dd")
};
}
public static class Builder extends XContentMapper.Builder<Builder, XContentObjectMapper> {

View File

@ -69,5 +69,9 @@ public class SimpleJodaTests {
@Test public void testSlashInFormat() {
FormatDateTimeFormatter formatter = Joda.forPattern("MM/yyyy");
formatter.parser().parseMillis("01/2001");
formatter = Joda.forPattern("yyyy/MM/dd HH:mm:ss");
long millis = formatter.parser().parseMillis("2001/01/01 00:00:00");
formatter.printer().print(millis);
}
}