As written, 70 microseconds. When I set the calendar's time zone to GMT, the time drops to 43 microseconds. Since my app will only work with dates in GMT, this is a plus. Even so, 40 microseconds is far slower than the 7 - 8 microseconds offered by -[NSCalendarDate dayOfYear]. Unless someone has another offering, I plan to file a bug report on this issue. This calculation is part of an animation loop, so the performance hit is important.
Btw, my two offerings return an incorrect 367 for the date 2008-12-31 23:59:59 +0000; 2008 being a leap year, the correct return is 366. Your offering and NSCalendarDate get it right. int dayOfYearForDate4(NSDate *_date) { NSTimeZone *gmtTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; [calendar setTimeZone:gmtTimeZone]; int day = [calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:_date]; return day; } on 8/18/08 7:34 AM, Eliza Block at [EMAIL PROTECTED] wrote: > You could do this: > > int dayOfYearForDate(NSDate *_date) > { > NSCalendar *calendar = [[NSCalendar alloc] > initWithCalendarIndentifier:NSGregorianCalendar]]; > int day = [calendar ordinalityOfUnit:NSDayCalendarUnit > inUnit:NSYearCalendarUnit forDate:_date]; > return day; > } > > I've never benchmarked this, but it's certainly a lot less code. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]