fix birthday date validation
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 38s

This commit is contained in:
Lee 2024-06-30 03:47:34 +01:00
parent b66114503c
commit b7f2b6a3d7

@ -58,7 +58,10 @@ public class SetSubCommand extends BatSubCommand {
Date birthday = parseBirthday(birthdayString); Date birthday = parseBirthday(birthdayString);
if (birthday == null) { if (birthday == null) {
interaction.replyEmbeds(EmbedUtils.errorEmbed() 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(); .build()).queue();
return; return;
} }
@ -79,9 +82,16 @@ public class SetSubCommand extends BatSubCommand {
*/ */
private Date parseBirthday(String birthday) { private Date parseBirthday(String birthday) {
try { try {
return FORMATTER.parse(birthday); Date date = FORMATTER.parse(birthday);
} catch (ParseException ignored) { if (date.after(new Date())) {
return null;
} }
if (date.toInstant().toEpochMilli() < 0) {
return null;
}
return date;
} catch (ParseException ignored) {
return null; return null;
} }
} }
}