-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GRAD2-2266: task is completed. (#563)
GRAD2-2266: task is completed.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/DateUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
|
||
} |