forked from Fascinated/Bat
fix birthday date validation
This commit is contained in:
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (date.toInstant().toEpochMilli() < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
} catch (ParseException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user