我的函数有问题,该函数应该检索本周的星期一日期。
有时是休息日:
+(NSDate *) lastMondayBeforeDate:(NSDate*)timeStamp {
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps =
[gregorian components:NSWeekdayCalendarUnit fromDate:timeStamp];
NSInteger weekday = [comps weekday];
weekday = weekday==1 ? 6 : weekday-2;
NSTimeInterval secondsSinceMondayMidnight =
(NSUInteger) [timeStamp timeIntervalSince1970] % 60*60*24 +
weekday * 60*60*24;
NSLog(@"MONDAY's DATE-----------%@", [timeStamp dateByAddingTimeInterval:-secondsSinceMondayMidnight]);
return [timeStamp dateByAddingTimeInterval:-secondsSinceMondayMidnight];
}