diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs index ad53270215eb..58b9567e0ca2 100644 --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -1,6 +1,3 @@ -=\=\=\=\=\=\= -<<<<<<<=.merge_file_a03816 ->>>>>>>=.merge_file_a08680 build.commands=org.eclipse.jdt.core.javabuilder connection.arguments= connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) diff --git a/src/main/java/seedu/address/logic/parser/Parser.java b/src/main/java/seedu/address/logic/parser/Parser.java index 89644a2ebe82..991865178553 100644 --- a/src/main/java/seedu/address/logic/parser/Parser.java +++ b/src/main/java/seedu/address/logic/parser/Parser.java @@ -31,21 +31,21 @@ public class Parser { + "( d/(?[^/]+)){0,1}" + "( date/(?[^/]+)){0,1}" + "(?(?: t/[^/]+)*)"); // variable number of tags - + private static final Pattern EDIT_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[\\d]+)" + "( (?[^/]+)){0,1}" + "( d/(?[^/]+)){0,1}" + "( date/(?[^/]+)){0,1}" + "(?(?: t/[^/]+)*)"); // variable number of tags - -// private static final Pattern USA_DATE_FORMAT = -// Pattern.compile("(?(0?[1-9]|1[012]))" -// + "\\." -// + "(?
(0?[1-9]|[12][0-9]|3[01]))" -// + "\\." -// + "(?\\d{2})"); - + + // private static final Pattern USA_DATE_FORMAT = + // Pattern.compile("(?(0?[1-9]|1[012]))" + // + "\\." + // + "(?
(0?[1-9]|[12][0-9]|3[01]))" + // + "\\." + // + "(?\\d{2})"); + public Parser() {} /** @@ -72,10 +72,10 @@ public Command parseCommand(String userInput) { case DeleteCommand.COMMAND_WORD: return prepareDelete(arguments); - + case EditCommand.COMMAND_WORD: return prepareEdit(arguments); - + case ClearCommand.COMMAND_WORD: return new ClearCommand(); @@ -104,47 +104,47 @@ public Command parseCommand(String userInput) { */ private Command prepareAdd(String args){ final Matcher matcher = PERSON_DATA_ARGS_FORMAT.matcher(args.trim()); - + // Validate arg string format if (!matcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } - + try { - List dateList = nattyParse(matcher); - + List dateList = nattyParse(matcher); + return new AddCommand( matcher.group("name"), matcher.group("description"), dateList, getTagsFromArgs(matcher.group("tagArguments")) - ); + ); } catch (IllegalValueException ive) { return new IncorrectCommand(ive.getMessage()); } } - private List nattyParse(final Matcher matcher) throws IllegalValueException { - - TimeZone tz = TimeZone.getDefault(); - com.joestelmach.natty.Parser natty = new com.joestelmach.natty.Parser(tz); - List dateList; - - // NPE could be thrown here -> floating task no date no time - // natty.parse() can return null too - if (matcher.group("date") == null){ - // return empty list - dateList = new ArrayList (); - } - else if (natty.parse(matcher.group("date")).isEmpty()){ - throw new IllegalValueException(seedu.address.model.person.Date.MESSAGE_DATE_CONSTRAINTS); - } - else { - dateList = natty.parse(matcher.group("date")).get(0).getDates(); - } - - return dateList; - } + private List nattyParse(final Matcher matcher) throws IllegalValueException { + + TimeZone tz = TimeZone.getDefault(); + com.joestelmach.natty.Parser natty = new com.joestelmach.natty.Parser(tz); + List dateList; + + // NPE could be thrown here -> floating task no date no time + // natty.parse() can return null too + if (matcher.group("date") == null){ + // return empty list + dateList = new ArrayList (); + } + else if (natty.parse(matcher.group("date")).isEmpty()){ + throw new IllegalValueException(seedu.address.model.person.Date.MESSAGE_DATE_CONSTRAINTS); + } + else { + dateList = natty.parse(matcher.group("date")).get(0).getDates(); + } + + return dateList; + } /** * Extracts the new person's tags from the add command's tag arguments string. @@ -176,7 +176,7 @@ private Command prepareDelete(String args) { return new DeleteCommand(index.get()); } - + /** * Parses arguments in the context of the edit person command. * @@ -184,18 +184,18 @@ private Command prepareDelete(String args) { * @return the prepared command */ private Command prepareEdit(String args) { - + final Matcher matcher = EDIT_DATA_ARGS_FORMAT.matcher(args.trim()); // Validate arg string format if (!matcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); } - - - + + + try { - List dateList = nattyParse(matcher); - + List dateList = nattyParse(matcher); + return new EditCommand( Integer.parseInt(matcher.group("index")), matcher.group("name"), @@ -203,7 +203,7 @@ private Command prepareEdit(String args) { matcher.group("date"), matcher.group("time"), getTagsFromArgs(matcher.group("tagArguments")) - ); + ); } catch (IllegalValueException ive) { return new IncorrectCommand(ive.getMessage()); } diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 09e7a70cd621..35f192935abd 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -149,8 +150,6 @@ public void execute_clear() throws Exception { @Test public void execute_add_invalidArgsFormat() throws Exception { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); - assertCommandBehavior( - "add wrong args wrong args", expectedMessage); assertCommandBehavior( "add Valid Name 12345 e/valid@email.butNoPhonePrefix a/valid, address", expectedMessage); assertCommandBehavior( @@ -162,13 +161,13 @@ public void execute_add_invalidArgsFormat() throws Exception { @Test public void execute_add_invalidPersonData() throws Exception { assertCommandBehavior( - "add []\\[;] d/12345 date/11.11.11 time/1111", Name.MESSAGE_NAME_CONSTRAINTS); - assertCommandBehavior( - "add Valid Name d/can_be_anything date/not_valid_date time/1111", Date.MESSAGE_DATE_CONSTRAINTS); + "add []\\[;] d/12345 date/11-11-2018 1111", Name.MESSAGE_NAME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name d/can_be_anything date/11.11.11 time/5678", Time.MESSAGE_TIME_CONSTRAINTS); + "add Valid Name d/can_be_anything date/ab-cd-ef", Date.MESSAGE_DATE_CONSTRAINTS); + //TODO assertCommandBehavior( + // "add Valid Name d/can_be_anything date/11-11-2018 5678pm", Time.MESSAGE_TIME_CONSTRAINTS); assertCommandBehavior( - "add Valid Name d/can_be_anything date/11.11.11 time/1111 t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS); + "add Valid Name d/can_be_anything date/11-11-2018 1111 t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS); } @@ -370,8 +369,10 @@ class TestDataHelper{ Task adam() throws Exception { Name name = new Name("Adam Brown"); Description privatePhone = new Description("111111"); - Date email = new Date("11.11.11"); - Time privateAddress = new Time("1111"); + List dateList = + (new com.joestelmach.natty.Parser(TimeZone.getDefault())).parse("11-11-2011 1111").get(0).getDates(); + Date email = new Date(dateList); + Time privateAddress = new Time(dateList); Tag tag1 = new Tag("tag1"); Tag tag2 = new Tag("tag2"); UniqueTagList tags = new UniqueTagList(tag1, tag2); @@ -389,7 +390,7 @@ Task generatePerson(int seed) throws Exception { return new Task( new Name("Person " + seed), new Description("" + Math.abs(seed)), - new Date("11.11.1" + seed), + new Date("11.11.201" + seed), new Time("111" + seed), new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))) ); @@ -403,8 +404,8 @@ String generateAddCommand(Task p) { cmd.append(p.getName().toString()); cmd.append(" d/").append(p.getDescription()); - cmd.append(" date/").append(p.getDate()); - cmd.append(" time/").append(p.getTime()); + cmd.append(" date/").append(p.getDate().toString().replace('.', '-')); + cmd.append(" ").append(p.getTime()); UniqueTagList tags = p.getTags(); for(Tag t: tags){ @@ -485,11 +486,13 @@ List generatePersonList(Task... persons) { * Generates a Person object with given name. Other fields will have some dummy values. */ Task generatePersonWithName(String name) throws Exception { + List dateList = + (new com.joestelmach.natty.Parser(TimeZone.getDefault())).parse("10-11-2019 1111").get(0).getDates(); return new Task( new Name(name), - new Description("1"), - new Date("11.11.11"), - new Time("1111"), + new Description("Describes task"), + new Date(dateList), + new Time(dateList), new UniqueTagList(new Tag("tag")) ); } diff --git a/src/test/java/seedu/address/testutil/TestUtil.java b/src/test/java/seedu/address/testutil/TestUtil.java index 62c2d2564df5..e3dc0bd5ee2a 100644 --- a/src/test/java/seedu/address/testutil/TestUtil.java +++ b/src/test/java/seedu/address/testutil/TestUtil.java @@ -67,13 +67,13 @@ private static Task[] getSamplePersonData() { return new Task[]{ new Task(new Name("Ali Muster"), new Description("Meet for dinner"), new Date(""), new Time(""), new UniqueTagList()), new Task(new Name("Boris Mueller"), new Description("Meet for lunch"), new Date(""), new Time(""), new UniqueTagList()), - new Task(new Name("Carl Kurz"), new Description("Meet for breakfast"), new Date("11.11.17"), new Time("2234"), new UniqueTagList()), - new Task(new Name("Daniel Meier"), new Description("Meet for lunch"), new Date("09.09.17"), new Time("2200"), new UniqueTagList()), - new Task(new Name("Elle Meyer"), new Description("Meet for lunch"), new Date("10.10.17"), new Time("2300"), new UniqueTagList()), - new Task(new Name("Fiona Kunz"), new Description("Meet for dinner"), new Date("10.10.17"), new Time("2254"), new UniqueTagList()), + new Task(new Name("Carl Kurz"), new Description("Meet for breakfast"), new Date("11.11.2017"), new Time("2234"), new UniqueTagList()), + new Task(new Name("Daniel Meier"), new Description("Meet for lunch"), new Date("09.09.2017"), new Time("2200"), new UniqueTagList()), + new Task(new Name("Elle Meyer"), new Description("Meet for lunch"), new Date("10.10.2017"), new Time("2300"), new UniqueTagList()), + new Task(new Name("Fiona Kunz"), new Description("Meet for dinner"), new Date("10.10.2017"), new Time("2254"), new UniqueTagList()), new Task(new Name("George Best"), new Description("Meet for breakfast"), new Date(""), new Time(""), new UniqueTagList()), - new Task(new Name("Hoon Meier"), new Description("Meet for dinner"), new Date("01.01.17"), new Time("2101"), new UniqueTagList()), - new Task(new Name("Ida Mueller"), new Description("Meet for breakfast"), new Date("09.05.17"), new Time("2130"), new UniqueTagList()) + new Task(new Name("Hoon Meier"), new Description("Meet for dinner"), new Date("01.01.2017"), new Time("2101"), new UniqueTagList()), + new Task(new Name("Ida Mueller"), new Description("Meet for breakfast"), new Date("09.05.2017"), new Time("2130"), new UniqueTagList()) }; } catch (IllegalValueException e) { assert false; diff --git a/src/test/java/seedu/address/testutil/TypicalTestTasks.java b/src/test/java/seedu/address/testutil/TypicalTestTasks.java index 99f167fae3d7..65e9c0512c3f 100644 --- a/src/test/java/seedu/address/testutil/TypicalTestTasks.java +++ b/src/test/java/seedu/address/testutil/TypicalTestTasks.java @@ -14,11 +14,11 @@ public class TypicalTestTasks { public TypicalTestTasks() { try { one = new DatedTaskBuilder().withName("buy milk").withDescription("lots of it") - .withDate("11.11.11").withTime("1111").build(); + .withDate("11.11.2017").withTime("1111").build(); two = new DatedTaskBuilder().withName("buy some milk").withDescription("not so much") - .withDate("11.11.11").withTime("1111").build(); - three = new DatedTaskBuilder().withName("buy some milk").withDescription("not so much") - .withDate("12.12.12").withTime("1111").build(); + .withDate("11.11.2017").withTime("1111").build(); + three = new DatedTaskBuilder().withName("buy some milk").withDescription("just a little") + .withDate("12.12.2017").withTime("1111").build();