Skip to content
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

Fix bugs on Birthday, Money, ClaimCommandParser #69

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ClaimCommandParser implements Parser<ClaimCommand> {
public ClaimCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CLAIM_AMOUNT);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_CLAIM_AMOUNT);

Index index;
Claim claim;
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/seedu/address/model/person/Birthday.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
* Represents a Person's dob.
*/
public class Birthday {
public static final String MESSAGE_CONSTRAINTS =
"Invalid date of birth. Please provide date of birth with format: YYYY-MM-DD";
"Invalid date of birth. Please provide date of birth with format: YYYY-MM-DD.\n"
+ "An employee must be at least 13 years old.";

public final String dob;

Expand All @@ -23,12 +26,8 @@
public Birthday(String dateStr) {
requireNonNull(dateStr);
dateStr = dateStr.trim();
try {
LocalDate.parse(dateStr);
dob = dateStr;
} catch (DateTimeException e) {
throw new IllegalArgumentException(MESSAGE_CONSTRAINTS);
}
checkArgument(isValidDob(dateStr), MESSAGE_CONSTRAINTS);
dob = dateStr;
}

/**
Expand All @@ -37,7 +36,11 @@
public static boolean isValidDob(String test) {
String dateStr = test.trim();
try {
LocalDate.parse(dateStr);
LocalDate birthday = LocalDate.parse(dateStr);
LocalDate legalBirthday = LocalDate.now().minusYears(13);
if (legalBirthday.until(birthday, ChronoUnit.DAYS) > 0) {
return false;

Check warning on line 42 in src/main/java/seedu/address/model/person/Birthday.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L42 was not covered by tests
}
} catch (DateTimeException e) {
return false;
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/seedu/address/model/person/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ public class Money {
*/
public Money(String numStr) {
requireNonNull(numStr);
checkArgument(numStr.length() < 14, MESSAGE_CONSTRAINTS);
try {
Long num = Long.valueOf(numStr);
checkArgument(num >= 0 && num <= MAX_VALUE, MESSAGE_CONSTRAINTS);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(MESSAGE_CONSTRAINTS);
}
checkArgument(isValidMoney(numStr), MESSAGE_CONSTRAINTS);
amount = numStr;
}

/**
* Returns true if a given string is a valid dollar amount.
*/
public static boolean isValidMoney(String test) {
if (test.length() >= 14) {
return false;
}
try {
Long num = Long.valueOf(test);
return num >= 0 && num <= MAX_VALUE;
Expand Down
Loading