From 49c3c01b1c237acf2498112018c679cc253e8d01 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jul 2023 16:11:07 -0600 Subject: [PATCH 1/3] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern --- .../api/gradstudent/util/GradLocalDateTimeDeserializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java index a065b019..d73aa6ac 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java @@ -55,7 +55,7 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d formatter = DateTimeFormatter.ofPattern("yyyy/MM/ddTHH:mm:ss.000+00:00"); return LocalDateTime.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains("T")) { - formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss"); return LocalDateTime.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDateTime.parse(dateAsString, formatter); From 14416b76c1d34202297ec69eec705f913aae600b Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jul 2023 17:00:46 -0600 Subject: [PATCH 2/3] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern --- .../educ/api/gradstudent/model/dto/ReportGradStudentData.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java index 021c9215..35388e75 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java @@ -1,6 +1,5 @@ package ca.bc.gov.educ.api.gradstudent.model.dto; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.io.Serializable; @@ -38,7 +37,6 @@ public class ReportGradStudentData implements Serializable { private String honorsStanding; private String graduated; private String transcriptTypeCode; - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") private LocalDateTime updateDate; private List certificateTypes; private List nonGradReasons; From 799c7ede8a00a918eb2a0e056b1df445f4b7107c Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jul 2023 22:05:55 -0600 Subject: [PATCH 3/3] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern --- .../util/EducGradStudentApiConstants.java | 4 +++- .../util/GradLocalDateDeserializer.java | 6 ++++-- .../util/GradLocalDateTimeDeserializer.java | 18 +++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java index b5e7ff46..22cb62dd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java @@ -107,7 +107,9 @@ public class EducGradStudentApiConstants { public static final String DEFAULT_UPDATED_BY = "API_GRAD_STUDENT"; public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; - public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final String SECOND_DEFAULT_DATE_FORMAT = "yyyy/MM/dd"; + public static final String SECOND_DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss"; public static final String TRAX_DATE_FORMAT = "yyyyMM"; public static final String PROGRAM_COMPLETION_DATE_FORMAT = "yyyy/MM"; public static final String DATE_FORMAT = "yyyy/MM/dd"; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java index 9a9f5420..3baf3f70 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java @@ -12,6 +12,8 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import static ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants.SECOND_DEFAULT_DATE_FORMAT; + public class GradLocalDateDeserializer extends StdDeserializer { public GradLocalDateDeserializer() { @@ -30,7 +32,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser dateAsString = dateAsString + "/01"; } if(slashCount > 0) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); } return LocalDate.parse(dateAsString, formatter); } else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) { @@ -39,7 +41,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("-")) { return LocalDate.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("/")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); return LocalDate.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDate.parse(dateAsString, formatter); diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java index d73aa6ac..1d00179e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java @@ -13,6 +13,8 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import static ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants.*; + public class GradLocalDateTimeDeserializer extends StdDeserializer { public GradLocalDateTimeDeserializer() { @@ -31,31 +33,25 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d dateAsString = dateAsString + "/01"; } if(slashCount > 0) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); } return LocalDateTime.parse(dateAsString, formatter); } else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) { long timestamp = jsonParser.getValueAsLong(); return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("-")) { - formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT); LocalDate localDate = LocalDate.parse(dateAsString, formatter); return localDate.atStartOfDay(); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("/")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + 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(" ")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + 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(" ")) { - formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - return LocalDateTime.parse(dateAsString, formatter); - } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("/") && dateAsString.contains("T")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/ddTHH:mm:ss.000+00:00"); - return LocalDateTime.parse(dateAsString, formatter); - } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains("T")) { - formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss"); + formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT); return LocalDateTime.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDateTime.parse(dateAsString, formatter);