Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-23 Thread Ken Tozier
On Dec 22, 2008, at 2:30 PM, mmalc Crawford wrote: No! This is precisely the direction in which not to go: Important: Use of NSCalendarDate strongly discouraged. It is not deprecated yet, however it may be in the next major OS release after Mac OS X v10.5. For calendrical calculations, you

NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Keith Blount
Hi, Apologies in advance for what I think must be a basic question. It's something I've never had cause to do before, assumed must be fairly straightforward, and then seemed a lot more complicated than it should be which leads me to think that I am using the wrong search terms... All I want

Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Ken Tozier
Fun problem Basically it's safe to assume 24 hours in a day for date calculation (check details at Wikipedia) so you just have to get January 1 of the target year, January 1 of the subsequent year and increment until the time interval between them equals zero. This makes no assumptions

Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread WT
Hi Keith, Ken's suggestion is much more elegant than mine, but here's mine anyway. I wrote a little Foundation Tool to test it and it works fine. Note that the year (2009), and the fact that 2009 is not a leap year, are hard-coded. You'll have to change that, of course. Hope this helps.

Re: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread Keith Blount
Hi, Many thanks to both of you for your very helpful replies - much appreciated! I've gone with Ken's solution, which works perfectly for what I need. For the sake of the archives, I've attached the method I created based on Ken's code, which just creates a hierarchical dictionary of objects

Re: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread mmalc Crawford
On Dec 22, 2008, at 8:34 AM, Keith Blount wrote: Hi, Many thanks to both of you for your very helpful replies - much appreciated! I've gone with Ken's solution, which works perfectly for what I need. For the sake of the archives, I've attached the method I created based on Ken's code,

Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Nathan Vander Wilt
On Dec 22, 2008, at 4:53 AM, Keith Blount wrote: Hi, Apologies in advance for what I think must be a basic question. It's something I've never had cause to do before, assumed must be fairly straightforward, and then seemed a lot more complicated than it should be which leads me to think

Re: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread mmalc Crawford
On Dec 22, 2008, at 8:47 AM, mmalc Crawford wrote: There shouldn't be any need, though, to add a month for each iteration, just start a new month with a date components object with a new month number. This could be made a little more efficient (and if you're not using garbage

Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread mmalc Crawford
On Dec 22, 2008, at 9:22 AM, Nathan Vander Wilt wrote: [Good advice, except:] NSCalendar can handle overflow, so you can have an NSDateComponent that says something like Year:2008 Month:1 Days:364 and you will get the right date from components. You should not rely on this behaviour.

Re: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread Keith Blount
(less nasty :) ) methods. Thanks again! Keith --- On Mon, 12/22/08, mmalc Crawford mmalc_li...@me.com wrote: From: mmalc Crawford mmalc_li...@me.com Subject: Re: NSCalendar/NSDate - generating all months/days in a year [SOLVED] To: Cocoa-Dev List cocoa-dev@lists.apple.com Cc: Keith Blount

Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Ken Tozier
Following everyone's advice, I came up with the following, more compact, solution - (NSDictionary *) dates:(int) inYear { NSMutableDictionary *result = [NSMutableDictionary dictionary]; NSMutableArray *days =

Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread mmalc Crawford
On Dec 22, 2008, at 11:20 AM, Ken Tozier wrote: NSCalendarDate *date = [NSCalendarDate dateWithYear: ... No! This is precisely the direction in which not to go: Important: Use of NSCalendarDate strongly discouraged. It is not deprecated yet, however it may be in the next major OS release

Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Kenneth Bruno
On Mon, 22 Dec 2008 12:01:11 -0800, mmalc Crawford mmalc_li...@me.com said: On Dec 22, 2008, at 11:48 AM, Kenneth Bruno wrote: Basically, NSCalendarDate gets you pretty much what you need: As in a recent message: Important: Use of NSCalendarDate strongly discouraged. It is not