Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSCEXAM-478 Fixes for non-restrictive exception event handling #1134

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions app/util/datetime/DateTimeHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.joda.time.DateTimeZone;
import org.joda.time.Interval;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import util.config.ConfigReader;

public class DateTimeHandlerImpl implements DateTimeHandler {
Expand Down Expand Up @@ -115,13 +114,25 @@ public List<Interval> getExceptionEvents(
DateTime end = new DateTime(ewh.getEndDate()).plusMillis(ewh.getEndDateTimezoneOffset());
Interval exception = new Interval(start, end);
Interval wholeDay = date.toInterval();
// exception covers this day fully
if (exception.contains(wholeDay) || exception.equals(wholeDay)) {
exceptions.clear();
exceptions.add(wholeDay);
break;
}
if (exception.overlaps(wholeDay)) {
exceptions.add(new Interval(exception.getStart(), exception.getEnd()));
} else if (exception.overlaps(wholeDay)) {
// exception starts this day but ends on a later day
if (start.toLocalDate().equals(date) && end.toLocalDate().isAfter(date)) {
exceptions.add(new Interval(exception.getStart(), wholeDay.getEnd()));
}
// exception ends this day but starts on an earlier day
else if (start.toLocalDate().isBefore(date) && end.toLocalDate().equals(date)) {
exceptions.add(new Interval(wholeDay.getStart(), exception.getEnd()));
}
// exception starts and ends this day
else {
exceptions.add(
new Interval(exception.getStart().withDate(date), exception.getEnd().withDate(date))
);
}
}
}
}
Expand Down Expand Up @@ -275,17 +286,9 @@ public List<OpeningHours> getWorkingHoursForDate(LocalDate date, ExamRoom room)
List<Interval> unifiedIntervals = mergeSlots(
Stream.concat(workingHours.stream().map(OpeningHours::getHours), extensionEvents.stream()).toList()
);
int tzOffset;
if (workingHours.isEmpty()) {
LocalTime lt = LocalTime.now().withHourOfDay(java.time.LocalTime.NOON.getHour());
tzOffset = DateTimeZone.forID(room.getLocalTimezone()).getOffset(date.toDateTime(lt));
} else {
tzOffset = workingHours.getFirst().getTimezoneOffset();
}
int offset = DateTimeZone.forID(room.getLocalTimezone()).getOffset(DateTime.now().withDayOfYear(1));
workingHours.clear();
workingHours.addAll(
unifiedIntervals.stream().map(interval -> new OpeningHours(interval, tzOffset)).toList()
);
workingHours.addAll(unifiedIntervals.stream().map(interval -> new OpeningHours(interval, offset)).toList());
}
if (!restrictionEvents.isEmpty()) {
for (OpeningHours hours : workingHours) {
Expand Down