Skip to content

Commit

Permalink
fix -ve pi bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LimZiJia committed Apr 14, 2024
1 parent 41145d7 commit 0c00bdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Notes:
* `AREA` can be either 'east', 'southeast', 'south', 'southwest', 'west', 'northwest', 'north', or 'northeast'.
* `DETAILS` is optional and refers to the housekeeping details for CLIENT ONLY. It is not applicable for housekeepers.
The format for `DETAILS` is `d/yyyy-MM-dd NUMBER INTERVAL` where `yyyy-MM-dd` is the date of the last
housekeeping, `NUMBER` is the quantity of `INTERVAL`(s) which can be ***'days', 'weeks', 'months' or 'years'.***
housekeeping, `NUMBER` is the (non-negative) quantity of `INTERVAL`(s) which can be ***'days', 'weeks', 'months' or 'years'.***
This `INTERVAL` is the period between housekeeping sessions that the client prefers. It is meant to be an estimate, so
options such as `2 weeks and 3 days` are not supported. If precision is needed, you should convert it to `NUMBER days`.

Expand Down Expand Up @@ -289,7 +289,7 @@ General format: `booking TYPE ACTION INDEX [PARAMETERS]`
<div markdown="span" class="alert alert-primary">:bulb: **Tip:**
For the subcommands of booking below, here are some clarifications.<br>
`INDEX` refers to the index of the observed client/housekeeper list.<br>
`NUMBER` refers to any integer. This could represent the quantity of `INTERVAL`(s).<br>
`NUMBER` refers to a non-negative integer. This could represent the quantity of `INTERVAL`(s).<br>
`INTERVAL` refers to a period, which can be 'days', 'weeks', 'months' or 'years'.
This `INTERVAL` is the period between housekeeping sessions that the client prefers. It is meant to be an estimate, so
options such as `2 weeks and 3 days` are not supported. If precision is needed, you should convert it to `NUMBER days`.<br>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/housekeeping/hub/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public static Period parsePreferredInterval(String pI) throws ParseException {
String[] splitPI = trimmedPI.split("\\s+");
Period period;
int quantity = Integer.parseInt(splitPI[0]);
if (quantity <= 0) {
throw new ParseException(HousekeepingDetails.MESSAGE_CONSTRAINTS);
}
switch (splitPI[1]) {
case "days":
period = Period.ofDays(quantity);
Expand Down Expand Up @@ -254,6 +257,9 @@ public static HousekeepingDetails parseHousekeepingDetails(Optional<String> deta
s = trimmedDetails.split(" ");
date = LocalDate.parse(s[0]);
quantity = Integer.parseInt(s[1]);
if (quantity <= 0) {
throw new ParseException(HousekeepingDetails.MESSAGE_CONSTRAINTS);
}
} catch (DateTimeParseException e) {
throw new ParseException(e.getMessage());
}
Expand Down

0 comments on commit 0c00bdb

Please sign in to comment.