Skip to content

Commit

Permalink
Change deadline to read dates and times instead of just dates
Browse files Browse the repository at this point in the history
Change Ui picture so that it reflects new functionality as stated above
  • Loading branch information
Arixeyeion committed Feb 21, 2024
1 parent 0fe8eac commit 783d486
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
10 changes: 6 additions & 4 deletions data/SavedTasks.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
todo_read book_0
event_CS2103 tutorial /from 3pm/to 4pm_0
deadline_ip soft deadline/by 2024-02-23_0
deadline_finish reading book/by 2024-03-01_0
todo_read book_1
event_meeting /from 2pm/to 6pm_1
deadline_english project/by 2024-03-01 23:58_0
deadline_math project/by 2024-03-01 23:59_0
deadline_art project/by 2024-05-03 23:58_0
deadline_science project/by 2024-05-03 23:59_0
EOF
Binary file modified docs/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 14 additions & 11 deletions src/main/java/zoe/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package zoe;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* Subclass of task
* Creates a deadline when keyed in the form: deadline XYZ /by yyyy-mm-dd
*/
public class Deadline extends Task {
private static DateTimeFormatter DATE_TIME_PARSER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

private static DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("MMM d yyyy HH:mm");
private static int DESCRIPTION = 0;
private static int DATE = 1;
protected String date;
protected String dateTime;
protected String formattedDate;
public Deadline(String desc) {
String[] str = desc.split("/by");
this.description = str[DESCRIPTION].trim();
this.date = str[DATE].trim();
LocalDate inputDate = LocalDate.parse(date);
this.formattedDate = inputDate.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
this.dateTime = str[DATE].trim();
LocalDateTime inputDate = LocalDateTime.parse(dateTime, DATE_TIME_PARSER);
this.formattedDate = inputDate.format(FORMATTER);
this.type = "D";
this.isDone = false;
this.priority = TaskPriority.DEADLINE.getPriority();
Expand All @@ -26,9 +29,9 @@ public Deadline(String desc) {
public Deadline(String desc, String isDoneNumber) {
String[] str = desc.split("/by");
this.description = str[DESCRIPTION].trim();
this.date = str[DATE].trim();
LocalDate inputDate = LocalDate.parse(date);
this.formattedDate = inputDate.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
this.dateTime = str[DATE].trim();
LocalDateTime inputDate = LocalDateTime.parse(dateTime, DATE_TIME_PARSER);
this.formattedDate = inputDate.format(FORMATTER);
this.type = "D";
int doneState = Integer.parseInt(isDoneNumber);
assert doneState < 2 : "Data file corrupted, invalid state";
Expand All @@ -45,13 +48,13 @@ public String getStatus() {

@Override
public String saveTask() {
return String.format("deadline_%s/by %s_%d", description, date, isDoneNumerical());
return String.format("deadline_%s/by %s_%d", description, dateTime, isDoneNumerical());
}

/**
* Provides date to the comparator to sort deadlines
*/
public LocalDate getDate() {
return LocalDate.parse(date);
public LocalDateTime getDateTime() {
return LocalDateTime.parse(dateTime, DATE_TIME_PARSER);
}
}
1 change: 0 additions & 1 deletion src/main/java/zoe/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void initialize(Zoe zoe, Ui ui) {
/**
* Creates two dialog boxes, one echoing user input and the other containing Zoe's reply and then appends them to
* the dialog container. Clears the user input after processing.
* Thrown exception is to allow for pausing the bot for 2 seconds so that it can say bye to the user
*/
@FXML
private void handleUserInput() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/zoe/PriorityComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class PriorityComparator implements Comparator<Task>{
public int compare(Task firstTask, Task secondTask) {
if ((firstTask instanceof Deadline) && (secondTask instanceof Deadline)) {

return ((Deadline) firstTask).getDate().isBefore(((Deadline) secondTask).getDate()) ? -1 : 0;
return ((Deadline) firstTask).getDateTime().isBefore(((Deadline) secondTask).getDateTime()) ? -1 : 0;
}

return firstTask.getPriority() - secondTask.getPriority();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/zoe/Zoe.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static void main(String[] args) {

public String getResponse(String input) {


if (input.equals("bye")) {
return ui.saysBye();
}
Expand Down

0 comments on commit 783d486

Please sign in to comment.