forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #186 from ryanlimdx/fix-dates
Aims to refactor the code base for date classes
- Loading branch information
Showing
14 changed files
with
118 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package seedu.address.commons.util; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* A utility class for handling dates. | ||
*/ | ||
public class DateUtil { | ||
|
||
public static final String MESSAGE_CONSTRAINTS_FORMAT = "%1$s takes in a date of format dd/MM/yyyy"; | ||
public static final String MESSAGE_CONSTRAINTS_FUTURE_OCCURRENCE = "%1$s should not be later than current date"; | ||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); | ||
|
||
/** | ||
* Returns true if a given string is a valid date. | ||
* | ||
* @param value The date to be checked. | ||
*/ | ||
public static boolean isValidDate(String value) { | ||
try { | ||
LocalDate date = LocalDate.parse(value, formatter); | ||
return true; | ||
} catch (DateTimeParseException e) { | ||
return false; | ||
} | ||
} | ||
/** | ||
* Returns true if a given string is a future date. | ||
* | ||
* @param value The date to be checked. | ||
*/ | ||
public static boolean isFutureDate(String value) { | ||
if (isValidDate(value)) { | ||
LocalDate date = LocalDate.parse(value, formatter); | ||
return date.isAfter(LocalDate.now()); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the formatter for the date. | ||
*/ | ||
public static DateTimeFormatter getFormatter() { | ||
return formatter; | ||
} | ||
} |
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
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
Oops, something went wrong.