Skip to content

Commit

Permalink
Update EditCommand.java and Person.java
Browse files Browse the repository at this point in the history
Include new method isSameDateTime to check if other person has the
same datetime
  • Loading branch information
Hwww23 committed Apr 3, 2024
1 parent 1ca59b0 commit 761820b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

if (model.hasDateTime(editedPerson)) {
if (!personToEdit.isSameDateTime(editedPerson) && model.hasDateTime(editedPerson)) {
throw new CommandException(MESSAGE_DUPLICATE_DATETIME);
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ public boolean isSamePerson(Person otherPerson) {
&& otherPerson.getName().equals(getName());
}

/**
* Returns true if both persons have the same set of datetime.
*/
public boolean isSameDateTime(Person otherPerson) {
if (otherPerson == this) {
return true;
}

return otherPerson != null
&& otherPerson.getDateTimes().equals(getDateTimes());
}

/**
* Returns true if both persons have the same identity and data fields.
* This defines a stronger notion of equality between two persons.
Expand Down

0 comments on commit 761820b

Please sign in to comment.