Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension Calendar {
- /**
- Returns a tuple containing the start and end dates for the week that the
- specified date falls in.
- */
- func weekDatesForDate(date: NSDate) -> (start: NSDate, end: NSDate) {
- var interval: TimeInterval = 0
- var start: NSDate?
- range(of: .weekOfYear, start: &start, interval: &interval, for: date as Date)
- let end = start!.addingTimeInterval(interval)
- return (start!, end)
- }
- }
- extension NSCalendar {
- /**
- Returns a tuple containing the start and end dates for the week that the
- specified date falls in.
- */
- func weekDatesForDate(date: NSDate) -> (start: NSDate, end: NSDate) {
- var interval: TimeInterval = 0
- var start: NSDate?
- range(of: .weekOfYear, start: &start, interval: &interval, for: date as Date)
- let end = start!.addingTimeInterval(interval)
- return (start!, end)
- }
- }
Add Comment
Please, Sign In to add comment