The method isTimeLaterThanCurrentTime compare the times lot with the current time. If the times lot is later than the current time, the method returns false. However, a problem occurs when the user add a book that is the same hour with the current time. Let say the current time is 11:00:00. If I enter the parameter as 11:15:00 which has the same hour and minute larger than the current time, it still returns false. I expect it to return true as 11:15:00 is later than current time 11:00:00. Here is the code for you public boolean isTimeLaterThanCurrentTime(String inputTime) { int currentHour, currentMin, currentSec; int inputHour, inputMin, inputSec; int currentHour; int inputHour; String currentTime = getCurrentTime(); currentHour = Integer.parseInt(currentTime.substring(0, 2)); currentMin = Integer.parseInt(currentTime.substring(3, 5)); currentSec = Integer.parseInt(currentTime.substring(6, 8)); inputHour = Integer.parseInt(inputTime.substring(0, 2)); inputMin = Integer.parseInt(inputTime.substring(3, 5)); inputSec = Integer.parseInt(inputTime.substring(6, 8)); //checking if (currentHour > inputHour) { return false; } else if (currentMin > inputMin) { return false; } else if (currentSec > inputSec) { return false; } else { return true; } }
Problem can be reproduced. Turn out I found that we do not need to compare minutes and seconds. The problem can be solved by updating the code as below: public boolean isTimeLaterThanCurrentTime(String inputTime) { int currentHour; int inputHour; String currentTime = getCurrentTime(); currentHour = Integer.parseInt(currentTime.substring(0, 2)); inputHour = Integer.parseInt(inputTime.substring(0, 2)); //checking return currentHour < inputHour; } Thank you for your bug report btw!