Guest User

Untitled

a guest
Oct 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. extension Calendar {
  2. /**
  3. Returns a tuple containing the start and end dates for the week that the
  4. specified date falls in.
  5. */
  6. func weekDatesForDate(date: NSDate) -> (start: NSDate, end: NSDate) {
  7. var interval: TimeInterval = 0
  8. var start: NSDate?
  9. range(of: .weekOfYear, start: &start, interval: &interval, for: date as Date)
  10. let end = start!.addingTimeInterval(interval)
  11.  
  12. return (start!, end)
  13. }
  14. }
  15.  
  16. extension NSCalendar {
  17. /**
  18. Returns a tuple containing the start and end dates for the week that the
  19. specified date falls in.
  20. */
  21. func weekDatesForDate(date: NSDate) -> (start: NSDate, end: NSDate) {
  22. var interval: TimeInterval = 0
  23. var start: NSDate?
  24. range(of: .weekOfYear, start: &start, interval: &interval, for: date as Date)
  25. let end = start!.addingTimeInterval(interval)
  26.  
  27. return (start!, end)
  28. }
  29. }
Add Comment
Please, Sign In to add comment