@@ -137,11 +137,11 @@ public class OpenSearchDateType extends OpenSearchDataType {
137137 private static final String CUSTOM_FORMAT_DATE_SYMBOLS = "FecEWwYqQgdMLDyuG" ;
138138
139139 @ EqualsAndHashCode .Exclude
140- String formatString ;
140+ private final List < String > formats ;
141141
142142 private OpenSearchDateType () {
143143 super (MappingType .Date );
144- this .formatString = "" ;
144+ this .formats = List . of () ;
145145 }
146146
147147 private OpenSearchDateType (ExprCoreType exprCoreType ) {
@@ -156,16 +156,20 @@ private OpenSearchDateType(ExprType exprType) {
156156
157157 private OpenSearchDateType (String format ) {
158158 super (MappingType .Date );
159- this .formatString = format ;
159+ this .formats = getFormatList ( format ) ;
160160 this .exprCoreType = getExprTypeFromFormatString (format );
161161 }
162162
163+ public boolean hasFormats () {
164+ return !formats .isEmpty ();
165+ }
166+
163167 /**
164168 * Retrieves and splits a user defined format string from the mapping into a list of formats.
165169 * @return A list of format names and user defined formats.
166170 */
167- private List <String > getFormatList () {
168- String format = strip8Prefix (formatString );
171+ private List <String > getFormatList (String format ) {
172+ format = strip8Prefix (format );
169173 return splitCombinedPatterns (format ).stream ().map (String ::trim ).collect (Collectors .toList ());
170174 }
171175
@@ -174,7 +178,7 @@ private List<String> getFormatList() {
174178 * @return a list of DateFormatters that can be used to parse a Date/Time/Timestamp.
175179 */
176180 public List <DateFormatter > getAllNamedFormatters () {
177- return getFormatList () .stream ()
181+ return formats .stream ()
178182 .filter (formatString -> FormatNames .forName (formatString ) != null )
179183 .map (DateFormatter ::forPattern ).collect (Collectors .toList ());
180184 }
@@ -184,7 +188,7 @@ public List<DateFormatter> getAllNamedFormatters() {
184188 * @return a list of DateFormatters that can be used to parse a Date.
185189 */
186190 public List <DateFormatter > getNumericNamedFormatters () {
187- return getFormatList () .stream ()
191+ return formats .stream ()
188192 .filter (formatString -> {
189193 FormatNames namedFormat = FormatNames .forName (formatString );
190194 return namedFormat != null && SUPPORTED_NAMED_NUMERIC_FORMATS .contains (namedFormat );
@@ -197,7 +201,7 @@ public List<DateFormatter> getNumericNamedFormatters() {
197201 * @return a list of formats as strings that can be used to parse a Date/Time/Timestamp.
198202 */
199203 public List <String > getAllCustomFormats () {
200- return getFormatList () .stream ()
204+ return formats .stream ()
201205 .filter (format -> FormatNames .forName (format ) == null )
202206 .map (format -> {
203207 try {
@@ -217,17 +221,8 @@ public List<String> getAllCustomFormats() {
217221 * @return a list of DateFormatters that can be used to parse a Date/Time/Timestamp.
218222 */
219223 public List <DateFormatter > getAllCustomFormatters () {
220- return getFormatList ().stream ()
221- .filter (format -> FormatNames .forName (format ) == null )
222- .map (format -> {
223- try {
224- return DateFormatter .forPattern (format );
225- } catch (Exception ignored ) {
226- // parsing failed
227- return null ;
228- }
229- })
230- .filter (Objects ::nonNull )
224+ return getAllCustomFormats ().stream ()
225+ .map (DateFormatter ::forPattern )
231226 .collect (Collectors .toList ());
232227 }
233228
@@ -236,7 +231,7 @@ public List<DateFormatter> getAllCustomFormatters() {
236231 * @return a list of DateFormatters that can be used to parse a Date.
237232 */
238233 public List <DateFormatter > getDateNamedFormatters () {
239- return getFormatList () .stream ()
234+ return formats .stream ()
240235 .filter (formatString -> {
241236 FormatNames namedFormat = FormatNames .forName (formatString );
242237 return namedFormat != null && SUPPORTED_NAMED_DATE_FORMATS .contains (namedFormat );
@@ -249,7 +244,7 @@ public List<DateFormatter> getDateNamedFormatters() {
249244 * @return a list of DateFormatters that can be used to parse a Time.
250245 */
251246 public List <DateFormatter > getTimeNamedFormatters () {
252- return getFormatList () .stream ()
247+ return formats .stream ()
253248 .filter (formatString -> {
254249 FormatNames namedFormat = FormatNames .forName (formatString );
255250 return namedFormat != null && SUPPORTED_NAMED_TIME_FORMATS .contains (namedFormat );
@@ -262,7 +257,7 @@ public List<DateFormatter> getTimeNamedFormatters() {
262257 * @return a list of DateFormatters that can be used to parse a DateTime.
263258 */
264259 public List <DateFormatter > getDateTimeNamedFormatters () {
265- return getFormatList () .stream ()
260+ return formats .stream ()
266261 .filter (formatString -> {
267262 FormatNames namedFormat = FormatNames .forName (formatString );
268263 return namedFormat != null && SUPPORTED_NAMED_DATETIME_FORMATS .contains (namedFormat );
@@ -274,17 +269,17 @@ private ExprCoreType getExprTypeFromCustomFormats(List<String> formats) {
274269 boolean isDate = false ;
275270 boolean isTime = false ;
276271
277- for (var format : formats ) {
272+ for (String format : formats ) {
278273 if (!isTime ) {
279- for (var symbol : CUSTOM_FORMAT_TIME_SYMBOLS .toCharArray ()) {
274+ for (char symbol : CUSTOM_FORMAT_TIME_SYMBOLS .toCharArray ()) {
280275 if (format .contains (String .valueOf (symbol ))) {
281276 isTime = true ;
282277 break ;
283278 }
284279 }
285280 }
286281 if (!isDate ) {
287- for (var symbol : CUSTOM_FORMAT_DATE_SYMBOLS .toCharArray ()) {
282+ for (char symbol : CUSTOM_FORMAT_DATE_SYMBOLS .toCharArray ()) {
288283 if (format .contains (String .valueOf (symbol ))) {
289284 isDate = true ;
290285 break ;
@@ -393,7 +388,7 @@ public static OpenSearchDateType of() {
393388
394389 @ Override
395390 public List <ExprType > getParent () {
396- return List .of (this . exprCoreType );
391+ return List .of (exprCoreType );
397392 }
398393
399394 @ Override
@@ -403,9 +398,9 @@ public boolean shouldCast(ExprType other) {
403398
404399 @ Override
405400 protected OpenSearchDataType cloneEmpty () {
406- if (this . formatString .isEmpty ()) {
407- return OpenSearchDateType .of (this . exprCoreType );
401+ if (formats .isEmpty ()) {
402+ return OpenSearchDateType .of (exprCoreType );
408403 }
409- return OpenSearchDateType .of (this . formatString );
404+ return OpenSearchDateType .of (String . join ( " || " , formats ) );
410405 }
411406}
0 commit comments