Skip to content

Commit

Permalink
validate date format
Browse files Browse the repository at this point in the history
Signed-off-by: msvinaykumar <vinakuma@redhat.com>
  • Loading branch information
msvinaykumar committed Aug 11, 2023
1 parent 689b1c4 commit e72378b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/autotune/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ public static boolean isAValidDate(String format, String date) {
try {
if (null == format || null == date)
return false;
Date _unused = (new SimpleDateFormat(format)).parse(date);
return true;
SimpleDateFormat dateFormat = (new SimpleDateFormat(format));
dateFormat.setLenient(false);
Date parsedDate = dateFormat.parse(date);
return date.equals(dateFormat.format(parsedDate));
} catch (Exception e) {
return false;
}
Expand Down

0 comments on commit e72378b

Please sign in to comment.