Skip to content

Commit

Permalink
CSCEXAM-478 Fixes for non-restrictive exception event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lupari committed Aug 12, 2024
1 parent 5e6ab08 commit f8045e9
Showing 1 changed file with 18 additions and 15 deletions.
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

0 comments on commit f8045e9

Please sign in to comment.