Mapping: Root object non ISO date formats to support timezone, closes #1181.

This commit is contained in:
Shay Banon 2011-07-29 20:01:43 +03:00
parent 91f97bb7b6
commit f43bf307c8
2 changed files with 20 additions and 1 deletions

View File

@ -51,7 +51,7 @@ public class RootObjectMapper extends ObjectMapper {
public static final FormatDateTimeFormatter[] DATE_TIME_FORMATTERS =
new FormatDateTimeFormatter[]{
DateFieldMapper.Defaults.DATE_TIME_FORMATTER,
Joda.forPattern("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd")
Joda.forPattern("yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z")
};
public static final boolean DATE_DETECTION = true;
}

View File

@ -21,8 +21,10 @@ package org.elasticsearch.index.mapper.date;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperTests;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.*;
@ -31,6 +33,23 @@ import static org.hamcrest.Matchers.*;
@Test
public class SimpleDateMappingTests {
@Test public void testAutomaticDateParser() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").endObject()
.endObject().endObject().string();
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
.startObject()
.field("date_field", "2011/01/22 00:00:00 +02")
.endObject()
.copiedBytes());
FieldMapper fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field");
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));
}
@Test public void testTimestampAsDate() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("date_field").field("type", "date").endObject().endObject()