NSCalendarDate and NSDate hash values differ for equal objects
Originator: | aeriksson | ||
Number: | rdar://6737598 | Date Originated: | 2009-03-30 |
Status: | Open | Resolved: | |
Product: | Mac OS X | Product Version: | 10.5.6 |
Classification: | Serious Bug | Reproducible: | Always |
Summary: The hash values for an NSCalendar date and an equal (according to [isEqual:] NSDate Steps to Reproduce: NSDate* date = [NSDate date]; NSDate* anotherDate = [NSDate dateWithTimeIntervalSinceReferenceDate: [date timeIntervalSinceReferenceDate]]; NSCalendarDate* calendarDate; calendarDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate: [date timeIntervalSinceReferenceDate]]; STAssertTrue([date isEqual:anotherDate], @"isEqual between NSDate and NSDate"); // OK STAssertEquals([date hash], [anotherDate hash], @"equal hash value for NSDate and NSDate"); // OK STAssertTrue([date isEqual:calendarDate], @"isEqual between NSDate and NSCalendarDate"); // OK STAssertEquals([date hash], [calendarDate hash], @"equal hash value for NSDate and NSCalendarDate"); // FAILS Expected Results: From the NSObject documentation of hash: "If two objects are equal (as determined by the isEqual: method), they must have the same hash value. This last point is particularly important if you define hash in a subclass and intend to put instances of that subclass into a collection." Actual Results: hash value differs for objects that are equal as determined by isEqual: Regression: Notes: This is extra serious because the Calendar Store framework sometimes returns NSCalendarDates and sometimes NSDates (when making an event occurrence detached).
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!