NSQuarterCalendarUnit does not seem to be actually implemented

Originator:lroathe
Number:rdar://16341277 Date Originated:Mar 17, 2014
Status:Open Resolved:
Product:NSFoundation SDK Product Version:iOS 4.0+, OSX 10.6+
Classification:Serious Bug Reproducible:Always
 
Summary:
The NSCalendarComponents describes components parameter to decide how to work with a date in different units, for decomposing, adjusting, etc. NSQuarterCalendarUnit is one of those parameters, but it is ignored in any test I perform.

Steps to Reproduce:
Run this simple app:

#import <Foundation/Foundation.h>
 
int main (int argc, const char * argv[])
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  NSLog( @"Current Quarter: %d", [[[NSCalendar currentCalendar] components: NSQuarterCalendarUnit fromDate: [NSDate date]] quarter] );

  [pool drain];
  return 0;
}

Expected Results:
When retrieving the current quarter, expect a value from 1 to 4, depending on the current date. When adjusting a date by quarter, expect the date to be changed by 3 months * the # of quarters specified.


Actual Results:
Retrieving the current quarter always returns 0. Attempting to adjust a date using the quarter component has no effect.

Regression:
Bug occurs on Mac OS X as well as iOS, and is 100% reproducible. It appears as if NSQuarterCalendarUnit was defined, but never implemented.

Notes:
Work around is to write custom methods to calculate quarter information using months (at least for Roman calendar users).

Apple Radar includes a sample project with more examples, specifically this category method on NSDate which should adjust the date by quarters but has no effect (using the day, week, month or year component does work):

- (NSDate *) dateByAddingQuarters: (NSInteger)numQuarters
{
// OS BUG? Adding quarters does _not_ effect the date!

	NSCalendar *calendar = [NSCalendar currentCalendar];

	NSDateComponents *offset = [[NSDateComponents alloc] init];
	[offset setQuarter: numQuarters];

	NSDate *date = [calendar dateByAddingComponents: offset toDate: self options: 0];

	return date;
}

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!