Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonwidjaja committed Oct 12, 2023
1 parent 6a3a32e commit b18a3fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
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 class Birthday {
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 Birthday(String dateStr) {
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

0 comments on commit b18a3fd

Please sign in to comment.