Last active
          August 2, 2016 05:15 
        
      - 
      
- 
        Save aqubi/fb13fbddc7428a1a76a8287556df9d6f to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | private func firstDayOfWeek(date:Date) -> Date { | |
| let cal = Calendar.current | |
| let firstWeekDay = cal.firstWeekday | |
| let thisWeekDay = cal.dateComponents([.weekday], from: date).weekday! | |
| var diff = thisWeekDay - firstWeekDay | |
| if thisWeekDay < firstWeekDay { | |
| diff += cal.weekdaySymbols.count | |
| } | |
| diff = -1 * diff | |
| let firstDay = cal.date(byAdding: .day, value: diff, to: date)! | |
| return firstDay | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment