forked from nus-cs2103-AY2223S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from yixiann/fix-dates
Ensure we cannot create an item with bought date after expiry date
- Loading branch information
Showing
13 changed files
with
314 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package seedu.foodrem.model.item; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* Represents an item date in an {@link Item}. | ||
* Guarantees: details are present and not null, immutable. | ||
*/ | ||
public abstract class ItemDate { | ||
// Remember to change relevant messages displayed to users when changing the regex. | ||
public static final String DATE_PATTERN_REGEX = "dd-MM-uuuu"; | ||
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter | ||
.ofPattern(DATE_PATTERN_REGEX); | ||
|
||
private final LocalDate date; | ||
|
||
protected ItemDate(LocalDate date) { | ||
this.date = date; | ||
} | ||
|
||
public LocalDate getDate() { | ||
return date; | ||
} | ||
|
||
public int compareTo(ItemDate other) { | ||
return date.compareTo(other.date); | ||
} | ||
|
||
/** | ||
* Returns true if the given datetime object is after or on the same date. | ||
* | ||
* @param datetime The datetime object to compare against | ||
*/ | ||
public boolean isAfterOrOnDate(LocalDate datetime) { | ||
return date.isAfter(datetime.minusDays(1)); | ||
} | ||
|
||
/** | ||
* Returns true if the given ItemDate object is after the date. | ||
* | ||
* @param itemDate The ItemDate object to compare against | ||
*/ | ||
public boolean isAfterDate(ItemDate itemDate) { | ||
return date.isAfter(itemDate.date); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
return other == this | ||
&& other instanceof ItemDate | ||
&& date.equals(((ItemDate) other).date); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return date.hashCode(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String toString() { | ||
return date.format(DATE_FORMATTER); | ||
} | ||
} |
Oops, something went wrong.