Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (NSInteger)getEducationWeekFromDate:(NSDate *)date{
  2.    
  3.     NSCalendar *calendar = [NSCalendar currentCalendar];
  4.     NSDateComponents *components = [[NSDateComponents alloc]init];
  5.     components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekdayCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit| NSMinuteCalendarUnit) fromDate:date];
  6.     components.day = components.day - [self weekDayFromDay:date];
  7.     components.hour = 0;
  8.     components.minute = 0;
  9.     date = [calendar dateFromComponents:components];
  10.    
  11.     NSDate *timeTableStartDate = self.startDate;
  12.     components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekdayCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit| NSMinuteCalendarUnit) fromDate:timeTableStartDate];
  13.     components.day = components.day - [self weekDayFromDay:timeTableStartDate];
  14.     components.hour = 0;
  15.     components.minute = 0;
  16.    
  17.     timeTableStartDate = [calendar dateFromComponents:components];
  18.     NSInteger weeks = [[calendar components:NSWeekCalendarUnit fromDate:timeTableStartDate toDate:date options:0]week] + 1;
  19.     return weeks;
  20.    
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement