Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between NSCalendarUnitWeekOfYear & NSCalendarUnitWeekOfMonth

I want to make a UILocalNotification repeat every week, before iOS7 I would use localNotification.repeatInterval = NSWeekCalendarUnit - except NSWeekCalendarUnit has been deprecated.

The docs say:

"Use NSCalendarUnitWeekOfMonth or NSCalendarUnitWeekOfYear, depending on which you mean"

But I don't know what the difference is, so I don't know which one I mean.

like image 801
daihovey Avatar asked Mar 12 '14 02:03

daihovey


2 Answers

As for the UILocalNotification

NSCalendarUnitWeekOfYear should be used as a unit for repeatInterval.

When I set repeatInterval = NSCalendarUnitWeekOfMonth for the notification scheduled 10 seconds from now, the notification doesn't fire, and the description of the instance of UILocalNotification prints .. next fire date = (null) ...

If I use NSCalendarUnitWeekOfYear then notification appears and I see correct next fire date from code in the notification's description.

like image 200
zubko Avatar answered Oct 20 '22 00:10

zubko


These don't appear to be documented but most likely NSCalendarUnitWeekOfYear will be a value from 1-53 (or maybe 0-52) representing the week number within the calendar year while NSCalendarUnitWeekOfMonth will be 1-5 (or maybe 0-4) representing the week within the month.

This all assumes Gregorian calendar. I can't speak to other calendar types.

It seems that NSCalendarUnitWeekOfMonth is equal to kCFCalendarUnitWeekOfMonth which is defined as "Specifies the original week of a month calendar unit." and NSCalendarUnitWeekOfYear is equal to kCFCalendarUnitWeekOfYear which is defined as "Specifies the original week of the year calendar unit.".

like image 35
rmaddy Avatar answered Oct 20 '22 00:10

rmaddy