[Java.time] Retain prefixed date pattern in formatter (#48703)
JavaDateFormatter should keep the pattern with the prefixed 8 as it will be used for serialisation. The stripped pattern should be used for the enclosed formatters. closes #48698
This commit is contained in:
parent
0a73ba05de
commit
502873b144
|
@ -82,11 +82,6 @@ enum DateFormat {
|
|||
|
||||
@Override
|
||||
Function<String, ZonedDateTime> getFunction(String format, ZoneId zoneId, Locale locale) {
|
||||
// support the 6.x BWC compatible way of parsing java 8 dates
|
||||
if (format.startsWith("8")) {
|
||||
format = format.substring(1);
|
||||
}
|
||||
|
||||
boolean isUtc = ZoneOffset.UTC.equals(zoneId);
|
||||
|
||||
DateFormatter dateFormatter = DateFormatter.forPattern(format)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
"Test Index and Search locale dependent mappings / dates":
|
||||
- skip:
|
||||
version: "all"
|
||||
reason: "Awaits fix: https://github.com/elastic/elasticsearch/issues/39981(Previously: JDK9 only supports this with a special sysproperty added in 6.2.0.)"
|
||||
version: " - 6.1.99"
|
||||
reason: JDK9 only supports this with a special sysproperty added in 6.2.0
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index
|
||||
|
@ -13,7 +13,7 @@
|
|||
properties:
|
||||
date_field:
|
||||
type: date
|
||||
format: "E, d MMM yyyy HH:mm:ss Z"
|
||||
format: "8E, d MMM uuuu HH:mm:ss Z"
|
||||
locale: "de"
|
||||
- do:
|
||||
bulk:
|
||||
|
|
|
@ -129,27 +129,28 @@ public interface DateFormatter {
|
|||
DateMathParser toDateMathParser();
|
||||
|
||||
static DateFormatter forPattern(String input) {
|
||||
|
||||
if (Strings.hasLength(input) == false) {
|
||||
throw new IllegalArgumentException("No date pattern provided");
|
||||
}
|
||||
|
||||
// support the 6.x BWC compatible way of parsing java 8 dates
|
||||
if (input.startsWith("8")) {
|
||||
input = input.substring(1);
|
||||
}
|
||||
|
||||
List<String> patterns = splitCombinedPatterns(input);
|
||||
String format = strip8Prefix(input);
|
||||
List<String> patterns = splitCombinedPatterns(format);
|
||||
List<DateFormatter> formatters = patterns.stream()
|
||||
.map(DateFormatters::forPattern)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (formatters.size() == 1) {
|
||||
return formatters.get(0);
|
||||
}
|
||||
|
||||
return JavaDateFormatter.combined(input, formatters);
|
||||
}
|
||||
|
||||
static String strip8Prefix(String input) {
|
||||
if (input.startsWith("8")) {
|
||||
return input.substring(1);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
static List<String> splitCombinedPatterns(String input) {
|
||||
List<String> patterns = new ArrayList<>();
|
||||
for (String pattern : Strings.delimitedListToStringArray(input, "||")) {
|
||||
|
|
|
@ -339,4 +339,21 @@ public class DocumentMapper implements ToXContentFragment {
|
|||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
return mapping.toXContent(builder, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DocumentMapper{" +
|
||||
"mapperService=" + mapperService +
|
||||
", type='" + type + '\'' +
|
||||
", typeText=" + typeText +
|
||||
", mappingSource=" + mappingSource +
|
||||
", mapping=" + mapping +
|
||||
", documentParser=" + documentParser +
|
||||
", fieldMappers=" + fieldMappers +
|
||||
", objectMappers=" + objectMappers +
|
||||
", hasNestedObjects=" + hasNestedObjects +
|
||||
", deleteTombstoneMetadataFieldMappers=" + Arrays.toString(deleteTombstoneMetadataFieldMappers) +
|
||||
", noopTombstoneMetadataFieldMappers=" + Arrays.toString(noopTombstoneMetadataFieldMappers) +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue