Cannot get number of weeks in month with -[NSCalendar rangeOfUnit:inUnit:forDate:] with NSCalendarUnitWeekOfMonth unit

Originator:pitiphong.ph
Number:rdar://15826991 Date Originated:16-Jan-2014 02:34 AM
Status:Open Resolved:
Product:iOS SDK Product Version:7.0.0
Classification:Other Bug Reproducible:Always
 
Summary:
Cannot get number of weeks in month with -[NSCalendar rangeOfUnit:inUnit:forDate:] with NSCalendarUnitWeekOfMonth unit

Steps to Reproduce:
1. Trying to get number of week in this month with
- [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitWeekOfMonth inUnit:NSCalendarUnitMonth forDate:[NSDate date]] API
PS. [NSDate date] is Jan 16 2014

Expected Results:
Return (NSRange) { 1, 5 }

Actual Results:
Return (NSRange) { NSNotFound, NSNotfound}

Regression:
If I use deprecated NSWeekCalendar enum, it will return the expected results.

Notes:
If I try to the the number of week in next month, the NSWeekCalendar will return { 5, 5 } which is the expected results too.
The NSWeekCalendar enum is deprecated and the documentation said we should used NSCalendarUnitWeekOfMonth or NSCalendarUnitWeekOfYear which don't work for this case.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!