Bug 267

Summary: Time method cannot compare time correctly.
Product: Group 1: FSFBS Reporter: hohintang2-c
Component: CoreAssignee: Justin <yhwong56-c>
Status: RESOLVED FIXED    
Severity: major CC: hohintang2-c
Priority: High    
Version: unspecified   
Hardware: Macintosh   
OS: Mac OS   
Deadline: 2018-11-29   

Description hohintang2-c 2018-11-29 15:04:12 HKT
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;
        }
}
Comment 1 Justin 2018-12-09 23:34:14 HKT
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!