diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 0ee417e4ec..4347cc3bd3 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -887,7 +887,14 @@ window. Sorry for the inconvenience caused. 🥲 | **Delete from watchlist** | `deletestock /s STOCKCODE` | | **Visualization** | `vis /t TYPE /c CHART` | | **Exit program** | `exit` | - +| **Add Reminder** | `addreminder /t TYPE /d DATE` | +| **Delete Reminder** | `deletereminder INDEX` | +| **Mark Reminder as Done** | `markreminder INDEX` | +| **Add Goal** | `set goal /g GOAL /l LABEL` | +| **Delete Goal** | `deletegoal INDEX` | +| **Mark Goal as Achieved** | `markgoal INDEX` | +| **List all reminders** | `reminderlist` | +| **List all goals** | `wishlist` | - Note: Cashflow is referring to an income or expense **Income and Expense types** diff --git a/src/main/java/seedu/financialplanner/commands/AddReminderCommand.java b/src/main/java/seedu/financialplanner/commands/AddReminderCommand.java index 44053a7876..bfc065b830 100644 --- a/src/main/java/seedu/financialplanner/commands/AddReminderCommand.java +++ b/src/main/java/seedu/financialplanner/commands/AddReminderCommand.java @@ -1,11 +1,16 @@ package seedu.financialplanner.commands; + import seedu.financialplanner.commands.utils.Command; import seedu.financialplanner.commands.utils.RawCommand; import seedu.financialplanner.reminder.Reminder; import seedu.financialplanner.reminder.ReminderList; import seedu.financialplanner.utils.Ui; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + @SuppressWarnings("unused") public class AddReminderCommand extends Command { public static final String NAME = "addreminder"; @@ -16,19 +21,39 @@ public class AddReminderCommand extends Command { public static final String EXAMPLE = "addreminder /t debt /d 2023.12.11"; private final String type; - private final String date; + private final LocalDate date; public AddReminderCommand(RawCommand rawCommand) throws IllegalArgumentException { String typeString = String.join(" ", rawCommand.args); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); if (!rawCommand.extraArgs.containsKey("t")) { throw new IllegalArgumentException("Reminder must have a type"); } type = rawCommand.extraArgs.get("t"); + if(type.isEmpty()){ + throw new IllegalArgumentException("Reminder type cannot be empty"); + } rawCommand.extraArgs.remove("t"); if (!rawCommand.extraArgs.containsKey("d")) { throw new IllegalArgumentException("Reminder must have a date"); } - date = rawCommand.extraArgs.get("d"); + + String dateString = rawCommand.extraArgs.get("d"); + if(dateString.isEmpty()){ + throw new IllegalArgumentException("Reminder date cannot be empty"); + } + + try { + date = LocalDate.parse(dateString, formatter); + } catch (DateTimeParseException e) { + throw new IllegalArgumentException("Reminder date must be in the format dd/MM/yyyy"); + } + + LocalDate currentTime = LocalDate.now(); + if(date.isBefore(currentTime)){ + throw new IllegalArgumentException("Reminder date cannot be in the past"); + } + rawCommand.extraArgs.remove("d"); if (!rawCommand.extraArgs.isEmpty()) { String unknownExtraArgument = new java.util.ArrayList<>(rawCommand.extraArgs.keySet()).get(0); diff --git a/src/main/java/seedu/financialplanner/reminder/Reminder.java b/src/main/java/seedu/financialplanner/reminder/Reminder.java index d32c683823..104d0cbf24 100644 --- a/src/main/java/seedu/financialplanner/reminder/Reminder.java +++ b/src/main/java/seedu/financialplanner/reminder/Reminder.java @@ -1,18 +1,22 @@ package seedu.financialplanner.reminder; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.Duration; public class Reminder { private String type; - private String date; + private LocalDate date; private boolean isDone = false; - public Reminder(String type, String date) { + public Reminder(String type, LocalDate date) { this.type = type; this.date = date; } public Reminder(String type, String date, String status) { this.type = type; - this.date = date; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + this.date = LocalDate.parse(date, formatter); if (status.equals("Done")) { this.isDone = true; } else { @@ -21,16 +25,16 @@ public Reminder(String type, String date, String status) { } public String toString() { String status = isDone ? "Done" : "Not Done"; + LocalDate currentTime = LocalDate.now(); + Duration duration = Duration.between(currentTime.atStartOfDay(), date.atStartOfDay()); return "Reminder " + System.lineSeparator() + " Type: " + type + System.lineSeparator() - + " Date: " + date + System.lineSeparator() + " Status: " + status; + + " Date: " + date + System.lineSeparator() + " Status: " + status + + System.lineSeparator() + " Left Days: " + duration.toDays(); } public void markAsDone() { this.isDone = true; } - public void unmark() { - this.isDone = false; - } /* * Returns a string that can be saved to a file. * Format: type | date | isDone