From b7f2b6a3d79923a34053e1c1b7514f6cdbb74ad9 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 30 Jun 2024 03:47:34 +0100 Subject: [PATCH] fix birthday date validation --- .../features/birthday/command/SetSubCommand.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java index 5eb9598..d6eb6ca 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java @@ -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; } }