Skip to content

Commit

Permalink
validate date format yyyy-mm-dd
Browse files Browse the repository at this point in the history
  • Loading branch information
TsimurSh committed May 19, 2024
1 parent 2c9dc03 commit c88d0c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/org/transitclock/core/reports/SqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,17 @@ public static String timeRangeClause(

SimpleDateFormat currentFormat = new SimpleDateFormat("MM-dd-yyyy");
SimpleDateFormat requiredFormat = new SimpleDateFormat("yyyy-MM-dd");
if (beginDate.charAt(4) != '-') { // for two patterns MM-dd-yyyy & yyyy-MM-dd

try {
beginDate = requiredFormat.format(currentFormat.parse(beginDate));
if (beginDate.charAt(4) != '-') { // for two patterns MM-dd-yyyy & yyyy-MM-dd
beginDate = requiredFormat.format(currentFormat.parse(beginDate));
} else {
requiredFormat.parse(beginDate);
}
} catch (ParseException e) {
logger.error("Exception happened while processing time-range clause", e);
}
}

return " AND %s BETWEEN '%s' AND TIMESTAMP '%s' + INTERVAL '%d day' %s "
.formatted(timeColumnName, beginDate, beginDate, numDays, timeSql);
}
Expand Down

0 comments on commit c88d0c8

Please sign in to comment.