added support for dates like '27-Oct-2022'
This commit is contained in:
parent
f2a33d5352
commit
fa5bce3c39
|
@ -15,6 +15,7 @@ public class ESUtils {
|
|||
private static DateTimeFormatter originalRecordDateFormatter = DateTimeFormatter.ofPattern("dd MMM yyyy");
|
||||
private static DateTimeFormatter elasticSearchDateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
private static DateTimeFormatter fastCatDateFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
|
||||
|
||||
private static ZoneId preferredZone = ZoneId.of("Europe/London");
|
||||
private static DateTimeFormatter BST_FORMATTER = new DateTimeFormatterBuilder()
|
||||
.appendPattern("EEE MMM dd HH:mm:ss ")
|
||||
|
@ -24,6 +25,8 @@ public class ESUtils {
|
|||
private static DateTimeFormatter yearOnlyDateFormatter = new DateTimeFormatterBuilder()
|
||||
.appendPattern("yyyy").toFormatter();
|
||||
|
||||
private static DateTimeFormatter stringMonthDateFormatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
|
||||
|
||||
public static String getESFormatDate(String originalDate) {
|
||||
try{
|
||||
LocalDate parsedDate = LocalDate.parse(originalDate, elasticSearchDateFormatter);
|
||||
|
@ -48,7 +51,12 @@ public class ESUtils {
|
|||
LocalDate parsedDate = LocalDate.parse(originalDate, fastCatDateFormatter);
|
||||
return parsedDate.format(elasticSearchDateFormatter);
|
||||
} catch (Exception e4) {
|
||||
return "0000";
|
||||
try {
|
||||
LocalDate parsedDate = LocalDate.parse(originalDate, stringMonthDateFormatter);
|
||||
return parsedDate.format(elasticSearchDateFormatter);
|
||||
} catch (Exception e5) {
|
||||
return "0000";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,4 +41,13 @@ public class ESUtilsTest {
|
|||
String parsed = ESUtils.getESFormatDate(date);
|
||||
Assert.assertEquals(parsed, "0000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateMonthString(){
|
||||
String date = "27-Oct-2022";
|
||||
String parsed = ESUtils.getESFormatDate(date);
|
||||
System.out.println(parsed);
|
||||
Assert.assertEquals(parsed, "2022-10-27");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue