fix birthday date validation
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 38s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 38s
This commit is contained in:
parent
b66114503c
commit
b7f2b6a3d7
@ -58,7 +58,10 @@ public class SetSubCommand extends BatSubCommand {
|
||||
Date birthday = parseBirthday(birthdayString);
|
||||
if (birthday == null) {
|
||||
interaction.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("Invalid birthday format. Please use the format: DAY/MONTH/YEAR - 01/05/2004")
|
||||
.setDescription("""
|
||||
Invalid birthday format. Please use the following format:
|
||||
DAY/MONTH/YEAR - 01/05/2004
|
||||
""")
|
||||
.build()).queue();
|
||||
return;
|
||||
}
|
||||
@ -79,9 +82,16 @@ public class SetSubCommand extends BatSubCommand {
|
||||
*/
|
||||
private Date parseBirthday(String birthday) {
|
||||
try {
|
||||
return FORMATTER.parse(birthday);
|
||||
Date date = FORMATTER.parse(birthday);
|
||||
if (date.after(new Date())) {
|
||||
return null;
|
||||
}
|
||||
if (date.toInstant().toEpochMilli() < 0) {
|
||||
return null;
|
||||
}
|
||||
return date;
|
||||
} catch (ParseException ignored) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user