合并同一时间的课程,同一时间可能有多个课程,比如13:30-14:00 13:40-14:40
//递归实现
-(void)mergeClassSchedule:(NSMutableArray*)ary
retArray:(NSMutableArray*)retAry
beginDate:(NSDate*)beginDate
endDate:(NSDate*)endDate
{
NSMutableArray *groupAry=[NSMutableArray new];
if ([ary count]>0) {
[retAry addObject:groupAry];
}
while ([ary count]>0)
{
XSClassScheduleModel *classSchedulemodel=[ary objectAtIndex:0];
if (beginDate==nil)
{
beginDate=[XSUtil str2DateEx:classSchedulemodel.BeginDateTimeUTC];
endDate=[XSUtil str2DateEx:classSchedulemodel.EndDateTimeUTC];
[groupAry addObject:classSchedulemodel];
[ary removeObjectAtIndex:0];
}
else
{
NSDate *beginDate2=[XSUtil str2DateEx:classSchedulemodel.BeginDateTimeUTC];
NSDate *endDate2=[XSUtil str2DateEx:classSchedulemodel.EndDateTimeUTC];
if (([beginDate compare:beginDate2]==NSOrderedAscending || [beginDate compare:beginDate2]==NSOrderedSame)
&& [endDate compare:beginDate2]==NSOrderedDescending)
{
[groupAry addObject:classSchedulemodel];
[ary removeObjectAtIndex:0];
endDate=[endDate compare:endDate2]==NSOrderedAscending?endDate2:endDate;
}
else
{
beginDate=nil;
[self mergeClassSchedule:ary retArray:retAry beginDate:beginDate endDate:endDate];
}
}
}
}