Skip to content

Commit

Permalink
Merge pull request #265 from bcgov/develop/alex-GRAD2-2799
Browse files Browse the repository at this point in the history
GRAD2-2799-P3 GRAD Incident: REGALG is creating SCCP certificates for…
  • Loading branch information
arybakov-cgi authored Jun 26, 2024
2 parents 8b020d4 + 0a241d5 commit 2d90c0c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
Expand Down Expand Up @@ -178,7 +179,7 @@ public static String parsingDateForCertificate(String sessionDate) {
String actualSessionDate = sessionDate + "/01";
String sDates = null;
try {
Date temp = parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT);
Date temp = toLastDayOfMonth(parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT));
sDates = formatDate(temp, EducDistributionApiConstants.DEFAULT_DATE_FORMAT);
} catch (ParseException pe) {
logger.error(ERROR,pe.getMessage());
Expand All @@ -190,7 +191,7 @@ public static Date parsingTraxDate(String sessionDate) {
String actualSessionDate = sessionDate + "/01";
Date sDate = null;
try {
Date temp = EducDistributionApiUtils.parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT);
Date temp = toLastDayOfMonth(EducDistributionApiUtils.parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT));
String sDates = EducDistributionApiUtils.formatDate(temp, EducDistributionApiConstants.DEFAULT_DATE_FORMAT);
sDate = EducDistributionApiUtils.parseDate(sDates, EducDistributionApiConstants.DEFAULT_DATE_FORMAT);
} catch (ParseException pe) {
Expand Down Expand Up @@ -253,6 +254,13 @@ public static synchronized void zipFile(File fileToZip, String fileName, ZipOutp
}
}

private static Date toLastDayOfMonth(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
return cal.getTime();
}

/**
public static boolean isValid(File file) {
ZipFile zipfile = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

import static ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT;

Expand All @@ -34,7 +35,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser
if(slashCount > 0) {
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
}
return LocalDate.parse(dateAsString, formatter);
return LocalDate.parse(dateAsString, formatter).with(TemporalAdjusters.lastDayOfMonth());
} else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) {
long timestamp = jsonParser.getValueAsLong();
return LocalDate.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

import static ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants.*;

Expand All @@ -35,7 +36,7 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d
if(slashCount > 0) {
formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT);
}
return LocalDateTime.parse(dateAsString, formatter);
return LocalDateTime.parse(dateAsString, formatter).with(TemporalAdjusters.lastDayOfMonth());
} else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) {
long timestamp = jsonParser.getValueAsLong();
return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
Expand Down

0 comments on commit 2d90c0c

Please sign in to comment.