Bug 267 - Time method cannot compare time correctly.
Summary: Time method cannot compare time correctly.
Status: RESOLVED FIXED
Alias: None
Product: Group 1: FSFBS
Classification: Unclassified
Component: Core (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: High major
Deadline: 2018-11-29
Assignee: Justin
URL:
Depends on:
Blocks:
 
Reported: 2018-11-29 15:04 HKT by hohintang2-c
Modified: 2018-12-09 23:34 HKT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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!