<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Cocoa Tutorial: Yesterday, Today, and Tomorrow with NSDate</title>
	<atom:link href="http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/</link>
	<description>fill the void</description>
	<lastBuildDate>Mon, 30 Jan 2012 09:42:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: bdunagan &#8211; Cocoa Tip: Extend NSDate</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-11703</link>
		<dc:creator>bdunagan &#8211; Cocoa Tip: Extend NSDate</dc:creator>
		<pubDate>Mon, 13 Jun 2011 14:06:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-11703</guid>
		<description>[...] are a seemless way to extend existing Cocoa classes like NSDate. In my post on relative dates, I see if two timestamps land on the same day, by zeroing out the hour/minute/second components. [...]</description>
		<content:encoded><![CDATA[<p>[...] are a seemless way to extend existing Cocoa classes like NSDate. In my post on relative dates, I see if two timestamps land on the same day, by zeroing out the hour/minute/second components. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bdunagan</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-10806</link>
		<dc:creator>bdunagan</dc:creator>
		<pubDate>Sun, 01 May 2011 21:51:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-10806</guid>
		<description>@skot Much more elegant. :) Thanks for posting!</description>
		<content:encoded><![CDATA[<p>@skot Much more elegant. <img src='http://www.bdunagan.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Thanks for posting!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skot</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-10506</link>
		<dc:creator>skot</dc:creator>
		<pubDate>Tue, 19 Apr 2011 15:50:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-10506</guid>
		<description>This avoids looping through several reference dates, and automatically localizes &quot;Tomorrow&quot; and &quot;Yesterday&quot;:

@implementation NSDate (whenString)

- (NSDate *)dateWithZeroTime
{
  NSCalendar *calendar = [NSCalendar currentCalendar];
  unsigned unitFlags = NSYearCalendarUnit &#124; NSMonthCalendarUnit &#124;  NSDayCalendarUnit &#124; NSWeekdayCalendarUnit;
  NSDateComponents *comps = [calendar components:unitFlags fromDate:self];
  [comps setHour:0];
  [comps setMinute:0];
  [comps setSecond:0];
  return [calendar dateFromComponents:comps];
}

- (NSString *)whenString 
{
  NSDate *selfZero = [self dateWithZeroTime];
  NSDate *todayZero = [[NSDate date] dateWithZeroTime];
  NSTimeInterval interval = [todayZero timeIntervalSinceDate:selfZero];
  int dayDiff = interval/(60*60*24);
  
  // Initialize the formatter.
  NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
  
  if (dayDiff == 0) { // today: show time only
    [formatter setDateStyle:NSDateFormatterNoStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
  } else if (dayDiff == 1 &#124;&#124; dayDiff == -1) {
    //return NSLocalizedString((dayDiff == 1 ? @&quot;Yesterday&quot; : @&quot;Tomorrow&quot;), nil);
    [formatter setDoesRelativeDateFormatting:YES];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
  } else if (dayDiff &lt;= 7) { // &lt; 1 week ago: show weekday
    [formatter setDateFormat:@&quot;EEEE&quot;];
  } else { // show date
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];      
  }
  
  return [formatter stringFromDate:self];
}

@end</description>
		<content:encoded><![CDATA[<p>This avoids looping through several reference dates, and automatically localizes &#8220;Tomorrow&#8221; and &#8220;Yesterday&#8221;:</p>
<p>@implementation NSDate (whenString)</p>
<p>- (NSDate *)dateWithZeroTime<br />
{<br />
  NSCalendar *calendar = [NSCalendar currentCalendar];<br />
  unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSWeekdayCalendarUnit;<br />
  NSDateComponents *comps = [calendar components:unitFlags fromDate:self];<br />
  [comps setHour:0];<br />
  [comps setMinute:0];<br />
  [comps setSecond:0];<br />
  return [calendar dateFromComponents:comps];<br />
}</p>
<p>- (NSString *)whenString<br />
{<br />
  NSDate *selfZero = [self dateWithZeroTime];<br />
  NSDate *todayZero = [[NSDate date] dateWithZeroTime];<br />
  NSTimeInterval interval = [todayZero timeIntervalSinceDate:selfZero];<br />
  int dayDiff = interval/(60*60*24);</p>
<p>  // Initialize the formatter.<br />
  NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];</p>
<p>  if (dayDiff == 0) { // today: show time only<br />
    [formatter setDateStyle:NSDateFormatterNoStyle];<br />
    [formatter setTimeStyle:NSDateFormatterShortStyle];<br />
  } else if (dayDiff == 1 || dayDiff == -1) {<br />
    //return NSLocalizedString((dayDiff == 1 ? @&#8221;Yesterday&#8221; : @&#8221;Tomorrow&#8221;), nil);<br />
    [formatter setDoesRelativeDateFormatting:YES];<br />
    [formatter setDateStyle:NSDateFormatterMediumStyle];<br />
    [formatter setTimeStyle:NSDateFormatterNoStyle];<br />
  } else if (dayDiff <= 7) { // < 1 week ago: show weekday<br />
    [formatter setDateFormat:@"EEEE"];<br />
  } else { // show date<br />
    [formatter setDateStyle:NSDateFormatterShortStyle];<br />
    [formatter setTimeStyle:NSDateFormatterNoStyle];<br />
  }</p>
<p>  return [formatter stringFromDate:self];<br />
}</p>
<p>@end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bdunagan</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-10349</link>
		<dc:creator>bdunagan</dc:creator>
		<pubDate>Wed, 13 Apr 2011 09:52:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-10349</guid>
		<description>@a101 Glad it helped!</description>
		<content:encoded><![CDATA[<p>@a101 Glad it helped!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: a101</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-10208</link>
		<dc:creator>a101</dc:creator>
		<pubDate>Thu, 07 Apr 2011 08:02:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-10208</guid>
		<description>Great piece of code, did exactly what I needed. Thanks!</description>
		<content:encoded><![CDATA[<p>Great piece of code, did exactly what I needed. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bdunagan</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-8699</link>
		<dc:creator>bdunagan</dc:creator>
		<pubDate>Sun, 30 Jan 2011 21:52:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-8699</guid>
		<description>@bob I&#039;m pretty sure they&#039;re equivalent, but yours is more elegant. I use your way these days.</description>
		<content:encoded><![CDATA[<p>@bob I&#8217;m pretty sure they&#8217;re equivalent, but yours is more elegant. I use your way these days.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bob</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-8407</link>
		<dc:creator>bob</dc:creator>
		<pubDate>Wed, 12 Jan 2011 04:40:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-8407</guid>
		<description>[suppliedDate compare:referenceDate] == NSOrderedSame
should be written as [suppliedDate
isEqualToDate:referenceDate]</description>
		<content:encoded><![CDATA[<p>[suppliedDate compare:referenceDate] == NSOrderedSame<br />
should be written as [suppliedDate<br />
isEqualToDate:referenceDate]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-8248</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Sun, 02 Jan 2011 17:15:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-8248</guid>
		<description>Great help - thanks. You saved me a few hours of
work.</description>
		<content:encoded><![CDATA[<p>Great help &#8211; thanks. You saved me a few hours of<br />
work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nonamelive</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-3845</link>
		<dc:creator>nonamelive</dc:creator>
		<pubDate>Fri, 05 Feb 2010 18:22:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-3845</guid>
		<description>Thank you! This is so useful. I have added it to my NSDate category!</description>
		<content:encoded><![CDATA[<p>Thank you! This is so useful. I have added it to my NSDate category!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bdunagan</title>
		<link>http://www.bdunagan.com/2008/09/13/cocoa-tutorial-yesterday-today-and-tomorrow-with-nsdate/comment-page-1/#comment-2658</link>
		<dc:creator>bdunagan</dc:creator>
		<pubDate>Sat, 10 Oct 2009 03:39:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.bdunagan.com/blog/?p=43#comment-2658</guid>
		<description>@Asok Yep, the API handles it. You can start with April 1, execute [comps setDay:-3], and get March 28. Even handles leap years.</description>
		<content:encoded><![CDATA[<p>@Asok Yep, the API handles it. You can start with April 1, execute [comps setDay:-3], and get March 28. Even handles leap years.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

