Skip to content

Instantly share code, notes, and snippets.

@Bashta
Created August 10, 2016 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bashta/8ce1309938a6c2f9a136668a0d91fbdc to your computer and use it in GitHub Desktop.
Save Bashta/8ce1309938a6c2f9a136668a0d91fbdc to your computer and use it in GitHub Desktop.
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