6 Replies
      Latest reply on Jan 24, 2017 11:47 AM by goldsdad
      JayCo Level 1 Level 1 (5 points)



        I'm trying to compare two times against each other for a checkTimer method. I've got the functionality right, it's the 24 hour issue that's causing a problem.

        The functionality should be that if the current time is greater than the userDefault time then return true. The Bug exists where it's the next day. Am I better comparing two dates against each other or is there a simpler way.


        My method

        func checkTimer() -> Bool {
                let time = Int(currentTime())!
                let storedTime = Int(UserDefaults.standard.integer(forKey: "LastAccessTime"))
                if time >= storedTime {
                    print("Enough time has passed \(storedTime)")
                    return true
                print("Not enough time has passed \(storedTime)")
                return false
            func currentTime() -> String {
                let currentTime = Date()
                let formatter = DateFormatter()
                formatter.dateFormat = "Hmm"
                let time = formatter.string(from: currentTime)
                return "\(time)"