• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSCalendar/NSDate - generating all months/days in a year
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: NSCalendar/NSDate - generating all months/days in a year
  • From: Ken Tozier <email@hidden>
  • Date: Mon, 22 Dec 2008 14:20:14 -0500

Following everyone's advice, I came up with the following, more compact, solution

- (NSDictionary *) dates:(int) inYear
{
	NSMutableDictionary		*result			= [NSMutableDictionary dictionary];
	NSMutableArray			*days			= [NSMutableArray array];

	int						startMonth		= 1;

	NSTimeZone				*tz				= [NSTimeZone localTimeZone];

NSCalendarDate *date = [NSCalendarDate dateWithYear: inYear
month: startMonth
day: 1
hour: 0
minute: 0
second: 0
timeZone: tz];

[result setObject: days forKey: [date descriptionWithCalendarFormat: @"%B"]];

while ([date yearOfCommonEra] == inYear)
{
date = [date dateByAddingYears: 0
months: 0
days: 1
hours: 0
minutes: 0
seconds: 0];

if ([date monthOfYear] > startMonth)
{
days = [NSMutableArray array];
[result setObject: days forKey: [date descriptionWithCalendarFormat: @"%B"]];
startMonth++;
}

[days addObject: [date descriptionWithCalendarFormat: @"%a %m/%d/%y %I:%M %p"]];
}

return result;
}



On Dec 22, 2008, at 12:38 PM, mmalc Crawford wrote:


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.

mmalc
(With thanks for sage advice to Chris Kane.)

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSCalendar/NSDate - generating all months/days in a year
      • From: mmalc Crawford <email@hidden>
References: 
 >NSCalendar/NSDate - generating all months/days in a year (From: Keith Blount <email@hidden>)
 >Re: NSCalendar/NSDate - generating all months/days in a year (From: Nathan Vander Wilt <email@hidden>)
 >Re: NSCalendar/NSDate - generating all months/days in a year (From: mmalc Crawford <email@hidden>)

  • Prev by Date: NSStream APIs
  • Next by Date: Re: Color space for cmyk eps images converting to rgb
  • Previous by thread: Re: NSCalendar/NSDate - generating all months/days in a year
  • Next by thread: Re: NSCalendar/NSDate - generating all months/days in a year
  • Index(es):
    • Date
    • Thread