What is the best way to properly check if a date is at least tomorrow?

So far I was able to come up with this solution, but I'm not 100% sure it's correct:

let calendar = Calendar.current

func isAtLeastTomorrow(_ date: Date) -> Bool {
    let now = Date()
    let startOfToday = calendar.startOfDay(for: now)
    let startOfTomorrow = calendar.date(byAdding: .day, value: 1, to: startOfToday)!
    
    return startOfTomorrow.timeIntervalSince1970 - date.timeIntervalSince1970 <= 0
}


let someDate = Date(timeIntervalSinceNow: 60 * 60 * 16)
isAtLeastTomorrow(someDate)

2 Replies 2

You can simply check if the date is in the future and not today. No need for any manual calculations.

func isAtLeastTomorrow(_ date: Date) -> Bool {
    date > .now && !calendar.isDateInToday(date)
}

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.