Skip to content

Commit 2876a4c

Browse files
authored
Merge pull request #116 from solomonng2001/fix-dates-bugs-and-fix-message-display
Fix dates and display messages
2 parents 0071858 + d6c03b1 commit 2876a4c

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

src/main/java/seedu/address/commons/util/DateTimeUtil.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,24 @@ public static boolean isParsableDateTimeString(String test) {
3838
return false;
3939
}
4040

41+
LocalDateTime dateTime;
42+
4143
try {
42-
LocalDateTime.parse(test, DateTimeFormatter.ofPattern(DATE_FORMAT));
43-
return true;
44+
dateTime = LocalDateTime.parse(test, DateTimeFormatter.ofPattern(DATE_FORMAT));
4445
} catch (DateTimeParseException e) {
4546
return false;
4647
}
48+
49+
// Date is not parsable if truncation needed, eg. 29 Feb on non leap years will be truncated by parser
50+
if (!DateTimeUtil.parseDateToString(dateTime).equals(test)) {
51+
return false;
52+
}
53+
54+
if (dateTime == null) {
55+
return false;
56+
}
57+
58+
return true;
4759
}
4860

4961
/**

src/main/java/seedu/address/commons/util/DateUtil.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* Helper functions for handling dates and times.
1010
*/
1111
public class DateUtil {
12-
public static final String MESSAGE_CONSTRAINTS = "should be in the format YYYY-MM-DD and must be an actual date";
12+
public static final String MESSAGE_CONSTRAINTS =
13+
"date should be in the format YYYY-MM-DD and must be an actual date.";
1314
public static final String DATE_FORMAT = "yyyy-MM-dd";
1415
public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2}";
1516

@@ -37,12 +38,24 @@ public static boolean isParsableDateString(String test) {
3738
return false;
3839
}
3940

41+
LocalDate date;
42+
4043
try {
41-
LocalDate.parse(test, DateTimeFormatter.ofPattern(DATE_FORMAT));
42-
return true;
44+
date = LocalDate.parse(test, DateTimeFormatter.ofPattern(DATE_FORMAT));
4345
} catch (DateTimeParseException e) {
4446
return false;
4547
}
48+
49+
// Date is not parsable if truncation needed, eg. 29 Feb on non leap years will be truncated by parser
50+
if (!DateUtil.parseDateToString(date).equals(test)) {
51+
return false;
52+
}
53+
54+
if (date == null) {
55+
return false;
56+
}
57+
58+
return true;
4659
}
4760

4861
/**

src/main/java/seedu/address/logic/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Messages {
1818
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
1919
public static final String MESSAGE_LASTMET_FUTURE = "You cannot meet someone from the future.";
2020
public static final String MESSAGE_SCHEDULE_PAST = "You cannot schedule an appointment in the past.";
21-
public static final String MESSAGE_SCHEDULE_DONE = "This schedule has already been completed.";
21+
public static final String MESSAGE_SCHEDULE_DONE = "This client has no unmarked scheduled appointments.";
2222
public static final String MESSAGE_DUPLICATE_FIELDS =
2323
"Multiple values specified for the following single-valued field(s): ";
2424
public static final String MESSAGE_DUPLICATE_POLICY =

src/main/java/seedu/address/logic/commands/MarkCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
public class MarkCommand extends Command {
2222
public static final String COMMAND_WORD = "mark";
2323

24-
public static final String MESSAGE_USAGE = COMMAND_WORD + ": marks a schedule as done. "
24+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": marks a scheduled appointment with a client as done. "
2525
+ "Parameters: "
26-
+ "INDEX "
26+
+ "INDEX (client's index: must be a positive integer)\n"
2727
+ "Example: " + COMMAND_WORD + " "
2828
+ "1 ";
2929

src/main/java/seedu/address/logic/parser/LastMetCommandParser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* Parses input arguments and creates a new LastMetCommand object
2121
*/
2222
public class LastMetCommandParser {
23+
public static final String DATE_MESSAGE_CONSTRAINTS = DateUtil.getMessageConstraintsForDateType("LastMet");
2324

2425
/**
2526
* Parses the given {@code String} of arguments in the context of the LastMetCommand
@@ -46,6 +47,9 @@ public LastMetCommand parse(String args) throws ParseException {
4647

4748
String lastMetString = argMultimap.getValue(PREFIX_LASTMET).orElse("");
4849

50+
if (!DateUtil.isValidDateString(lastMetString)) {
51+
throw new ParseException(DATE_MESSAGE_CONSTRAINTS);
52+
}
4953
try {
5054
LastMet lastMet = convertStringToLastMet(lastMetString);
5155
return new LastMetCommand(index, lastMet);
@@ -62,7 +66,10 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre
6266
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
6367
}
6468

65-
private LastMet convertStringToLastMet(String input) {
69+
private LastMet convertStringToLastMet(String input) throws DateTimeParseException {
70+
if (!DateUtil.isValidDateString(input)) {
71+
throw new DateTimeParseException(DATE_MESSAGE_CONSTRAINTS, input, 0);
72+
}
6673
LocalDate formattedInput = DateUtil.parseStringToDate(input);
6774
return new LastMet(formattedInput);
6875
}

src/main/java/seedu/address/logic/parser/ScheduleCommandParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import seedu.address.commons.core.index.Index;
1212
import seedu.address.commons.exceptions.IllegalValueException;
1313
import seedu.address.commons.util.DateTimeUtil;
14+
import seedu.address.commons.util.DateUtil;
1415
import seedu.address.logic.commands.ScheduleCommand;
1516
import seedu.address.logic.parser.exceptions.ParseException;
1617
import seedu.address.model.person.Schedule;
@@ -19,6 +20,7 @@
1920
* Parses input arguments and creates a new ScheduleCommand object
2021
*/
2122
public class ScheduleCommandParser {
23+
public static final String DATE_MESSAGE_CONSTRAINTS = DateUtil.getMessageConstraintsForDateType("Schedule");
2224

2325
/**
2426
* Parses the given {@code String} of arguments in the context of the ScheduleCommand
@@ -46,6 +48,9 @@ public ScheduleCommand parse(String args) throws ParseException {
4648

4749
String scheduleString = argMultimap.getValue(PREFIX_SCHEDULE).orElse("");
4850

51+
if (!DateTimeUtil.isValidDateTimeString(scheduleString)) {
52+
throw new ParseException(DATE_MESSAGE_CONSTRAINTS);
53+
}
4954
try {
5055
Schedule schedule = convertStringToSchedule(scheduleString);
5156
return new ScheduleCommand(index, schedule);

src/main/java/seedu/address/model/person/Birthday.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* Guarantees: immutable; is valid as declared in {@link #isValidBirthday(String)}
1313
*/
1414
public class Birthday implements Comparable<Birthday> {
15-
public static final String MESSAGE_CONSTRAINTS = DateUtil.getMessageConstraintsForDateType("Birthday");
15+
public static final String MESSAGE_CONSTRAINTS = DateUtil.getMessageConstraintsForDateType("Birthday")
16+
+ " Birthday should not be in the future.";
1617
public final LocalDate date;
1718

1819
/**

0 commit comments

Comments
 (0)