Skip to content

Commit

Permalink
Merge pull request #162 from ChuaZiLong/branch-Bugs
Browse files Browse the repository at this point in the history
Fix some bugs for add schedule, calendar view and export
  • Loading branch information
sarjinius authored Apr 14, 2024
2 parents b36236c + 2296a0d commit 40ba1b4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ Format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…​`

<box type="info" seamless>

* Edits the person at the specified `INDEX`.
* The index refers to the index number shown in the displayed person list.
* Edits the person at the specified `INDEX`.
* The index refers to the index number shown in the displayed person list.
* The index **must be a positive integer**, such as 1, 2, 3, ...
* At least one of the optional fields must be provided. This means that either `NAME`, `PHONE`, `EMAIL`, `ADDRESS` or `TAG` needs to be provided.
* When editing tags, the existing tags of the person will be removed i.e., adding of tags is not cumulative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public CommandResult execute(Model model) {

Scene scene = new Scene(calendarView, 600, 400);
stage.setScene(scene);

stage.show();
});

Expand Down
18 changes: 11 additions & 7 deletions src/main/java/scm/address/logic/commands/FindAndExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ public class FindAndExportCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Exports the users filtered by a tag "
+ "and other optional parameters.\n"
+ "Parameters: "
+ "TAG"
+ "[" + PREFIX_NAME + "NAME]"
+ "[" + PREFIX_ADDRESS + "ADDRESS]"
+ "TAG, "
+ "[" + PREFIX_NAME + "NAME], "
+ "[" + PREFIX_ADDRESS + "ADDRESS], "
+ "[" + PREFIX_FILENAME + "FILENAME]\n"
+ "Example: " + COMMAND_WORD
+ " "
+ "cs2103t"
+ PREFIX_NAME + " john"
+ PREFIX_ADDRESS + " olive street 42"
+ PREFIX_FILENAME + " f/output1.json";
+ " "
+ PREFIX_NAME + "john"
+ " "
+ PREFIX_ADDRESS + "olive street 42"
+ " "
+ PREFIX_FILENAME + "output1.json";
public static final String FILE_NOT_WRITABLE_MESSAGE = "File exists but is not writable: ";
public static final String MESSAGE_UNSUPPORTED_FILE_FORMAT = "Unsupported file format: ";
private final String tag;
Expand Down Expand Up @@ -104,7 +108,7 @@ public CommandResult execute(Model model) throws CommandException {
}

private Predicate<Person> createPredicateForFiltering(String tag, String name, String address) {
Predicate<Person> predicate = person -> true; // start with a predicate that always returns true
Predicate<Person> predicate = person -> true;

if (tag != null && !tag.isBlank()) {
predicate = predicate.and(person -> person.getTags().stream().anyMatch(t -> t.tagName.equals(tag)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static scm.address.logic.parser.CliSyntax.PREFIX_START_DATETIME;
import static scm.address.logic.parser.CliSyntax.PREFIX_TITLE;

import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.stream.Stream;
Expand Down Expand Up @@ -47,30 +48,26 @@ public AddScheduleCommand parse(String userInput) throws ParseException {

if (!arePrefixesPresent(argMultimap, PREFIX_TITLE,
PREFIX_DESCRIPTION, PREFIX_START_DATETIME, PREFIX_END_DATETIME)
|| !argMultimap.getPreamble().isEmpty()) {
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
MESSAGE_USAGE));
}

Title title = ParserUtil.parseTitle(argMultimap.getValue(PREFIX_TITLE).get());
Description description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get());
String startDateTime = argMultimap.getValue(PREFIX_START_DATETIME).get();
String startYear = startDateTime.substring(0, 4);
String startMonth = startDateTime.substring(5, 7);
String startDay = startDateTime.substring(8, 10);
String startHour = startDateTime.substring(11, 13);
String startMinute = startDateTime.substring(14, 16);
String endDateTime = argMultimap.getValue(PREFIX_END_DATETIME).get();
String endYear = endDateTime.substring(0, 4);
String endMonth = endDateTime.substring(5, 7);
String endDay = endDateTime.substring(8, 10);
String endHour = endDateTime.substring(11, 13);
String endMinute = endDateTime.substring(14, 16);
Schedule schedule = new Schedule(title, description,
LocalDateTime.of(Integer.parseInt(startYear), Integer.parseInt(startMonth),
Integer.parseInt(startDay), Integer.parseInt(startHour), Integer.parseInt(startMinute)),
LocalDateTime.of(Integer.parseInt(endYear), Integer.parseInt(endMonth),
Integer.parseInt(endDay), Integer.parseInt(endHour), Integer.parseInt(endMinute)));

try {
LocalDateTime start = LocalDateTime.parse(startDateTime, FORMATTER);
LocalDateTime end = LocalDateTime.parse(endDateTime, FORMATTER);
} catch (DateTimeException e) {
throw new ParseException("Invalid date and/or time.", e);
}

LocalDateTime start = LocalDateTime.parse(startDateTime, FORMATTER);
LocalDateTime end = LocalDateTime.parse(endDateTime, FORMATTER);
Schedule schedule = new Schedule(title, description, start, end);

return new AddScheduleCommand(schedule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,25 @@ public void isFirstDateTimeBeforeSecond_validDateTimes_firstIsAfter() {

assertFalse(result, "First date-time should not be before the second date-time");
}

@Test
public void parse_invalidMonth_throwsParseException() {
AddScheduleCommandParser parser = new AddScheduleCommandParser();
String startDateTime = "2023-13-21 15:00";
String endDateTime = "2023-03-21 16:00";
String input = "add_schedule title/Meeting d/Discussion start/" + startDateTime + " end/" + endDateTime;

assertThrows(ParseException.class, () -> parser.parse(input));
}

@Test
public void parse_invalidDay_throwsParseException() {
AddScheduleCommandParser parser = new AddScheduleCommandParser();
String startDateTime = "2023-03-32 15:00";
String endDateTime = "2023-03-21 16:00";

String input = "add_schedule title/Meeting d/Discussion start/" + startDateTime + " end/" + endDateTime;

assertThrows(ParseException.class, () -> parser.parse(input));
}
}

0 comments on commit 40ba1b4

Please sign in to comment.