Skip to content

Commit

Permalink
Merge pull request #224 from Respirayson/branch-ped-bugfix
Browse files Browse the repository at this point in the history
Branch ped bugfix
  • Loading branch information
Respirayson authored Nov 9, 2023
2 parents 4846a9e + 49fd7b8 commit 788f066
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -42,7 +43,8 @@
public class ParserUtil {

public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer.";
public static final String MESSAGE_INVALID_DATE = "Date is needs to be in the format dd/MM/yyyy.";
public static final String MESSAGE_INVALID_DATE = "Date is needs to be in the format dd/MM/yyyy, "
+ "or date provided does not exist.";
public static final String MESSAGE_INVALID_TIME = "Time is needs to be in the format HH:mm.";

/**
Expand Down Expand Up @@ -168,7 +170,8 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
public static LocalDate parseDate(String date) throws ParseException {
requireNonNull(date);
String trimmedDate = date.trim();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/uuuu")
.withResolverStyle(ResolverStyle.STRICT);
try {
return LocalDate.parse(trimmedDate, formatter);
} catch (DateTimeParseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_PROGRESS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS;

import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import seedu.address.logic.commands.ViewTasksCommand;
Expand Down Expand Up @@ -46,27 +49,42 @@ public ViewTasksCommand parse(String args) throws ParseException {
Predicate<Task> predicate = PREDICATE_SHOW_ALL_TASKS;

if (argMultimap.getValue(PREFIX_TASK_NAME).isPresent()) {
String[] taskNameKeywords = argMultimap.getValue(PREFIX_TASK_NAME).get().split("\\s+");
String[] taskNameKeywords = ParserUtil.parseTaskName(
argMultimap.getValue(PREFIX_TASK_NAME).get()).taskName.split("\\s+");
predicate = new TaskNameContainsKeywordsPredicate(Arrays.asList(taskNameKeywords));
}

if (argMultimap.getValue(PREFIX_TASK_DESCRIPTION).isPresent()) {
String[] taskDescKeywords = argMultimap.getValue(PREFIX_TASK_DESCRIPTION).get().split("\\s+");
String[] taskDescKeywords = ParserUtil.parseTaskDescription(
argMultimap.getValue(PREFIX_TASK_DESCRIPTION).get()).description.split("\\s+");
predicate = new TaskDescriptionContainsKeywordsPredicate(Arrays.asList(taskDescKeywords));
}

if (argMultimap.getValue(PREFIX_TASK_PRIORITY).isPresent()) {
String[] taskPriorityKeywords = argMultimap.getValue(PREFIX_TASK_PRIORITY).get().split("\\s+");
predicate = new TaskPriorityContainsKeywordsPredicate(Arrays.asList(taskPriorityKeywords));

List<String> checkedTaskPriorityKeywords = new ArrayList<>();
for (String str : taskPriorityKeywords) {
checkedTaskPriorityKeywords.add(ParserUtil.parseTaskPriority(str).name());
}

predicate = new TaskPriorityContainsKeywordsPredicate(checkedTaskPriorityKeywords);
}

if (argMultimap.getValue(PREFIX_TASK_PROGRESS).isPresent()) {
String[] taskProgressKeywords = argMultimap.getValue(PREFIX_TASK_PROGRESS).get().split("\\s+");
predicate = new TaskProgressContainsKeywordsPredicate(Arrays.asList(taskProgressKeywords));

List<String> checkedTaskProgressKeywords = new ArrayList<>();
for (String str : taskProgressKeywords) {
checkedTaskProgressKeywords.add(ParserUtil.parseTaskProgress(str).name());
}

predicate = new TaskProgressContainsKeywordsPredicate(checkedTaskProgressKeywords);
}

if (argMultimap.getValue(PREFIX_DATE).isPresent()) {
String[] dateKeywords = argMultimap.getValue(PREFIX_DATE).get().split("\\s+");
String[] dateKeywords = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get())
.format(DateTimeFormatter.ofPattern("dd/MM/uuuu")).split("\\s+");
predicate = new DateContainsKeywordsPredicate(Arrays.asList(dateKeywords));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public void parse_validTaskDescArgs_returnsViewTasksCommand() {
assertParseSuccess(parser, " " + PREFIX_TASK_DESCRIPTION + "prs book", expectedCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, " " + PREFIX_TASK_DESCRIPTION + "prs \n \t book", expectedCommand);
assertParseSuccess(parser, " " + PREFIX_TASK_DESCRIPTION + "prs \t book", expectedCommand);
}

@Test
public void parse_validTaskProgressArgs_returnsViewTasksCommand() {
// no leading and trailing whitespaces
ViewTasksCommand expectedCommand =
new ViewTasksCommand(new TaskProgressContainsKeywordsPredicate(Arrays.asList("done", "pending")));
new ViewTasksCommand(new TaskProgressContainsKeywordsPredicate(Arrays.asList("DONE", "PENDING")));
assertParseSuccess(parser, " " + PREFIX_TASK_PROGRESS + "done pending", expectedCommand);

// multiple whitespaces between keywords
Expand All @@ -70,7 +70,7 @@ public void parse_validTaskProgressArgs_returnsViewTasksCommand() {
public void parse_validTaskPriorityArgs_returnsViewTasksCommand() {
// no leading and trailing whitespaces
ViewTasksCommand expectedCommand =
new ViewTasksCommand(new TaskPriorityContainsKeywordsPredicate(Arrays.asList("low", "high")));
new ViewTasksCommand(new TaskPriorityContainsKeywordsPredicate(Arrays.asList("LOW", "HIGH")));
assertParseSuccess(parser, " " + PREFIX_TASK_PRIORITY + "low high", expectedCommand);

// multiple whitespaces between keywords
Expand Down

0 comments on commit 788f066

Please sign in to comment.