Reputation: 891
I was creating a DateRange like this one in my App:
NSDateComponents *myDateComponentsStart = [[NSDateComponents alloc] init];
[myDateComponentsStart setWeek:-2];
NSDateComponents *myDateComponentsEnd = [[NSDateComponents alloc] init];
[myDateComponentsEnd setWeek:+2];
DateRange *myDateRage = [[DateRange dateRangeForToday] dateRangeByAddingStartDateComponents:myDateComponentsStart endDateComponents:myDateComponentsEnd];
It means a range between 2 weeks in the past and 2 weeks in the future.
But it seems setWeek is deprecated yet for iOS 8. It propose changing it by setWeekOfMonth or setWeekOfYear.
Since I don't care any change of month or year. What should I use now? I just want a period of 4 week with today in the middle, no worries about months or years.
Upvotes: 0
Views: 1139
Reputation: 1618
From my personal experience 'weekOfMonth' seems to give the same results that 'week' used to be.
weekOfYear seems to never work as I want it to.
Upvotes: 1
Reputation: 31782
You almost certainly want weekOfYear
. Although weekOfYear
and weekOfMonth
seem to produce the same result when you also specify NSCalendarWrapComponents
, weekOfYear
is semantically closer to your intent.
Upvotes: 2