<?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: Days between dates &#038; our perception of time</title>
	<atom:link href="http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/</link>
	<description>...so google can organize my head.</description>
	<pubDate>Tue, 06 Jan 2009 06:29:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: MMaI</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-30</link>
		<dc:creator>MMaI</dc:creator>
		<pubDate>Sun, 10 Jul 2005 16:51:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-30</guid>
		<description>I think the whole premise of this is wrong.  First you say "days between" and and then you say you want tomorrow to be considered one day away.  Those are two different things, because there are zero days *between* today and tomorrow.  I think ssp made the point best when they noted that a "relative" day starts when you get up, and that varies from person to person.  So it's really more of a time zone or perhaps localization issue.</description>
		<content:encoded><![CDATA[<p>I think the whole premise of this is wrong.  First you say &#8220;days between&#8221; and and then you say you want tomorrow to be considered one day away.  Those are two different things, because there are zero days *between* today and tomorrow.  I think ssp made the point best when they noted that a &#8220;relative&#8221; day starts when you get up, and that varies from person to person.  So it&#8217;s really more of a time zone or perhaps localization issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Lamb</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-28</link>
		<dc:creator>Alexander Lamb</dc:creator>
		<pubDate>Sun, 10 Jul 2005 06:53:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-28</guid>
		<description>That is something I really wanted for a long time: a NSCalendar class (I remember suggesting this in Redwood city in 1996:-)
Calculating days between dates is important, but what about calculating working houres between dates! This becomes especially important in project management software. You need to first merge two or three NSCalendar objects (the one for the company with the regular working hours, the one for the person for whom we are tracking the tasks which may add some vacations or different working hours and maybe even a project calendar).

Then, we need to be able to ask: "At what date and time shall we be if we add X working hours to a given date and time considering calendar A and B"...

Of course, I had that kind of class in a pet project of mine. But if Apple could bring some basic NSCalendar it would be a great help (it would have to be core data compatible since we would want to store custom calendars).

Alexander Lamb</description>
		<content:encoded><![CDATA[<p>That is something I really wanted for a long time: a NSCalendar class (I remember suggesting this in Redwood city in 1996:-)<br />
Calculating days between dates is important, but what about calculating working houres between dates! This becomes especially important in project management software. You need to first merge two or three NSCalendar objects (the one for the company with the regular working hours, the one for the person for whom we are tracking the tasks which may add some vacations or different working hours and maybe even a project calendar).</p>
<p>Then, we need to be able to ask: &#8220;At what date and time shall we be if we add X working hours to a given date and time considering calendar A and B&#8221;&#8230;</p>
<p>Of course, I had that kind of class in a pet project of mine. But if Apple could bring some basic NSCalendar it would be a great help (it would have to be core data compatible since we would want to store custom calendars).</p>
<p>Alexander Lamb</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-27</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Sun, 10 Jul 2005 05:01:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-27</guid>
		<description>and then there is the issue of what day it really is... because people use the language so ambiguously, you might go out with some friends at 10pm, and talk about what you are doing tomorow. then, at 2am, or even 4am, everyone says let's call it a night, and then what do they say? 'See you tomorrow!' - meaning see you later today. So, to an extent, you would have to put context into the class, because if i had been to bed and gotten up at 4am and seen them, i would say 'see you later today.'

best wishes in the classes. can think of a few other ways to do it, but all end up doing essentially the same things already posted.</description>
		<content:encoded><![CDATA[<p>and then there is the issue of what day it really is&#8230; because people use the language so ambiguously, you might go out with some friends at 10pm, and talk about what you are doing tomorow. then, at 2am, or even 4am, everyone says let&#8217;s call it a night, and then what do they say? &#8216;See you tomorrow!&#8217; - meaning see you later today. So, to an extent, you would have to put context into the class, because if i had been to bed and gotten up at 4am and seen them, i would say &#8217;see you later today.&#8217;</p>
<p>best wishes in the classes. can think of a few other ways to do it, but all end up doing essentially the same things already posted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Malte Tancred</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-26</link>
		<dc:creator>Malte Tancred</dc:creator>
		<pubDate>Sun, 10 Jul 2005 01:53:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-26</guid>
		<description>As has been pointed out, an NSDay class would be nice. In my own efforts to solve the problem of representing whole days without getting caught in time zone hell, I stumbled over &lt;a href="http://www.tondering.dk/claus/calendar.html" rel="nofollow"&gt;The Calendar FAQ&lt;/a&gt;, in which one can learn about &lt;a href="http://www.tondering.dk/claus/cal/node3.html#sec-calcjd" rel="nofollow"&gt;Julian Day numbers&lt;/a&gt; and &lt;a href="http://www.tondering.dk/claus/cal/node7.html#SECTION00780000000000000000" rel="nofollow"&gt;how to calculate the week number&lt;/a&gt; (as defined in ISO standard 8601 and which we use in Sweden). The algorithms presented are easily implemented in just about any language. I've written code in Java and Objective-C (there're some hacks &lt;a href="http://oops.se/~malte/software.html" rel="nofollow"&gt;here&lt;/a&gt; if you're interested).

Oh, in ruby, all you  have to do is &lt;code&gt;require 'date'&lt;/code&gt;. I wouldn't be surprised if python has a similar API.</description>
		<content:encoded><![CDATA[<p>As has been pointed out, an NSDay class would be nice. In my own efforts to solve the problem of representing whole days without getting caught in time zone hell, I stumbled over <a href="http://www.tondering.dk/claus/calendar.html" rel="nofollow">The Calendar FAQ</a>, in which one can learn about <a href="http://www.tondering.dk/claus/cal/node3.html#sec-calcjd" rel="nofollow">Julian Day numbers</a> and <a href="http://www.tondering.dk/claus/cal/node7.html#SECTION00780000000000000000" rel="nofollow">how to calculate the week number</a> (as defined in ISO standard 8601 and which we use in Sweden). The algorithms presented are easily implemented in just about any language. I&#8217;ve written code in Java and Objective-C (there&#8217;re some hacks <a href="http://oops.se/~malte/software.html" >here</a> if you&#8217;re interested).</p>
<p>Oh, in ruby, all you  have to do is <code>require 'date'</code>. I wouldn&#8217;t be surprised if python has a similar API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John C. Randolph</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-25</link>
		<dc:creator>John C. Randolph</dc:creator>
		<pubDate>Sat, 09 Jul 2005 04:52:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-25</guid>
		<description>This reminds me of something I started many years ago, which was a set of classes to represent spans of time, and selections of time.  The span was a pair of dates, which could include NSDistantFuture and NSDistantPast.  The TimeSelection class was a set of spans, that automatically merged any spans added to it that overlapped existing spans.

-jcr</description>
		<content:encoded><![CDATA[<p>This reminds me of something I started many years ago, which was a set of classes to represent spans of time, and selections of time.  The span was a pair of dates, which could include NSDistantFuture and NSDistantPast.  The TimeSelection class was a set of spans, that automatically merged any spans added to it that overlapped existing spans.</p>
<p>-jcr</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierce Wetter</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-24</link>
		<dc:creator>Pierce Wetter</dc:creator>
		<pubDate>Fri, 08 Jul 2005 20:41:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-24</guid>
		<description>I've had a lot of experience with this problem. 

First off, when you want to represent a "day", not a timestamp, NSDate and NSCalendarDate are actually the wrong solution to the problem because they represent a point in time, not an entire day. You really want to calculate some sort of day offset. If you use 1/1/2001 as zero, that corresponds to NSCalendarDate, which makes conversion easy. 

If you must use NSCalendarDate (because its easy, because EOF/CoreData supports it, etc.) you have to use Noon, not midnight or DST or timezone issues will cause your date to shift inappropraitely. So day 0 is 1/1/2001 12:00 not 1/1/2001 00:00. If you get a non-noon time, then you'll have to round it to the nearest day, but 'ware midnight if you get times from both EST and PST...  

 In our case, the market closes at 4pm EST, so midnight is far away, but there's no good answer for what to do at 10pm PST...

  So of all the solutions, Bob's is best because he is independently rounding each date to a day, this is good because this part of the code is the most application dependent. If you're work day focused, and you're working with programmers, anything before 7am EST is probably the "previous day's work". If you're doing something else, perhaps midnight makes more sense. Rounding each date separately makes sense, because if you are using midnight, but have dates from different time zones, the round to day code will work correctly in then 1am EST will round to tomorrow, while 10pm PST will round to yesterday. 

The real solution is that if you really need days, you need an NSDay class, but I've been bitching about that for years (along with the inability of either EOF or CoreData to map a class to a simple data type like integer...)</description>
		<content:encoded><![CDATA[<p>I&#8217;ve had a lot of experience with this problem. </p>
<p>First off, when you want to represent a &#8220;day&#8221;, not a timestamp, NSDate and NSCalendarDate are actually the wrong solution to the problem because they represent a point in time, not an entire day. You really want to calculate some sort of day offset. If you use 1/1/2001 as zero, that corresponds to NSCalendarDate, which makes conversion easy. </p>
<p>If you must use NSCalendarDate (because its easy, because EOF/CoreData supports it, etc.) you have to use Noon, not midnight or DST or timezone issues will cause your date to shift inappropraitely. So day 0 is 1/1/2001 12:00 not 1/1/2001 00:00. If you get a non-noon time, then you&#8217;ll have to round it to the nearest day, but &#8216;ware midnight if you get times from both EST and PST&#8230;  </p>
<p> In our case, the market closes at 4pm EST, so midnight is far away, but there&#8217;s no good answer for what to do at 10pm PST&#8230;</p>
<p>  So of all the solutions, Bob&#8217;s is best because he is independently rounding each date to a day, this is good because this part of the code is the most application dependent. If you&#8217;re work day focused, and you&#8217;re working with programmers, anything before 7am EST is probably the &#8220;previous day&#8217;s work&#8221;. If you&#8217;re doing something else, perhaps midnight makes more sense. Rounding each date separately makes sense, because if you are using midnight, but have dates from different time zones, the round to day code will work correctly in then 1am EST will round to tomorrow, while 10pm PST will round to yesterday. </p>
<p>The real solution is that if you really need days, you need an NSDay class, but I&#8217;ve been bitching about that for years (along with the inability of either EOF or CoreData to map a class to a simple data type like integer&#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Ippolito</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-23</link>
		<dc:creator>Bob Ippolito</dc:creator>
		<pubDate>Fri, 08 Jul 2005 19:04:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-23</guid>
		<description>It's more correct because SECONDS_IN_DAY is going to have a little bit of drift (not really in the time spans we're talking about, but it's still not technically correct), and it accounts for time zones.  Your example only works for GMT.

Throwing out clampToDay and instead just converting to NSCalendarDate and doing a direct calculation with dayOfCommonEra should be perfectly fine, which gets rid most of the messages sent.  If you were using NSCalendarDate instead of NSDate to begin with (which you probably should, given how you intend to use them), then there are no intermediate objects at all.</description>
		<content:encoded><![CDATA[<p>It&#8217;s more correct because SECONDS_IN_DAY is going to have a little bit of drift (not really in the time spans we&#8217;re talking about, but it&#8217;s still not technically correct), and it accounts for time zones.  Your example only works for GMT.</p>
<p>Throwing out clampToDay and instead just converting to NSCalendarDate and doing a direct calculation with dayOfCommonEra should be perfectly fine, which gets rid most of the messages sent.  If you were using NSCalendarDate instead of NSDate to begin with (which you probably should, given how you intend to use them), then there are no intermediate objects at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Ippolito</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-22</link>
		<dc:creator>Bob Ippolito</dc:creator>
		<pubDate>Fri, 08 Jul 2005 18:37:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-22</guid>
		<description>Actually, you probably don't need the clamping.. dayOfCommonEra is probably enough.  It's early here.</description>
		<content:encoded><![CDATA[<p>Actually, you probably don&#8217;t need the clamping.. dayOfCommonEra is probably enough.  It&#8217;s early here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bbum</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-21</link>
		<dc:creator>bbum</dc:creator>
		<pubDate>Fri, 08 Jul 2005 18:37:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-21</guid>
		<description>Why is that any more correct than what I did?

And it ends up producing numerous temporary objects that are later tossed.</description>
		<content:encoded><![CDATA[<p>Why is that any more correct than what I did?</p>
<p>And it ends up producing numerous temporary objects that are later tossed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Ippolito</title>
		<link>http://www.friday.com/bbum/2005/07/08/days-between-dates-our-perception-of-time/comment-page-1/#comment-20</link>
		<dc:creator>Bob Ippolito</dc:creator>
		<pubDate>Fri, 08 Jul 2005 18:31:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.friday.com/bbum/?p=477#comment-20</guid>
		<description>Of course, the correct way to do it is to use NSCalendarDate..

&lt;code&gt;
NSCalendarDate *clampToDay(NSDate *d) {
    // might want to allow for timezone fudge here?
    NSCalendarDate *c = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:[d timeIntervalSinceReferenceDate]];
    return [c dateByAddingYears:0 months:0 days:0 hours:-[c hourOfDay] minutes:-[c minuteOfHour] seconds:-[secondsOfMinute]];
}

int stupidHumanDateDifference(NSDate *a, NSDate *b) {
    return [clampToDay(b) dayOfCommonEra] - [clampToDay(a) dayOfCommonEra];
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Of course, the correct way to do it is to use NSCalendarDate..</p>
<p><code><br />
NSCalendarDate *clampToDay(NSDate *d) {<br />
    // might want to allow for timezone fudge here?<br />
    NSCalendarDate *c = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:[d timeIntervalSinceReferenceDate]];<br />
    return [c dateByAddingYears:0 months:0 days:0 hours:-[c hourOfDay] minutes:-[c minuteOfHour] seconds:-[secondsOfMinute]];<br />
}</p>
<p>int stupidHumanDateDifference(NSDate *a, NSDate *b) {<br />
    return [clampToDay(b) dayOfCommonEra] - [clampToDay(a) dayOfCommonEra];<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
