From b31a98e281a982f1b4ec66f99cc47a1a549e0af9 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 25 Jul 2023 10:17:57 -0600 Subject: [PATCH] Fix Date format when T present --- .../util/GradLocalDateTimeDeserializer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java index ebd75d6a..812956cb 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java @@ -47,12 +47,18 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); LocalDate localDate = LocalDate.parse(dateAsString, formatter); return localDate.atStartOfDay(); - } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("/") && dateAsString.contains(" ")) { + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.length() <= 19 && dateAsString.contains("/") && dateAsString.contains(" ")) { formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_TIME_FORMAT); return LocalDateTime.parse(dateAsString, formatter); - } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains(" ")) { + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.length() <= 19 && dateAsString.contains("-") && dateAsString.contains(" ")) { formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT); return LocalDateTime.parse(dateAsString, formatter); + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 19 && dateAsString.contains("/") && dateAsString.contains("T")) { + formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss.000+00:00"); + return LocalDateTime.parse(StringUtils.replace(dateAsString, "T", " "), formatter); + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 19 && dateAsString.contains("-") && dateAsString.contains("T")) { + formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.000+00:00"); + return LocalDateTime.parse(StringUtils.replace(dateAsString, "T", " "), formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDateTime.parse(dateAsString, formatter); }