Created
December 7, 2020 10:06
-
-
Save kawasima/62bad935b65f0e6de14584693fcdea1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* ルールの時間範囲を表現するクラスです。 | |
*/ | |
public class RulePeriod { | |
private LocalTime startTime; | |
private LocalTime endTime; | |
public RulePeriod(int startHour, int endHour) { | |
startTime = LocalTime.of(startHour, 0); | |
endTime = LocalTime.of(endHour, 0); | |
} | |
/** | |
* 走行記録がこの時間範囲に入っているかを判定します。 | |
*/ | |
public boolean isIn(HighwayDrive drive) { | |
int offset = drive.getEnteredAt().toLocalTime().isBefore(endTime) ? 0 : 1; | |
LocalDateTime start = LocalDateTime.of( | |
LocalDate.from(drive.getEnteredAt().plusDays(offset)), | |
startTime); | |
LocalDateTime end = LocalDateTime.of( | |
LocalDate.from(drive.getExitedAt().plusDays(offset)), | |
endTime); | |
return drive.getEnteredAt().isBefore(end) && drive.getExitedAt().isAfter(start); | |
} | |
/** | |
* 走行記録が休日(土日祝)かを判定します。 | |
*/ | |
public boolean isHoliday(HighwayDrive drive) { | |
int offset = drive.getEnteredAt().toLocalTime().isBefore(endTime) ? 0 : 1; | |
return HolidayUtils.isHoliday(LocalDate.from(drive.getEnteredAt().plusDays(offset))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment