Created
August 10, 2016 14:35
-
-
Save Bashta/8ce1309938a6c2f9a136668a0d91fbdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSDate { | |
func startOfDay(calendar: NSCalendar) -> NSDate { | |
return calendar.startOfDayForDate(self) | |
} | |
func endOfDay(calendar: NSCalendar) -> NSDate? { | |
let components = NSDateComponents() | |
components.day = 1 | |
components.second = -1 | |
return calendar.dateByAddingComponents(components, toDate: startOfDay(calendar), options: NSCalendarOptions()) | |
} | |
func tomorrowDay(calendar: NSCalendar) -> NSDate? { | |
let components = NSDateComponents() | |
components.second = 1 | |
guard let endOfToday = NSDate().endOfDay(calendar) else { | |
return nil | |
} | |
return calendar.dateByAddingComponents(components, toDate: endOfToday, options: NSCalendarOptions()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment