Mapping - Date Format: 3 or more custom date formats fail using '||' delimiter, closes #977.
This commit is contained in:
parent
ae9857cb45
commit
4cd2f79972
|
@ -21,7 +21,11 @@ package org.elasticsearch.common.joda;
|
|||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.joda.time.DateTimeZone;
|
||||
import org.elasticsearch.common.joda.time.format.*;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormat;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormatter;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormatterBuilder;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeParser;
|
||||
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
|
@ -117,7 +121,7 @@ public class Joda {
|
|||
} else if ("yearMonthDay".equals(input) || "year_month_day".equals(input)) {
|
||||
formatter = ISODateTimeFormat.yearMonthDay();
|
||||
} else {
|
||||
String[] formats = Strings.split(input, "||");
|
||||
String[] formats = Strings.delimitedListToStringArray(input, "||");
|
||||
if (formats == null || formats.length == 1) {
|
||||
formatter = DateTimeFormat.forPattern(input);
|
||||
} else {
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.elasticsearch.common.joda.time.DateTimeZone;
|
|||
import org.elasticsearch.common.joda.time.MutableDateTime;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormat;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormatter;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormatterBuilder;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeParser;
|
||||
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -39,6 +41,19 @@ import static org.hamcrest.Matchers.*;
|
|||
*/
|
||||
public class SimpleJodaTests {
|
||||
|
||||
@Test public void testMultiParsers() {
|
||||
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
|
||||
DateTimeParser[] parsers = new DateTimeParser[3];
|
||||
parsers[0] = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getParser();
|
||||
parsers[1] = DateTimeFormat.forPattern("MM-dd-yyyy").withZone(DateTimeZone.UTC).getParser();
|
||||
parsers[2] = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZone(DateTimeZone.UTC).getParser();
|
||||
builder.append(DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getPrinter(), parsers);
|
||||
|
||||
DateTimeFormatter formatter = builder.toFormatter();
|
||||
|
||||
formatter.parseMillis("2009-11-15 14:12:12");
|
||||
}
|
||||
|
||||
@Test public void testIsoDateFormatDateTimeNoMillisUTC() {
|
||||
DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC);
|
||||
long millis = formatter.parseMillis("1970-01-01T00:00:00Z");
|
||||
|
|
Loading…
Reference in New Issue