I am doing Open /Close status function that checks and compares current time with open hours of the cafeteria. But it is open till midnight. Midnight represents as 0 how do I compare it to 0? My current code
func displayStatusForBrandywine () -> String
{
let currentDateTime = NSDate()
// get the user's calendar
let userCalendar = NSCalendar.currentCalendar()
// choose which date and time components are needed
let requestedComponents: NSCalendarUnit = [
NSCalendarUnit.Year,
NSCalendarUnit.Month,
NSCalendarUnit.Day,
NSCalendarUnit.Hour,
NSCalendarUnit.Minute,
NSCalendarUnit.Weekday
]
let dateTimeComponents = userCalendar.components(requestedComponents, fromDate: currentDateTime)
var status: String = ""
// get the components
if (dateTimeComponents.hour >= 8 && dateTimeComponets.hour <0) //??
{
status = "Open"
}
else
{
status = "Closed"
}
return status
}