Skip to content

Commit

Permalink
Revert "Fix date parse for yyyy-MM-ddTHH:mm:ss pattern"
Browse files Browse the repository at this point in the history
  • Loading branch information
arybakov-cgi authored Jul 25, 2023
1 parent e00b278 commit 1e5c556
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.bc.gov.educ.api.gradstudent.model.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
Expand Down Expand Up @@ -37,6 +38,7 @@ 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<CertificateType> certificateTypes;
private List<NonGradReason> nonGradReasons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ 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 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 DATETIME_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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
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<LocalDate> {

public GradLocalDateDeserializer() {
Expand All @@ -32,7 +30,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser
dateAsString = dateAsString + "/01";
}
if(slashCount > 0) {
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
}
return LocalDate.parse(dateAsString, formatter);
} else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) {
Expand All @@ -41,7 +39,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(SECOND_DEFAULT_DATE_FORMAT);
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
return LocalDate.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString)) {
return LocalDate.parse(dateAsString, formatter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import static ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants.*;

public class GradLocalDateTimeDeserializer extends StdDeserializer<LocalDateTime> {

public GradLocalDateTimeDeserializer() {
Expand All @@ -33,25 +31,31 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d
dateAsString = dateAsString + "/01";
}
if(slashCount > 0) {
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
}
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(DEFAULT_DATE_FORMAT);
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(dateAsString, formatter);
return localDate.atStartOfDay();
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("/")) {
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate localDate = LocalDate.parse(dateAsString, formatter);
return localDate.atStartOfDay();
} else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("/") && dateAsString.contains(" ")) {
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_TIME_FORMAT);
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(" ")) {
formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT);
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.ISO_OFFSET_DATE_TIME;
return LocalDateTime.parse(dateAsString, formatter);
} else if(StringUtils.isNotBlank(dateAsString)) {
return LocalDateTime.parse(dateAsString, formatter);
Expand Down

0 comments on commit 1e5c556

Please sign in to comment.