diff --git a/src/main/java/seedu/waddle/logic/commands/EditItemCommand.java b/src/main/java/seedu/waddle/logic/commands/EditItemCommand.java index 32c238445e8..a6aa9308292 100644 --- a/src/main/java/seedu/waddle/logic/commands/EditItemCommand.java +++ b/src/main/java/seedu/waddle/logic/commands/EditItemCommand.java @@ -5,6 +5,7 @@ import static seedu.waddle.logic.parser.CliSyntax.PREFIX_DESCRIPTION; import static seedu.waddle.logic.parser.CliSyntax.PREFIX_DURATION; import static seedu.waddle.logic.parser.CliSyntax.PREFIX_PRIORITY; +import static seedu.waddle.logic.parser.CliSyntax.PREFIX_START_TIME; import java.util.Optional; @@ -18,6 +19,7 @@ import seedu.waddle.model.item.Duration; import seedu.waddle.model.item.Item; import seedu.waddle.model.item.Priority; +import seedu.waddle.model.item.StartTime; import seedu.waddle.model.itinerary.Itinerary; /** @@ -34,7 +36,8 @@ public class EditItemCommand extends Command { + "[" + PREFIX_DESCRIPTION + "DESCRIPTION]" + "[" + PREFIX_PRIORITY + "PRIORITY]" + "[" + PREFIX_COST + "COST]" - + "[" + PREFIX_DURATION + "DURATION]...\n" + + "[" + PREFIX_DURATION + "DURATION]" + + "[" + PREFIX_START_TIME + "START TIME]...\n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_DESCRIPTION + "Visit the Eiffel Tower "; @@ -119,6 +122,7 @@ public static class EditItemDescriptor { private Priority priority; private Cost cost; private Duration duration; + private StartTime startTime; public EditItemDescriptor() { } @@ -132,6 +136,7 @@ public EditItemDescriptor(EditItemDescriptor toCopy) { setPriority(toCopy.priority); setCost(toCopy.cost); setDuration(toCopy.duration); + setStartTime(toCopy.startTime); } /** @@ -173,6 +178,14 @@ public void setDuration(Duration duration) { this.duration = duration; } + public Optional getStartTime() { + return Optional.ofNullable(startTime); + } + + public void setStartTime(StartTime startTime) { + this.startTime = startTime; + } + @Override public boolean equals(Object other) { // short circuit if same object diff --git a/src/main/java/seedu/waddle/logic/parser/CliSyntax.java b/src/main/java/seedu/waddle/logic/parser/CliSyntax.java index 44c73c733e7..a3809276ae6 100644 --- a/src/main/java/seedu/waddle/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/waddle/logic/parser/CliSyntax.java @@ -9,6 +9,7 @@ public class CliSyntax { public static final Prefix PREFIX_NAME = new Prefix("n/"); public static final Prefix PREFIX_COUNTRY = new Prefix("c/"); public static final Prefix PREFIX_START_DATE = new Prefix("sd/"); + public static final Prefix PREFIX_START_TIME = new Prefix("t/"); public static final Prefix PREFIX_ITINERARY_DURATION = new Prefix("dur/"); public static final Prefix PREFIX_PEOPLE = new Prefix("p/"); public static final Prefix PREFIX_BUDGET = new Prefix("b/"); diff --git a/src/main/java/seedu/waddle/logic/parser/EditItemCommandParser.java b/src/main/java/seedu/waddle/logic/parser/EditItemCommandParser.java index bfe0afb9a78..83a218aa93d 100644 --- a/src/main/java/seedu/waddle/logic/parser/EditItemCommandParser.java +++ b/src/main/java/seedu/waddle/logic/parser/EditItemCommandParser.java @@ -6,6 +6,7 @@ import static seedu.waddle.logic.parser.CliSyntax.PREFIX_DESCRIPTION; import static seedu.waddle.logic.parser.CliSyntax.PREFIX_DURATION; import static seedu.waddle.logic.parser.CliSyntax.PREFIX_PRIORITY; +import static seedu.waddle.logic.parser.CliSyntax.PREFIX_START_TIME; import seedu.waddle.commons.core.index.Index; import seedu.waddle.logic.commands.EditItemCommand; @@ -25,7 +26,7 @@ public EditItemCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DESCRIPTION, PREFIX_PRIORITY, - PREFIX_COST, PREFIX_DURATION); + PREFIX_COST, PREFIX_DURATION, PREFIX_START_TIME); Index index; @@ -57,6 +58,11 @@ public EditItemCommand parse(String args) throws ParseException { ParserUtil.parseDuration(argMultimap.getValue(PREFIX_DURATION).get())); } + if (argMultimap.getValue(PREFIX_START_TIME).isPresent()) { + editItemDescriptor.setStartTime( + ParserUtil.parseStartTime(argMultimap.getValue(PREFIX_START_TIME).get())); + } + if (!editItemDescriptor.isAnyFieldEdited()) { throw new ParseException(EditItemCommand.MESSAGE_NOT_EDITED); } diff --git a/src/main/java/seedu/waddle/logic/parser/ParserUtil.java b/src/main/java/seedu/waddle/logic/parser/ParserUtil.java index 1a4e697d9a5..d33e2209b90 100644 --- a/src/main/java/seedu/waddle/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/waddle/logic/parser/ParserUtil.java @@ -8,6 +8,7 @@ import seedu.waddle.model.item.Cost; import seedu.waddle.model.item.Duration; import seedu.waddle.model.item.Priority; +import seedu.waddle.model.item.StartTime; import seedu.waddle.model.itinerary.Budget; import seedu.waddle.model.itinerary.Country; import seedu.waddle.model.itinerary.Date; @@ -189,4 +190,19 @@ public static Duration parseDuration(String duration) throws ParseException { return new Duration(trimmedDuration); } + /** + * Parses a {@code String startTime} into a {@code StartTime}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code startTime} is invalid. + */ + public static StartTime parseStartTime(String startTime) throws ParseException { + requireNonNull(startTime); + String trimmedStartTime = startTime.trim(); + if (!StartTime.isValidStartTime(trimmedStartTime)) { + throw new ParseException(StartTime.MESSAGE_CONSTRAINTS); + } + return new StartTime(startTime); + } + } diff --git a/src/main/java/seedu/waddle/model/item/StartTime.java b/src/main/java/seedu/waddle/model/item/StartTime.java index 5e242a71cea..b781f7f7f5a 100644 --- a/src/main/java/seedu/waddle/model/item/StartTime.java +++ b/src/main/java/seedu/waddle/model/item/StartTime.java @@ -24,14 +24,14 @@ public class StartTime { */ public StartTime(String startTime) { requireNonNull(startTime); - checkArgument(isValidCost(startTime), MESSAGE_CONSTRAINTS); + checkArgument(isValidStartTime(startTime), MESSAGE_CONSTRAINTS); this.startTime = LocalTime.parse(startTime, timeFormatter); } /** * Returns true if a given string is a valid Cost */ - public static boolean isValidCost(String test) { + public static boolean isValidStartTime(String test) { LocalTime time; try { time = LocalTime.parse(test, timeFormatter);