-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[nicljr] iP #369
base: master
Are you sure you want to change the base?
[nicljr] iP #369
Changes from 1 commit
556af3f
df77119
d6b8764
c910988
f2837d0
c26dc5f
7fccd03
a7f039d
326442a
722efb2
b808016
a29957d
8adc44b
a40eea4
1d74e99
8836d32
45f7698
45d6446
463ddac
f4d424f
fc0bd0a
cf14b0c
27fff36
0b1488d
15154a2
35810a9
09b4513
d6156b2
19c9546
be2ea3e
00bdbb8
3bceb3a
86b6388
c13783f
45b8a2d
dc82fb8
e2d914c
489aa58
1532784
9684d05
8cb19eb
4363e12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
T|0|borrow book | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,16 @@ | |
|
||
import duke.command.*; | ||
|
||
import java.time.LocalDate; | ||
import java.sql.Date; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class Parser { | ||
|
||
public static DateTimeFormatter strFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"); | ||
public static DateTimeFormatter ldtFormatter = DateTimeFormatter.ofPattern("MMM dd yyyy HHmm"); | ||
|
||
|
||
public static Integer stringToInt(String index) { | ||
return Integer.parseInt(index); | ||
} | ||
|
@@ -29,12 +34,24 @@ public static Command stringToCommand(String command) { | |
} | ||
} | ||
|
||
public static LocalDate stringToDate(String duration) { | ||
LocalDate localDate = LocalDate.parse(duration); | ||
return localDate; | ||
public static String[] deadlineSplit(String deadline) { | ||
return deadline.split(" ", 2); | ||
} | ||
|
||
public static String[] eventSplit(String event) { | ||
return event.split(" ", 6); | ||
} | ||
|
||
public static LocalDateTime stringToDateTime(String duration) { | ||
LocalDateTime localDateTime = LocalDateTime.parse(duration, strFormatter); | ||
return localDateTime; | ||
} | ||
|
||
public static String dateTimeToString(LocalDateTime localDateTime) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should methods such as |
||
return localDateTime.format(ldtFormatter); | ||
} | ||
|
||
public static String dateToString(LocalDate localDate) { | ||
return localDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); | ||
public static String dateTimeSaving(LocalDateTime localDateTime) { | ||
return localDateTime.format(strFormatter); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,33 +45,38 @@ public Task assignToDo(String command) { | |
public Task assignDeadline(String command) throws DukeException { | ||
String[] splitTiming = command.split("/by "); | ||
if (splitTiming.length != 2) { | ||
throw new DukeException("Improper Deadline Format! deadline {desc} /by {date}\n"); | ||
throw new DukeException("Improper Deadline Format! deadline {desc} /by yyyy-mm-dd hhmm\n"); | ||
} | ||
|
||
try { | ||
int d_index = command.indexOf("/by ") + 4; | ||
String deadline = command.substring(d_index); | ||
System.out.println(deadline); | ||
String updated_deadline = TimeChecker.updateTime(deadline); | ||
String d_desc = command.substring(9, d_index - 4); | ||
return new Deadline(d_desc, deadline); | ||
return new Deadline(d_desc, updated_deadline); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to consider changing |
||
} catch (DateTimeParseException e) { | ||
throw new DukeException("Date Incorrect Time Format! Follow: yyyy-mm-dd\n"); | ||
throw new DukeException("Improper Deadline Format! deadline {desc} /by yyyy-mm-dd hhmm\n"); | ||
} | ||
} | ||
|
||
public Task assignEvent(String command) throws DukeException { | ||
String[] splitTimings = command.split("/from | /to"); | ||
String[] splitTimings = command.split("/from | /to "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I clarify the intention behind the naming of this variable? Perhaps another name could be choosen to convey the message that the variable is an array of strings representing time (ie. |
||
if (splitTimings.length != 3) { | ||
throw new DukeException("Improper Event Format! Event {desc} /from {date} /to {date}\n"); | ||
throw new DukeException("Improper Event Format! Follow:\n" + | ||
"event {desc} /from yyyy-mm-dd hhmm /to yyyy-mm-dd hhmm\n"); | ||
} | ||
try { | ||
int s_index = command.indexOf("/from") + 6; | ||
int e_index = command.indexOf("/to") + 4; | ||
String start_date = command.substring(s_index, e_index - 5); | ||
String end_date = command.substring(e_index); | ||
String start_date = TimeChecker.updateTime(command.substring(s_index, e_index - 5)); | ||
String end_date = TimeChecker.updateTime(command.substring(e_index)); | ||
String e_desc = command.substring(6, s_index - 6); | ||
return new Events(e_desc, start_date, end_date); | ||
} catch (DateTimeParseException e) { | ||
throw new DukeException("Date Incorrect Format! Follow: yyyy-mm-dd\n"); | ||
throw new DukeException("Improper Event Format! Follow:\n" + | ||
"event {desc} /from yyyy-mm-dd hhmm /to yyyy-mm-dd hhmm\n"); | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package duke; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class TimeChecker { | ||
|
||
public static String DEFAULT_TIME = "2359"; | ||
private static DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HHmm"); | ||
|
||
public static String updateTime(String timeline) { | ||
String[] split = timeline.split(" "); | ||
if (split.length == 2) { | ||
return timeline; | ||
} else { | ||
return timeline + " " + DEFAULT_TIME; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,38 @@ | |
|
||
import duke.Parser; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
public class Deadline extends Task { | ||
protected LocalDate by; | ||
|
||
static protected String DEFAULT_TIME = "2359"; | ||
protected LocalDateTime by; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if others will understand what the |
||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = Parser.stringToDate(by); | ||
super(description); | ||
this.by = Parser.stringToDateTime(by); | ||
} | ||
|
||
@Override | ||
public String getStatusIcon() { | ||
return "[D]" + super.getStatusIcon(); | ||
} | ||
|
||
public String getBy() { | ||
return Parser.dateTimeToString(by); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return super.getDescription() + " (by: " + this.by + ")"; | ||
return super.getDescription() + " (by: " + this.getBy() + ")"; | ||
} | ||
|
||
public String parseBySaving() { | ||
return Parser.dateTimeSaving(by); | ||
} | ||
|
||
@Override | ||
public String saveString() { | ||
return String.format("D|%s|%s|%s", super.saveString(), super.description, this.by); | ||
return String.format("D|%s|%s|%s", super.saveString(), super.description, this.parseBySaving()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should Parser have a descriptive header comment?