Skip to content

Commit

Permalink
Added a method to get all the shift instances with working time in a …
Browse files Browse the repository at this point in the history
…given day.
  • Loading branch information
point85 committed Mar 27, 2019
1 parent 6c5bcbf commit 03c1164
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.point85</groupId>
<artifactId>workschedule</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>jar</packaging>

<name>workschedule</name>
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/org/point85/workschedule/ShiftInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,21 @@ public Team getTeam() {
}

/**
* Compare this non-working period to another such period by start time of
* day
* Determine if this time falls within the shift instance period
*
* @param dateTime Date and time to check
* @return True if the specified time is in this shift instance
*/
public boolean isInShiftInstance(LocalDateTime dateTime) {
if (dateTime.compareTo(startDateTime) >= 0 && dateTime.compareTo(getEndTime()) <= 0) {
return true;
} else {
return false;
}
}

/**
* Compare this non-working period to another such period by start time of day
*
* @return -1 if less than, 0 if equal and 1 if greater than
*/
Expand Down
38 changes: 33 additions & 5 deletions src/main/java/org/point85/workschedule/WorkSchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ public List<ShiftInstance> getShiftInstancesForDay(LocalDate day) throws Excepti
return workingShifts;
}

/**
* Get the list of shift instances for the specified date that start in that
* date or cross over from midnight the previous day
*
* @param day LocalDate
* @return List of {@link ShiftInstance}
* @throws Exception exception
*/
public List<ShiftInstance> getAllShiftInstancesForDay(LocalDate day) throws Exception {
// starting in this day
List<ShiftInstance> workingShifts = getShiftInstancesForDay(day);

// now check previous day
LocalDate yesterday = day.minusDays(1);

for (ShiftInstance instance : getShiftInstancesForDay(yesterday)) {
if (instance.getEndTime().toLocalDate().equals(day)) {
// shift ends in this day
workingShifts.add(instance);
}
}

Collections.sort(workingShifts);

return workingShifts;
}

/**
* Get the list of shift instances for the specified date and time of day
*
Expand All @@ -184,15 +211,16 @@ public List<ShiftInstance> getShiftInstancesForDay(LocalDate day) throws Excepti
public List<ShiftInstance> getShiftInstancesForTime(LocalDateTime dateTime) throws Exception {
List<ShiftInstance> workingShifts = new ArrayList<>();

// day
List<ShiftInstance> candidateShifts = getShiftInstancesForDay(dateTime.toLocalDate());

// check time now
// shifts from this date and yesterday
List<ShiftInstance> candidateShifts = getAllShiftInstancesForDay(dateTime.toLocalDate());

for (ShiftInstance instance : candidateShifts) {
if (instance.getShift().isInShift(dateTime.toLocalTime())) {
if (instance.isInShiftInstance(dateTime)) {
workingShifts.add(instance);
}
}

Collections.sort(workingShifts);

return workingShifts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ private void handleSave() {

showErrorDialog(dialogStage, e);
}

handleRefresh();

// show all schedules
displaySchedules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class BaseTest {
protected final LocalDate referenceDate = LocalDate.of(2016, 10, 31);

// partial test flags
protected static boolean testToString = false;
protected static boolean testToString = true;

protected static boolean testDeletions = true;

Expand Down Expand Up @@ -252,7 +252,7 @@ protected void runBaseTest(WorkSchedule ws, Duration hoursPerRotation, Duration
testTeams(ws, hoursPerRotation, rotationDays);

// shift instances
testShiftInstances(ws, instanceReference);
testShiftInstances(ws, instanceReference.plusDays(rotationDays.toDays()));

if (testDeletions) {
testDeletions();
Expand Down

0 comments on commit 03c1164

Please sign in to comment.