parse must succeed if the date is already in the expected format

This commit is contained in:
Alessia Bardi 2020-09-07 15:37:40 +02:00
parent 1e3ff13aa4
commit 832b95f064
1 changed files with 11 additions and 5 deletions

View File

@ -15,12 +15,18 @@ public class ESUtils {
.toFormatter(); .toFormatter();
public static String getESFormatDate(String originalDate) { public static String getESFormatDate(String originalDate) {
try { try{
LocalDate parsedDate = LocalDate.parse(originalDate, originalRecordDateFormatter); LocalDate parsedDate = LocalDate.parse(originalDate, elasticSearchDateFormatter);
return parsedDate.format(elasticSearchDateFormatter); return parsedDate.format(elasticSearchDateFormatter);
} catch (Exception e) { } catch(Exception e){
LocalDate parsedDate = LocalDate.parse(originalDate, yearOnlyDateFormatter); try {
return parsedDate.format(yearOnlyDateFormatter); LocalDate parsedDate = LocalDate.parse(originalDate, originalRecordDateFormatter);
return parsedDate.format(elasticSearchDateFormatter);
} catch (Exception e1) {
LocalDate parsedDate = LocalDate.parse(originalDate, yearOnlyDateFormatter);
return parsedDate.format(yearOnlyDateFormatter);
}
} }
} }
} }