NSDateComponents week is deprecated since iOS8. Apple suggest using weekOfMonth or weekOfYear instead, depending on the context, but they are working in a different way. For example:
components1 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date7DaysAgo]
toDate:[NSDate date]
options:0];
components1 returns month = 0, week = 1, day = 0, weekOfMonth and weekOfYear are both equal to 2147483647 (integer maximum value).
components2 = [calendar components:NSMonthCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit
fromDate:[self date30DaysAgo]
toDate:[NSDate date]
options:0];
components2 returns month = 1 (I know it depends, but its just an example), week = 0, day = 0, weekOfMonth and weekOfYear are both equal to 2147483647 (integer maximum value).
Week returns number of weeks during some period (if it was a week or it multiple) and it is completely different than number of a week in month or year. Why would Apple suggest using this instead?
Use NSWeekOfMonthCalendarUnit or NSWeekOfYearCalendarUnit instead of NSWeekCalendarUnit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With