From 0201b83b5d4bc618c68bfedd7aac5a90c3804db9 Mon Sep 17 00:00:00 2001 From: andrefoo <76435197+andrefoo@users.noreply.github.com> Date: Tue, 14 Nov 2023 04:12:28 +0800 Subject: [PATCH 1/2] Fix AddDatedEvent issue When there is a dated event in the past, it stops the user from adding schedules currently. This should not make sense. Fix adding schedules and datedevents to ignore events that have already passed. --- docs/DeveloperGuide.md | 4 ++++ docs/UserGuide.md | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 72ed3e2be51..928d7748365 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -570,6 +570,10 @@ Use case ends. Use case continues from step 1. +* 1d. Event clashes with other events in the schedule. + + Use case continues from step 1. + **Use case: UC08 - Clear list of friends** **MSS** diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 93fe564b4ce..e360516e523 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -237,7 +237,7 @@ Missing prefix(es) for en/ type/ h/ ! * Timeslots added of type `module` will be colored blue, while those of type `CCA` will be colored red. * To add an event that lasts until the end of the day (midnight), set the end timing as `2400`. We know it isn't ideal, but bear with us! -* You will not be allowed to add an event that clashes with any existing events. We are making sure you don't double book! +* You will not be allowed to add an event that clashes with any current or future events. We are making sure you don't double book! @@ -304,7 +304,7 @@ Events added outside the current week are not visible! The application is stream * Timeslots added with this command will be green. * To add an event that lasts until the end of the day (midnight), set the end timing as `2400`. -* You will not be allowed to add an event that clashes with any existing events. +* You will not be allowed to add an event that clashes with any current or future events. Keep those clashes in mind! @@ -608,7 +608,7 @@ Missing prefix(es) for en/ type/ h/ ! * Timeslots added of type `module` will be colored blue, while those of type `CCA` will be colored red. * To add an event that lasts until the end of the day (midnight), set the end timing as `2400`. -* You will not be allowed to add an event that clashes with any existing events. +* You will not be allowed to add an event that clashes with any current or future events. @@ -685,7 +685,7 @@ Missing prefix(es) for en/ h/ r/ ! * Timeslots added with this command will be green. * To add an event that lasts until the end of the day (midnight), set the end timing as `2400`. -* You will not be allowed to add an event that clashes with any existing events. +* You will not be allowed to add an event that clashes with any current or future events. From 88aaa89700fbb1521fadc7bddddac359a4f38501 Mon Sep 17 00:00:00 2001 From: andrefoo <76435197+andrefoo@users.noreply.github.com> Date: Tue, 14 Nov 2023 04:14:08 +0800 Subject: [PATCH 2/2] Fix AddDatedEvent issue When there is a dated event in the past, it stops the user from adding schedules currently. This should not make sense. Fix adding schedules and datedevents to ignore events that have already passed. --- .../model/person/timetable/DatedEvent.java | 27 +++++++++++++ .../model/person/timetable/Schedule.java | 40 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/timetable/DatedEvent.java b/src/main/java/seedu/address/model/person/timetable/DatedEvent.java index 67e0964809b..91623a3ea32 100644 --- a/src/main/java/seedu/address/model/person/timetable/DatedEvent.java +++ b/src/main/java/seedu/address/model/person/timetable/DatedEvent.java @@ -165,6 +165,33 @@ public String getStringForReminder() { return name + " " + super.getTimeBlockString(); } + /** + * Checks if this event's date is before the given date. + * @param date The date to compare with. + * @return true if this event's date is before the given date. + */ + public boolean isBefore(LocalDate date) { + return this.date.isBefore(date); + } + + /** + * Checks if this event overlaps with another event. + * This method assumes that two events overlap if they are on the same date. + * @param event The event to compare with. + * @return true if the events overlap. + */ + public boolean isOverlap(DatedEvent event) { + if (!this.date.equals(event.date)) { + return false; + } + int thisStartTime = Integer.parseInt(this.getStartTime()); + int thisEndTime = Integer.parseInt(this.getEndTime()); + int eventStartTime = Integer.parseInt(event.getStartTime()); + int eventEndTime = Integer.parseInt(event.getEndTime()); + + return thisStartTime < eventEndTime && thisEndTime > eventStartTime; + } + @Override public boolean equals(Object e) { if (e == this) { diff --git a/src/main/java/seedu/address/model/person/timetable/Schedule.java b/src/main/java/seedu/address/model/person/timetable/Schedule.java index 8eff914fe98..9efec242d57 100644 --- a/src/main/java/seedu/address/model/person/timetable/Schedule.java +++ b/src/main/java/seedu/address/model/person/timetable/Schedule.java @@ -371,7 +371,7 @@ public void deleteCca(String ccaName) throws CommandException { } /** - * Returns true if the given event overlaps with any event in the schedule + * Returns true if the given TimeBlock overlaps with any event in the schedule * @param event the event to be checked * @return true if the given event overlaps with any event in the schedule */ @@ -379,12 +379,48 @@ public boolean isOverlapping(TimeBlock event) { List totalList = new ArrayList<>(); totalList.addAll(modulesList); totalList.addAll(ccasList); - totalList.addAll(datedEventsList); for (TimeBlock e : totalList) { if (event.isOverlap(e)) { return true; } } + List datedEventsList = getDatedEventsList(); + LocalDate currentDate = LocalDate.now(); + + for (DatedEvent e : datedEventsList) { + if (!e.isBefore(currentDate)) { + if (event.isOverlap(e)) { + return true; + } + } + } + return false; + } + + /** + * Returns true if the given event overlaps with any event in the schedule + * @param event the event to be checked + * @return true if the given event overlaps with any event in the schedule + */ + public boolean isOverlapping(DatedEvent event) { + List totalList = new ArrayList<>(); + totalList.addAll(modulesList); + totalList.addAll(ccasList); + for (TimeBlock e : totalList) { + if (e.isOverlap(event)) { + return true; + } + } + List datedEventsList = getDatedEventsList(); + LocalDate currentDate = LocalDate.now(); + + for (DatedEvent e : datedEventsList) { + if (!e.isBefore(currentDate)) { + if (event.isOverlap(e)) { + return true; + } + } + } return false; }