<?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"
	>
<channel>
	<title>Comments on: Happy Fun Leopard Bug Time: NSCalendar</title>
	<atom:link href="http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/</link>
	<description>On Mac OS X programming</description>
	<pubDate>Tue, 02 Dec 2008 12:35:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: mr_noodle</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13054</link>
		<dc:creator>mr_noodle</dc:creator>
		<pubDate>Fri, 01 Feb 2008 16:09:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13054</guid>
		<description>Chris:
-maximumRangeOfUnit: seems to work. I seemed to have overlooked the NSWeekdayCalendarUnit since weekdays means the days Monday-Friday (at least in these parts) but in the APIs it represents a any day relative to a week. I'm not sure how big an assumption it is that all weeks are the same length for any particular calendar. It looks like the following would also work, and I assume should take into account any variances in week-length:

range = [[NSCalendar currentCalendar] rangeOfUnit:NSWeekdayCalendarUnit
                                               inUnit:NSWeekCalendarUnit
                                              forDate:date];

This will do what Tom was expecting. For a Gregorian calendar, it should always return {1, 7}. Still not useful for getting the starting day relative to the month. In such a case you can create an NSCalendarDate, get its -dayOfWeek and then create a new date by subtracting that number of days from the original date.

In any case, going to amend the article to tell people to read the comments.</description>
		<content:encoded><![CDATA[<p>Chris:<br />
-maximumRangeOfUnit: seems to work. I seemed to have overlooked the NSWeekdayCalendarUnit since weekdays means the days Monday-Friday (at least in these parts) but in the APIs it represents a any day relative to a week. I&#8217;m not sure how big an assumption it is that all weeks are the same length for any particular calendar. It looks like the following would also work, and I assume should take into account any variances in week-length:</p>
<p>range = [[NSCalendar currentCalendar] rangeOfUnit:NSWeekdayCalendarUnit<br />
                                               inUnit:NSWeekCalendarUnit<br />
                                              forDate:date];</p>
<p>This will do what Tom was expecting. For a Gregorian calendar, it should always return {1, 7}. Still not useful for getting the starting day relative to the month. In such a case you can create an NSCalendarDate, get its -dayOfWeek and then create a new date by subtracting that number of days from the original date.</p>
<p>In any case, going to amend the article to tell people to read the comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mr_noodle</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13028</link>
		<dc:creator>mr_noodle</dc:creator>
		<pubDate>Fri, 01 Feb 2008 06:10:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13028</guid>
		<description>Point(s) taken. I know of the Leopard-only method but, it's Leopard-only. Not a luxury we all have (at least not yet).

I think the range currently returned is just as inaccurate though. If you have (28, 29, 31, 1, 2, 3, 4), the range {1, 31} implies that 5, 6, 7..27 are in that range, which they aren't. It's the similar to the logic that {28, 7} implies numbers greater than 31.

In some ways, I think it might have been better if Apple treated this as an undefined computation and returned NSNotFound.</description>
		<content:encoded><![CDATA[<p>Point(s) taken. I know of the Leopard-only method but, it&#8217;s Leopard-only. Not a luxury we all have (at least not yet).</p>
<p>I think the range currently returned is just as inaccurate though. If you have (28, 29, 31, 1, 2, 3, 4), the range {1, 31} implies that 5, 6, 7..27 are in that range, which they aren&#8217;t. It&#8217;s the similar to the logic that {28, 7} implies numbers greater than 31.</p>
<p>In some ways, I think it might have been better if Apple treated this as an undefined computation and returned NSNotFound.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Suter</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13027</link>
		<dc:creator>Chris Suter</dc:creator>
		<pubDate>Fri, 01 Feb 2008 06:01:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13027</guid>
		<description>&#62; IÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢m still stuck hardcoding 7 days in a week.

What about using:

-[NSCalendar maximumRangeOfUnit:]

with kCFCalendarUnitWeekday.

That's 10.4.</description>
		<content:encoded><![CDATA[<p>&gt; IÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢m still stuck hardcoding 7 days in a week.</p>
<p>What about using:</p>
<p>-[NSCalendar maximumRangeOfUnit:]</p>
<p>with kCFCalendarUnitWeekday.</p>
<p>That&#8217;s 10.4.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Suter</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13025</link>
		<dc:creator>Chris Suter</dc:creator>
		<pubDate>Fri, 01 Feb 2008 05:51:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13025</guid>
		<description>&#62; Plus, answer this, how is the behavior you described even remotely useful?

The only use I can think is for user interface validation/limitation. For example, let's say you've specified a year and month, you could use this function to determine the range of values that day can take within that month. I can't think of a use where the larger unit is NSCalendarUnitWeek though. Maybe it's useful in non-Gregorian calendars.

If you want to work out the start date and length of a week, I'm sure you've probably spotted the Leopard only: 

-[NSCalendar rangeOfUnit:startDate:interval:forDate:]

method. There's also

-[NSCalendarDate years:months:days:hours:minutes:seconds:sinceDate:]

which might be useful for your purposes.

The example where you pass 34 for the day is clearly a special case and I certainly wouldn't rely on it, especially since the documentation says that valid values are 1 through 31.

&#62;And additionally, your logic doesnÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢t explain the 31 days in a year.
&#62;How is that supposed to be desired behavior?

Within a particular year, the day can take the value 1 to 31. It's not saying that there's 31 days in a year.

&#62; Look, at this point, there is no way you can convince me that youÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢re way
&#62; makes more sense or is in any way more useful.

I'm not trying to convince you that it makes more sense or is any way more useful. I'm just explaining to you the way it is, or trying to at least.

&#62; And if you canÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢t see the obvious logical expectation that everybody else has
&#62; (ask around by just showing them the method description and see what they
&#62; say) then thereÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢s little point in me trying to convince you.

Of course I can see the logical expectation that everyone else has. What you expected and want is clearly more useful which is presumably why Apple added a method for that purpose.</description>
		<content:encoded><![CDATA[<p>&gt; Plus, answer this, how is the behavior you described even remotely useful?</p>
<p>The only use I can think is for user interface validation/limitation. For example, let&#8217;s say you&#8217;ve specified a year and month, you could use this function to determine the range of values that day can take within that month. I can&#8217;t think of a use where the larger unit is NSCalendarUnitWeek though. Maybe it&#8217;s useful in non-Gregorian calendars.</p>
<p>If you want to work out the start date and length of a week, I&#8217;m sure you&#8217;ve probably spotted the Leopard only: </p>
<p>-[NSCalendar rangeOfUnit:startDate:interval:forDate:]</p>
<p>method. There&#8217;s also</p>
<p>-[NSCalendarDate years:months:days:hours:minutes:seconds:sinceDate:]</p>
<p>which might be useful for your purposes.</p>
<p>The example where you pass 34 for the day is clearly a special case and I certainly wouldn&#8217;t rely on it, especially since the documentation says that valid values are 1 through 31.</p>
<p>&gt;And additionally, your logic doesnÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢t explain the 31 days in a year.<br />
&gt;How is that supposed to be desired behavior?</p>
<p>Within a particular year, the day can take the value 1 to 31. It&#8217;s not saying that there&#8217;s 31 days in a year.</p>
<p>&gt; Look, at this point, there is no way you can convince me that youÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢re way<br />
&gt; makes more sense or is in any way more useful.</p>
<p>I&#8217;m not trying to convince you that it makes more sense or is any way more useful. I&#8217;m just explaining to you the way it is, or trying to at least.</p>
<p>&gt; And if you canÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢t see the obvious logical expectation that everybody else has<br />
&gt; (ask around by just showing them the method description and see what they<br />
&gt; say) then thereÃƒÂ¢Ã¢â€šÂ¬Ã¢â€žÂ¢s little point in me trying to convince you.</p>
<p>Of course I can see the logical expectation that everyone else has. What you expected and want is clearly more useful which is presumably why Apple added a method for that purpose.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mr_noodle</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13023</link>
		<dc:creator>mr_noodle</dc:creator>
		<pubDate>Fri, 01 Feb 2008 05:39:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13023</guid>
		<description>Chris: I do see where you are coming from and how it does fit the docs. I apologize if it took me a while to figure out what you were getting at but you have to admit the logic of it is a bit twisted. Nonetheless, my point still stands that NSCalendar is rendered pretty useless by this. If it is by design, then I feel it is flawed by design as it ends up calculating a number that is not useful.

I'm still stuck hardcoding 7 days in a week. Chances are slim that this will come back to haunt me but it defeats the purpose of abstracting out the calendar if you can't rely on it for information like this.</description>
		<content:encoded><![CDATA[<p>Chris: I do see where you are coming from and how it does fit the docs. I apologize if it took me a while to figure out what you were getting at but you have to admit the logic of it is a bit twisted. Nonetheless, my point still stands that NSCalendar is rendered pretty useless by this. If it is by design, then I feel it is flawed by design as it ends up calculating a number that is not useful.</p>
<p>I&#8217;m still stuck hardcoding 7 days in a week. Chances are slim that this will come back to haunt me but it defeats the purpose of abstracting out the calendar if you can&#8217;t rely on it for information like this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Harrington</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13021</link>
		<dc:creator>Tom Harrington</dc:creator>
		<pubDate>Fri, 01 Feb 2008 05:15:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13021</guid>
		<description>Unfortunately I think I'm seeing Chris Suter's point.  I say "unfortunately" because it seems that the results are completely useless, and it makes me question whether NSCalendar is worth bothering with.  I can follow the logic of why the results are as they are, what I can't do is think of any reason it's not stupid to design the API that way.  Chris, can you suggest a situation where the results you describe would be a useful thing to get?</description>
		<content:encoded><![CDATA[<p>Unfortunately I think I&#8217;m seeing Chris Suter&#8217;s point.  I say &#8220;unfortunately&#8221; because it seems that the results are completely useless, and it makes me question whether NSCalendar is worth bothering with.  I can follow the logic of why the results are as they are, what I can&#8217;t do is think of any reason it&#8217;s not stupid to design the API that way.  Chris, can you suggest a situation where the results you describe would be a useful thing to get?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mr_noodle</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13019</link>
		<dc:creator>mr_noodle</dc:creator>
		<pubDate>Fri, 01 Feb 2008 04:47:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13019</guid>
		<description>I'm sorry, but that logic is way to contrived. I've polled several devs and not one even intimated anything close to what you suggested, all expecting the same behavior I was. Plus, answer this, how is the behavior you described even remotely useful?

But, even using your logic, it doesn't hold up. Try this:
&lt;code&gt;
  date = [NSCalendarDate dateWithYear:2008 month:1 day:34 hour:0 minute:0 secon\
d:0 timeZone:nil];
  NSLog(@"Date : %@", date);
&lt;/code&gt;

34 is an acceptable value for day and NSCalendarDate is smart enough to know that extends into the next month. Plus, the range does not necessarily suggest that the numbers 32-34 are the actual "labels" for the days. The range says the 7 days starting from the 28th.

And additionally, your logic doesn't explain the 31 days in a year. How is that supposed to be desired behavior?

Look, at this point, there is no way you can convince me that you're way makes more sense or is in any way more useful. And if you can't see the obvious logical expectation that everybody else has (ask around by just showing them the method description and see what they say) then there's little point in me trying to convince you.</description>
		<content:encoded><![CDATA[<p>I&#8217;m sorry, but that logic is way to contrived. I&#8217;ve polled several devs and not one even intimated anything close to what you suggested, all expecting the same behavior I was. Plus, answer this, how is the behavior you described even remotely useful?</p>
<p>But, even using your logic, it doesn&#8217;t hold up. Try this:<br />
<code><br />
  date = [NSCalendarDate dateWithYear:2008 month:1 day:34 hour:0 minute:0 secon\<br />
d:0 timeZone:nil];<br />
  NSLog(@&#8221;Date : %@&#8221;, date);<br />
</code></p>
<p>34 is an acceptable value for day and NSCalendarDate is smart enough to know that extends into the next month. Plus, the range does not necessarily suggest that the numbers 32-34 are the actual &#8220;labels&#8221; for the days. The range says the 7 days starting from the 28th.</p>
<p>And additionally, your logic doesn&#8217;t explain the 31 days in a year. How is that supposed to be desired behavior?</p>
<p>Look, at this point, there is no way you can convince me that you&#8217;re way makes more sense or is in any way more useful. And if you can&#8217;t see the obvious logical expectation that everybody else has (ask around by just showing them the method description and see what they say) then there&#8217;s little point in me trying to convince you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Suter</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13017</link>
		<dc:creator>Chris Suter</dc:creator>
		<pubDate>Fri, 01 Feb 2008 04:26:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13017</guid>
		<description>Firstly I should say that I'm in Sydney, so it's February for me now. For the end of February you get { 1, 28 }. For January you get { 1, 31 }.

What the function does is ask this (in the case where you pass NSDayCalendarUnit and NSWeekCalendarUnit):

"What is the smallest range that will cover the possible values of day for the week on the date I specify?"

What the function does *not* do is tell you "what is the first day of that week and how long is it?".

So, take 31 Jan 2008 for example. The week starts on 27 Jan, so the day can take the values, 27, 28, 29, 30, 31, 1, 2. The smallest range that covers those values is clearly {1, 31} which is what you get on Leopard.

I realise that you want the function to work differently, but I'm afraid it doesn't and it's perfectly logical the way it works. There is a bug on Tiger because by returning { 28, 7 } it's suggesting that the day will always fall into that range i.e. 28-34.

I'll bet your Mac Pro that Apple tell you it works as expected. :-)</description>
		<content:encoded><![CDATA[<p>Firstly I should say that I&#8217;m in Sydney, so it&#8217;s February for me now. For the end of February you get { 1, 28 }. For January you get { 1, 31 }.</p>
<p>What the function does is ask this (in the case where you pass NSDayCalendarUnit and NSWeekCalendarUnit):</p>
<p>&#8220;What is the smallest range that will cover the possible values of day for the week on the date I specify?&#8221;</p>
<p>What the function does *not* do is tell you &#8220;what is the first day of that week and how long is it?&#8221;.</p>
<p>So, take 31 Jan 2008 for example. The week starts on 27 Jan, so the day can take the values, 27, 28, 29, 30, 31, 1, 2. The smallest range that covers those values is clearly {1, 31} which is what you get on Leopard.</p>
<p>I realise that you want the function to work differently, but I&#8217;m afraid it doesn&#8217;t and it&#8217;s perfectly logical the way it works. There is a bug on Tiger because by returning { 28, 7 } it&#8217;s suggesting that the day will always fall into that range i.e. 28-34.</p>
<p>I&#8217;ll bet your Mac Pro that Apple tell you it works as expected. <img src='http://www.noodlesoft.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mr_noodle</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13015</link>
		<dc:creator>mr_noodle</dc:creator>
		<pubDate>Fri, 01 Feb 2008 03:47:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13015</guid>
		<description>I'm sorry but I'm not following your logic here. Why can't the day occur on 28? It is calculating the calendar week (i.e. the week aligned with the calendar.) When I look at the last week in January, 2007, I see that the beginning of the week according to the Gregorian calendar (and assuming Sunday is the first day) falls on the 28th. If you check this under Tiger, you get {28, 7}. That means the calendar date starts on the 28th and lasts 7 days.

Leopard reports {1, 31}. Now, even if you take that 1 to be the first of the next month, 31 still doesn't make sense under your logic because the next month is February and it only has 28 days. But all that is moot as the week does not start on the first for either Jan or Feb of 2007. In addition, back to the original bug I cited, there is no good reason why the week, which was accurately reported as being 7 days long in the other weeks (and in every week on Tiger) is reported as being 31 days. Of what possible use is that to the developer? It seems like you are trying to argue the "logic" of the bug. I just don't see how you can argue this as being logical. It may be an explanation of why it's happening, but that doesn't mean it's correct.</description>
		<content:encoded><![CDATA[<p>I&#8217;m sorry but I&#8217;m not following your logic here. Why can&#8217;t the day occur on 28? It is calculating the calendar week (i.e. the week aligned with the calendar.) When I look at the last week in January, 2007, I see that the beginning of the week according to the Gregorian calendar (and assuming Sunday is the first day) falls on the 28th. If you check this under Tiger, you get {28, 7}. That means the calendar date starts on the 28th and lasts 7 days.</p>
<p>Leopard reports {1, 31}. Now, even if you take that 1 to be the first of the next month, 31 still doesn&#8217;t make sense under your logic because the next month is February and it only has 28 days. But all that is moot as the week does not start on the first for either Jan or Feb of 2007. In addition, back to the original bug I cited, there is no good reason why the week, which was accurately reported as being 7 days long in the other weeks (and in every week on Tiger) is reported as being 31 days. Of what possible use is that to the developer? It seems like you are trying to argue the &#8220;logic&#8221; of the bug. I just don&#8217;t see how you can argue this as being logical. It may be an explanation of why it&#8217;s happening, but that doesn&#8217;t mean it&#8217;s correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Suter</title>
		<link>http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13013</link>
		<dc:creator>Chris Suter</dc:creator>
		<pubDate>Fri, 01 Feb 2008 02:39:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2008/01/25/happy-fun-leopard-bug-time-nscalendar/#comment-13013</guid>
		<description>@mr_noodle: I think you'll find is that it's a bug in Tiger. On Tiger, you'll find when it gets at the end of the month, it will report a range back of, say, { 28, 7 }, which suggests that the day can take the values, 28, 29, 30, 31, 32, 33, 34, which is clearly wrong.

@tom: The code above only produces a result of 1-7 if the first day happens to be the first day of the month. The reason the length differs is for the reason I outlined earlier: because the day wraps when a week straddles a month boundary. If you look at the week at the end of this month, you'll find you get {1, 29} back.</description>
		<content:encoded><![CDATA[<p>@mr_noodle: I think you&#8217;ll find is that it&#8217;s a bug in Tiger. On Tiger, you&#8217;ll find when it gets at the end of the month, it will report a range back of, say, { 28, 7 }, which suggests that the day can take the values, 28, 29, 30, 31, 32, 33, 34, which is clearly wrong.</p>
<p>@tom: The code above only produces a result of 1-7 if the first day happens to be the first day of the month. The reason the length differs is for the reason I outlined earlier: because the day wraps when a week straddles a month boundary. If you look at the week at the end of this month, you&#8217;ll find you get {1, 29} back.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
