Active button when 10 minutes is left from current time in swift

Active button when 10 minutes is left from current time in swift.

func isActiveButton(bookingDate: String) -> Bool {
        var isActive: Bool = false
      //  1. Check date is future or not
        let currentDate: String = self.getCurrentDate("yyyy-MM-dd HH:mm:ss")
        let dateCurrent: Date = self.stringToDate(currentDate, strformate: "yyyy-MM-dd HH:mm:ss")
        let dateBooking: Date = self.stringToDate(bookingDate, strformate: "yyyy-MM-dd HH:mm:ss")
        if dateBooking > dateCurrent {
           // 2. if future then minus 10 minute from date and get new date
            let dateActive: Date = dateBooking.addingTimeInterval(-600)
           // 3. check new date and current date if current date is bigger than new date then active begin button
            if dateCurrent > dateActive {
                isActive = true
            }
        }
        return isActive
    }

Get current time

func getCurrentDate(_ dateFormate: String) -> String {
        let currDate = Date()
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = dateFormate
        let currentDate: String = dateFormatter.string(from: currDate)
        return currentDate
    }

Convert string formate to date formate

func stringToDate(_ str: String, strformate: String) -> Date {
        let formatter = DateFormatter()
        formatter.dateFormat = strformate
        return formatter.date(from: str)!
    }

Convert date formate to string formate

func dateToString(_ str: Date, strformate: String) -> String{
        let formatter = DateFormatter()
        formatter.dateFormat = strformate
        return formatter.string(from: str)
    }