forked from nusCS2113-AY1920S1/PersonalAssistant-Duke
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from lmtaek/master
[AY1920S1-CS2113-T13-2]-lmtaek-B-RecurringTasks
- Loading branch information
Showing
11 changed files
with
261 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
E | 0 | fsahufias | 30/06/2020 0316 | false | ||
D | 0 | abc | 27/07/1996 2130 | false | ||
E | 0 | fsahufias | 30/06/2020 0316 | ONCE | ||
D | 0 | abc | 24/09/2019 0915 | DAILY | ||
P | 0 | abc | 27/07/1996 2130 | 27/06/2029 1630 | ||
D | 0 | abc | 27/07/1996 2130 | false | ||
T | 1 | abc | false | ||
D | 0 | abc | 17/09/2019 2130 | false | ||
E | 0 | werq | 17/09/2019 1500 | false | ||
T | 0 | homework | false | ||
E | 0 | abc | 06/06/2016 1530 | false | ||
D | 0 | abc | 24/09/2019 1145 | DAILY | ||
T | 1 | abc | DAILY | ||
D | 0 | abc | 17/09/2019 2130 | ONCE | ||
E | 0 | werq | 17/09/2019 1500 | ONCE | ||
T | 0 | homework | ONCE | ||
E | 0 | abc | 24/09/2019 1530 | DAILY | ||
P | 0 | abc | 27/08/2019 1630 | 29/11/2020 1630 | ||
P | 0 | abc | 27/08/2019 1630 | 29/11/2020 1630 | ||
P | 0 | abc | 27/08/2019 1630 | 29/11/2020 1630 | ||
E | 1 | dog | 24/09/2019 0001 | MONTHLY | ||
D | 0 | cat | 11/10/2019 0001 | DAILY | ||
E | 0 | rabbit | 23/09/2019 0909 | WEEKLY |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package duke.task; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class RecurringTask { | ||
|
||
public enum RecurringFrequency { DAILY, WEEKLY, MONTHLY}; | ||
public enum TaskType { TODO, DEADLINE, EVENT} | ||
|
||
private LocalDateTime lastRecordedTime; | ||
private RecurringFrequency frequency; | ||
private TaskType taskType; | ||
|
||
public RecurringTask(Task task, RecurringFrequency frequency) { | ||
if (task instanceof Todo) { this.taskType = TaskType.TODO; } | ||
if (task instanceof Deadline) { this.taskType = TaskType.DEADLINE; } | ||
if (task instanceof Event) { this.taskType = TaskType.EVENT; } | ||
|
||
if (task.getDateTime() != null) { | ||
lastRecordedTime = task.getDateTime(); | ||
} | ||
this.frequency = frequency; | ||
} | ||
|
||
public RecurringFrequency getFrequency() { return frequency; } | ||
|
||
/** | ||
* When a task is recurring, method compares current time to listed date. | ||
* If the task's date is outdated, then it will update to be for the next day. | ||
*/ | ||
public LocalDateTime recurringTaskTimeUpdate(Task task) { | ||
if (lastRecordedTime != null) { | ||
try { | ||
LocalDateTime currentTime = LocalDateTime.now(); | ||
if (lastRecordedTime.isBefore(currentTime)) { | ||
|
||
switch (this.frequency) { | ||
case DAILY: | ||
while (lastRecordedTime.isBefore(currentTime) || task.isDone()) { | ||
lastRecordedTime = lastRecordedTime.plusDays(1); | ||
if (task.isDone()) { task.isDone = false; } | ||
} | ||
case WEEKLY: | ||
while (lastRecordedTime.isBefore(currentTime) || task.isDone()) { | ||
lastRecordedTime = lastRecordedTime.plusWeeks(1); | ||
if (task.isDone) { task.isDone = false; } | ||
} | ||
case MONTHLY: | ||
while (lastRecordedTime.isBefore(currentTime) || task.isDone()) { | ||
lastRecordedTime = lastRecordedTime.plusMonths(1); | ||
if (task.isDone) { task.isDone = false; } | ||
} | ||
} | ||
} | ||
} catch (DateTimeParseException e) { | ||
System.out.println("I couldn't update your recurring events' times."); | ||
} | ||
} | ||
return lastRecordedTime; | ||
} | ||
} |
Oops, something went wrong.