Skip to content

Commit

Permalink
GRAD2-2266: task is completed. (#563)
Browse files Browse the repository at this point in the history
GRAD2-2266: task is completed.
  • Loading branch information
infstar authored Aug 3, 2023
1 parent c8ff74b commit 1f1a589
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.educ.api.gradstudent.model.dto.GraduationStudentRecordHistory;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordHistoryEntity;
import ca.bc.gov.educ.api.gradstudent.util.DateUtils;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiUtils;
import ca.bc.gov.educ.api.gradstudent.util.GradValidation;
import org.modelmapper.ModelMapper;
Expand Down Expand Up @@ -44,6 +45,8 @@ public List<GraduationStudentRecordHistory> transformToDTO (Iterable<GraduationS
for (GraduationStudentRecordHistoryEntity graduationStudentRecordHistoryEntity : graduationStudentRecordHistoryEntities) {
GraduationStudentRecordHistory graduationStudentRecordHistory = modelMapper.map(graduationStudentRecordHistoryEntity, GraduationStudentRecordHistory.class);
graduationStudentRecordHistory.setProgramCompletionDate(EducGradStudentApiUtils.formatDate(graduationStudentRecordHistoryEntity.getProgramCompletionDate(), "yyyy/MM"));
graduationStudentRecordHistory.setCreateDate(DateUtils.toLocalDateTime(graduationStudentRecordHistoryEntity.getCreateDate()));
graduationStudentRecordHistory.setUpdateDate(DateUtils.toLocalDateTime(graduationStudentRecordHistoryEntity.getUpdateDate()));
graduationStudentRecordHistoryList.add(graduationStudentRecordHistory);
}
return graduationStudentRecordHistoryList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ca.bc.gov.educ.api.gradstudent.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public class DateUtils {

private DateUtils(){}

// Date
public static LocalDate toLocalDate(Date date) {
if(date == null) return null;
return date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}

public static Date toDate(LocalDate localDate) {
if(localDate == null) return null;
return Date.from(localDate.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
}

// DateTime
public static LocalDateTime toLocalDateTime(Date date) {
if(date == null) return null;
return date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}

public static Date toDate(LocalDateTime localDateTime) {
if(localDateTime == null) return null;
return Date.from(localDateTime
.atZone(ZoneId.systemDefault())
.toInstant());
}


}

0 comments on commit 1f1a589

Please sign in to comment.