Skip to content

Commit

Permalink
Merge pull request #263 from M-kew/branch-code-declaration
Browse files Browse the repository at this point in the history
Branch code declaration
  • Loading branch information
SSirMentos authored Nov 11, 2024
2 parents d8fee60 + 0ccb219 commit 95e79a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* Searches for clients who have appointments on the specified date and time.
*/
public class SearchAppointmentCommand extends Command {
// ChatGPT used to generate javadocs
public static final String COMMAND_WORD = "search " + PREFIX_SEARCH_APPOINTMENT;

public static final String MESSAGE_USAGE = COMMAND_WORD
Expand Down Expand Up @@ -75,6 +74,7 @@ public SearchAppointmentCommand(String dateTimeInput) throws CommandException {

@Override
public CommandResult execute(Model model) throws CommandException {
// This execute method relied on GPT to help check the correctness of the code.
requireNonNull(model);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
Predicate<Person> predicate = person -> {
Expand Down Expand Up @@ -123,7 +123,7 @@ private boolean isValidDateTime(String dateTime) {

@Override
public boolean equals(Object other) {
// This method made use of ChatGPT to ensure its correctness when comparing the Command object
// This method made use of ChatGPT to ensure its correctness when comparing the Command objects
if (other == this) {
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/model/person/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class Appointment {
* The appointment date and time should in the format 'yyyy-MM-dd HH:mm'.
* Example: 2023-01-31 13:00
*/

// This regex is generated by ChatGPT to assist me in performing validation check for the appointment dates
public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}";

private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
Expand Down Expand Up @@ -55,12 +57,16 @@ private static LocalDateTime parseDateTime(String dateTimeStr) {
* Returns true if a given string is a valid appointment date and time.
*/
public static boolean isValidAppointment(String input) {
// make sure appointment is not null
requireNonNull(input);
if (!input.matches(VALIDATION_REGEX)) {
// check if it meets the correct format
return false;
}
try {
// get appointment date
LocalDateTime appointmentDateTime = LocalDateTime.parse(input, FORMATTER);
// ensure appointment date is not after the current date, else throw exception
return appointmentDateTime.toLocalDate().isAfter(LocalDate.now());
} catch (DateTimeParseException e) {
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/person/Birthday.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class Birthday {
* @param dateStr A valid date string.
*/
public Birthday(String dateStr) {
requireNonNull(dateStr);
requireNonNull(dateStr); // check entry is not null
// check valid birthday input
checkArgument(isValidBirthday(dateStr), MESSAGE_CONSTRAINTS);
date = parseDate(dateStr);
this.value = date.format(FORMATTER);
Expand All @@ -52,6 +53,7 @@ public static boolean isValidBirthday(String input) {
requireNonNull(input);
try {
LocalDate testBirthday = LocalDate.parse(input, FORMATTER);
// compare current date with birthday. If birthday exceeds current, throw an exception
return testBirthday.isBefore(LocalDate.now());
} catch (DateTimeParseException e) {
return false;
Expand All @@ -66,7 +68,6 @@ public int hashCode() {
@Override
public boolean equals(Object other) {
// This method made use of ChatGPT to ensure its correctness when comparing the birthday object

return this == other
|| (other instanceof Birthday
&& date.equals(((Birthday) other).date));
Expand Down

0 comments on commit 95e79a2

Please sign in to comment.