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();
public static String getESFormatDate(String originalDate) {
try {
LocalDate parsedDate = LocalDate.parse(originalDate, originalRecordDateFormatter);
try{
LocalDate parsedDate = LocalDate.parse(originalDate, elasticSearchDateFormatter);
return parsedDate.format(elasticSearchDateFormatter);
} catch (Exception e) {
LocalDate parsedDate = LocalDate.parse(originalDate, yearOnlyDateFormatter);
return parsedDate.format(yearOnlyDateFormatter);
} catch(Exception e){
try {
LocalDate parsedDate = LocalDate.parse(originalDate, originalRecordDateFormatter);
return parsedDate.format(elasticSearchDateFormatter);
} catch (Exception e1) {
LocalDate parsedDate = LocalDate.parse(originalDate, yearOnlyDateFormatter);
return parsedDate.format(yearOnlyDateFormatter);
}
}
}
}