Skip to content

Commit

Permalink
Merge pull request #198 from hshiah/hshiah
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
hshiah authored Nov 10, 2023
2 parents 8f06d05 + cac53ac commit 320aa07
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
9 changes: 8 additions & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/seedu/financialplanner/reminder/Reminder.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 320aa07

Please sign in to comment.