Skip to content

Commit

Permalink
Reference the same default locale
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop committed Oct 4, 2024
1 parent bf47823 commit b8ee548
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void doValidate(MappingLookup lookup) {
Map<?, ?> configuredSettings = XContentHelper.convertToMap(BytesReference.bytes(builder), false, XContentType.JSON).v2();
configuredSettings = (Map<?, ?>) configuredSettings.values().iterator().next();

// Only type, meta, and format, and locale attributes are allowed:
// Only type, meta, format, and locale attributes are allowed:
configuredSettings.remove("type");
configuredSettings.remove("meta");
configuredSettings.remove("format");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static class Builder extends AbstractScriptFieldType.Builder<DateFieldSc
(n, c, o) -> o == null ? null : LocaleUtils.parse(o.toString()),
RuntimeField.initializerNotSupported(),
(b, n, v) -> {
if (v != null && false == v.equals(Locale.ENGLISH)) {
if (v != null && false == v.equals(DateFieldMapper.DEFAULT_LOCALE)) {
b.field(n, v.toString());
}
},
Expand Down Expand Up @@ -97,7 +97,7 @@ protected AbstractScriptFieldType<?> createFieldType(
OnScriptError onScriptError
) {
String pattern = format.getValue() == null ? DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.pattern() : format.getValue();
Locale locale = this.locale.getValue() == null ? Locale.ENGLISH : this.locale.getValue();
Locale locale = this.locale.getValue() == null ? DateFieldMapper.DEFAULT_LOCALE : this.locale.getValue();
DateFormatter dateTimeFormatter = DateFormatter.forPattern(pattern, supportedVersion).withLocale(locale);
return new DateScriptFieldType(name, factory, dateTimeFormatter, script, meta, onScriptError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class RangeFieldMapper extends FieldMapper {

public static class Defaults {
public static final DateFormatter DATE_FORMATTER = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER;
public static final Locale LOCALE = DateFieldMapper.DEFAULT_LOCALE;
}

// this is private since it has a different default
Expand All @@ -82,7 +83,7 @@ public static class Builder extends FieldMapper.Builder {
private final Parameter<Locale> locale = new Parameter<>(
"locale",
false,
() -> Locale.ENGLISH,
() -> Defaults.LOCALE,
(n, c, o) -> LocaleUtils.parse(o.toString()),
m -> toType(m).locale,
(xContentBuilder, n, v) -> xContentBuilder.field(n, v.toString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public DateTime(StreamInput in) throws IOException {
String formatterPattern = in.readString();
Locale locale = in.getTransportVersion().onOrAfter(TransportVersions.DATE_TIME_DOC_VALUES_LOCALES)
? LocaleUtils.parse(in.readString())
: Locale.ENGLISH; // default to english (also see DateFieldMapper.Builder)
: DateFieldMapper.DEFAULT_LOCALE;
String zoneId = in.readString();
this.timeZone = ZoneId.of(zoneId);
this.formatter = DateFormatter.forPattern(formatterPattern).withZone(this.timeZone).withLocale(locale);
Expand Down

0 comments on commit b8ee548

Please sign in to comment.