Hi everyone I'm trying to get a positive answer when comparing a date earlier than today
To do this I am using a Date
extension with this boolean
extension Date {
var isPreviousDate: Bool {
return self.timeIntervalSinceNow.sign == .minus
}
}
Here is my problem .. when I print the date to compare it tells me that today's date is earlier and I don't understand why
Since I'm having problems I tried to create a current date and compare it with today's date the answer is that today's date is earlier than today ... this is weird because it shouldn't tell me it's older
This is how I create the date
to compare
var calendar = Calendar(identifier: Calendar.current.identifier)
calendar.timeZone = NSTimeZone(name: "UTC")! as TimeZone
guard let selectedDate = calendar.date(from: DateComponents(year: Date().currentYear, month: Date().currentMonth, day: Date().currentDate)) else { return }
print("isPrevious Date :",selectedDate.isPreviousDate)
print(selectedDate)
am I doing something wrong?
this is what I read in the console when I print the created date to compare
isPrevious Date: true
2021-02-11 00:00:00 +0000