I did find myself still using NSCalendarDate because I wanted its - dayOfYear method. I wasn't worried about localization because my application is used by exactly one user in the middle of a cornfield in SW Michigan. But if someone knows, what is the way to get this with NSCalendar? I found I could use NSCalendar to get all the other useful date pieces (such as -dayOfMonth, -dayOfWeek) I needed except this one. Hmm, I just thought of: computing the first day of the year and get the interval between the first day and the target day? I was blinded to that idea I think by the ease of -dayOfYear!

Use ordinalityOfUnit:inUnit:forDate: which is intended to replace the plethora of methods such as -dayOfYear. You should be able to pass "day" and "year" as the units.

Deborah Goldsmith
Apple Inc.
[EMAIL PROTECTED]

On Feb 26, 2008, at 5:45 AM, Paul Bruneau wrote:

I am sympathetic to using NSCalendar. At his Boot Camp, Aaron told me that NSCalendarDate was falling out of favor because it's not a good player regarding calendars other than Gregorian. I understand this.

However, the documentation really doesn't provide any direction as to this for a new developer. You might want to file a bug to make the documentation push us new developers in the good direction.

Nowhere in the NSCalendarDate docs does it say "don't use this" or even "try not to use this".

In the very first paragraph of the "Dates and Times Programming Topics for Cocoa" guide, it says:

"A Gregorian date object, a special type of date object, is useful for representing dates users do see. It adds methods for converting dates to strings, converting strings to dates, and retrieving elements from dates (such as hours, minutes, and the day of the week). This is implemented by NSCalendarDate in Objective-C and by com.apple.cocoa.foundation.NSGregorianDate in Java."

( file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/DatesAndTimes/index.html #//apple_ref/doc/uid/10000039i )

Not exactly a warning against its use.

I did find myself still using NSCalendarDate because I wanted its - dayOfYear method. I wasn't worried about localization because my application is used by exactly one user in the middle of a cornfield in SW Michigan. But if someone knows, what is the way to get this with NSCalendar? I found I could use NSCalendar to get all the other useful date pieces (such as -dayOfMonth, -dayOfWeek) I needed except this one. Hmm, I just thought of: computing the first day of the year and get the interval between the first day and the target day? I was blinded to that idea I think by the ease of -dayOfYear!

Maybe in addition to battling for localization with all of us, you have to battle with the internal folks too, I don't know. I wish you the best in your battles :)

On Feb 25, 2008, at 6:49 PM, Deborah Goldsmith wrote:

Please don't use NSCalendarDate, as it only supports the Gregorian calendar. Please use NSCalendar instead, unless you still need to run on 10.3.x.

Deborah Goldsmith
Apple Inc.
[EMAIL PROTECTED]

On Feb 25, 2008, at 11:39 AM, Nir Soffer wrote:


On Feb 25, 2008, at 21:27, Randall Meadows wrote:

Given a specific NSDate, I need to be able to find, say, the Sunday before that date, or the Saturday after that date. I was hoping to be able to use +dateWithNaturalLanguage with something like "Sunday before [myDate description]", but that just returns myDate.

I know I can brute-force it, by figuring out the myDate's day, then walking backward and/or forward, but is there an easier way? One more tried and true, less error-prone, that's calendar- savvy (not that I'm going to need to go as far back as Oct 1582...)?

Check NSCalendarDate -dayOfWeek and - dateByAddingYears:months:days:hours:minutes:seconds:

Best Regards,

Nir Soffer
_______________________________________________

Cocoa-dev mailing list ([email protected])

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/goldsmit%40apple.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list ([email protected])

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]

Reply via email to