Skip to content

Commit

Permalink
Merge branch 'feature-reminders'
Browse files Browse the repository at this point in the history
  • Loading branch information
A1WAYSD committed Sep 13, 2023
2 parents ad1f4af + 29866e1 commit b18cdda
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
6 changes: 5 additions & 1 deletion data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
TODO | 0 | hihi
TODO | 0 | test
TODO | 0 | test
TODO | 0 | test??
TODO | 0 | test??
DEADLINE | 0 | test1 | hi
DEADLINE | 0 | test2 | yes
DEADLINE | 0 | test3 | 2023-12-12date
DEADLINE | 0 | test4 | 2004-01-20date
4 changes: 3 additions & 1 deletion src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public String parse(String... inputs) throws DukeException {
return this.tasks.markTask(taskIndex, isDone);
} else if (taskMatcher.matches()) {
return this.tasks.addTask(TaskType.valueOf(taskMatcher.group(1).toUpperCase()), taskMatcher.group(2));
} else if (repeat.contains("list") || repeat.contains("List")) {
} else if (repeat.equals("list") || repeat.equals("List")) {
return this.tasks.getTasks();
} else if (repeat.equals("reminder")) {
return this.tasks.getReminder();
} else {
throw new DukeException("undefined");
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ public String toTxt() {
return this.by != null ? super.toTxt() + this.description + " | " + this.by + this.byDescription : super.toTxt()
+ this.description + " | " + this.byDescription;
}

public LocalDate getByDate() {
return this.by;
}
}
44 changes: 44 additions & 0 deletions src/main/java/duke/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import duke.DukeException;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -147,4 +149,46 @@ public String deleteTask(int taskIndex) throws DukeException {
return "I've successfully deleted this task:\n" + task + "\nNow you have " + size + taskInTotal
+ "\n\"Ride the waves.\"";
}

/**
* Returns the reminder of upcoming deadlines.
* @return
*/
public String getReminder() {
String result = "Upcoming deadlines:\n";
ArrayList<Deadline> deadlines = new ArrayList<>();
System.out.println(tasks);
for (int i = 0; i < tasks.size(); i++) {
if (tasks.get(i).taskType == TaskType.DEADLINE && !tasks.get(i).isDone) {
System.out.println("yes");
System.out.println(tasks.get(i));
Deadline task = (Deadline) tasks.get(i);
deadlines.add(task);
}
}

// Sort the deadlines list based on byDate
Collections.sort(deadlines, new Comparator<Deadline>() {
@Override
public int compare(Deadline d1, Deadline d2) {
if (d1.getByDate() == null && d2.getByDate() == null) {
return 0;
} else if (d1.getByDate() == null) {
return 1;
} else if (d2.getByDate() == null) {
return -1;
} else {
return d1.getByDate().compareTo(d2.getByDate());
}
}
});

System.out.println(deadlines);
System.out.println(deadlines.size());

for (int i = 0; i < deadlines.size(); i++) {
result += (i + 1) + " " + deadlines.get(i) + "\n";
}
return result + "\"One thing at a time.\"";
}
}

0 comments on commit b18cdda

Please sign in to comment.