@@ -25,10 +25,12 @@ public class Parser {
2525 private static final String DEADLINE_KEY = "(deadline)\\ s*(\\ S*)\\ s*/by\\ s*" + DATE_TIME_KEY ;
2626 private static final String EVENT_KEY = "(event)\\ s*(\\ S*)\\ s*/at\\ s*" + DATE_TIME_KEY ;
2727 private static final String FIND_KEY = "(find)\\ s*(\\ S+)" ;
28+ private static final String VIEW_SCHEDULE_KEY = "(view schedule)\\ s*" + DATE_TIME_KEY ;
2829
2930 private static final int POSITION_TARGET_INDEX = 2 ;
3031 private static final int POSITION_DESCRIPTION = 2 ;
3132 private static final int POSITION_KEYWORD = 2 ;
33+ private static final int POSITION_VIEW_SCHEDULE_DATE = 2 ;
3234 private static final int POSITION_DATE = 3 ;
3335 private static final int POSITION_TIME = 4 ;
3436
@@ -38,6 +40,7 @@ public class Parser {
3840 private static final Pattern DEADLINE_PATTERN = Pattern .compile (DEADLINE_KEY );
3941 private static final Pattern EVENT_PATTERN = Pattern .compile (EVENT_KEY );
4042 private static final Pattern FIND_PATTERN = Pattern .compile (FIND_KEY );
43+ private static final Pattern VIEW_SCHEDULE_PATTERN = Pattern .compile (VIEW_SCHEDULE_KEY );
4144
4245 /*Handle the difference that java list start from index 0 will human readable list
4346 starts from 1.*/
@@ -63,6 +66,17 @@ public static LocalDateTime parseDateTime(String dateString, String timeString)
6366 }
6467 }
6568
69+ public static LocalDate parseDate (String dateString ) throws
70+ IllegalDateTimeFormatException {
71+ try {
72+ return LocalDate .parse (dateString );
73+ } catch (DateTimeParseException dte ) {
74+ throw new IllegalDateTimeFormatException (dte .getMessage () + '\n' );
75+ } catch (NullPointerException npe ) {
76+ throw new IllegalDateTimeFormatException ("Oops!!! The date string is missing!\n " );
77+ }
78+ }
79+
6680 /**
6781 * Parse the indicated position from the input command.
6882 * @param pattern Java regular expression pattern.
@@ -106,8 +120,12 @@ private LocalDateTime findDateTime(Pattern pattern, String input) throws Illegal
106120 return parseDateTime (dateString , timeString );
107121 }
108122
109- private static boolean isExitKey (String input ) {
110- return EXIT_KEY .equals (input );
123+ private LocalDate findDate (Pattern pattern , String input ) throws IllegalDateTimeFormatException {
124+ Matcher matcher = pattern .matcher (input );
125+ matcher .find ();
126+ String dateString = matcher .group (POSITION_VIEW_SCHEDULE_DATE );
127+
128+ return parseDate (dateString );
111129 }
112130
113131 private String findKeyword (Pattern pattern , String input ) {
@@ -117,6 +135,10 @@ private String findKeyword(Pattern pattern, String input) {
117135 return matcher .group (POSITION_KEYWORD );
118136 }
119137
138+ private static boolean isExitKey (String input ) {
139+ return EXIT_KEY .equals (input );
140+ }
141+
120142 private static boolean isViewListKey (String input ) {
121143 return VIEW_LIST_KEY .equals (input );
122144 }
@@ -146,11 +168,16 @@ private static boolean isEventKey(String input) {
146168 return eventMatcher .find ();
147169 }
148170
149- private static boolean isFindKey (String userInput ) {
150- Matcher findMatcher = FIND_PATTERN .matcher (userInput );
171+ private static boolean isFindKey (String input ) {
172+ Matcher findMatcher = FIND_PATTERN .matcher (input );
151173 return findMatcher .find ();
152174 }
153175
176+ private static boolean isViewScheduleKey (String input ) {
177+ Matcher viewScheduleMatcher = VIEW_SCHEDULE_PATTERN .matcher (input );
178+ return viewScheduleMatcher .find ();
179+ }
180+
154181 /**
155182 * Returns corresponding command with the parsed parameters.
156183 * @param userInput String user input.
@@ -184,6 +211,9 @@ public Command parseCommand(String userInput) throws
184211 } else if (Parser .isFindKey (userInput )) {
185212 String keyWord = this .findKeyword (FIND_PATTERN , userInput );
186213 return new FindCommand (keyWord );
214+ } else if (Parser .isViewScheduleKey (userInput )) {
215+ LocalDate targetDate = this .findDate (VIEW_SCHEDULE_PATTERN , userInput );
216+ return new ViewScheduleCommand (targetDate );
187217 }
188218 else {
189219 throw new NoCommandException ("OOPS!!! I'm sorry, but I don't know what that means :-(\n " );
0 commit comments