<?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: DDD: making the Time Period concept explicit</title>
	<atom:link href="http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/feed/" rel="self" type="application/rss+xml" />
	<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/</link>
	<description>The adventures of a young kiwi software developer in London</description>
	<lastBuildDate>Tue, 07 Sep 2010 06:56:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Richard</title>
		<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/comment-page-1/#comment-13272</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Mon, 29 Mar 2010 08:16:53 +0000</pubDate>
		<guid isPermaLink="false">http://richarddingwall.name/?p=2563#comment-13272</guid>
		<description>Daniel : Love it. I think we needed a Split method before, good idea.</description>
		<content:encoded><![CDATA[<p>Daniel : Love it. I think we needed a Split method before, good idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/comment-page-1/#comment-12904</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sat, 13 Mar 2010 21:50:41 +0000</pubDate>
		<guid isPermaLink="false">http://richarddingwall.name/?p=2563#comment-12904</guid>
		<description>Very nice.
Something alike should be included in .net.

I&#039;ve added 4 more methods, what do you think of them?


    /// 
    /// Splits TimePeriod
    /// 
    /// Any Time (within or out of TimePeriod)
    /// 1 or 2 new Elements
    public IEnumerable Split(DateTime splitTime)
    {
        if (splitTime &gt; Start &amp;&amp; (!End.HasValue &#124;&#124; End.Value &gt; splitTime))
            return new TimePeriod[] { new TimePeriod(Start, splitTime), new TimePeriod(splitTime, End) };
        else
            return new TimePeriod[] { (TimePeriod)this.MemberwiseClone() };
    }

    /// 
    /// Removes/Substracts onther Timeperiod
    /// 
    /// To be substracted
    /// returns 0, 1 or 2 new Elements
    public IEnumerable Remove(TimePeriod other)
    {
        List result = new List();

        // everything left over
        if (!Overlaps(other))
            result.Add(new TimePeriod(this.Start, this.End));
        // left side or right side or both sides or nothing left over
        else
        {
            // left ok
            if (this.Start  other.End))
                result.Add(new TimePeriod(other.End.Value, this.End));
        }
        return result;
    }

    /// 
    /// Compares 2 timelines and returns overlaps
    /// 
    /// Timeline1
    /// Timeline2
    /// new timeline of overlaps
    public static IEnumerable GetOverlaps(IEnumerable timePeriods1, IEnumerable timePeriods2)
    {
        List result = new List();

        foreach (TimePeriod t1 in timePeriods1)
        {
            foreach (TimePeriod t2 in timePeriods2)
            {
                // t1 eats t2
                if (t1.Start = t2.End))
                    result.Add(new TimePeriod(t2.Start, t2.End));
                // t2 eats t1
                else if (t1.Start &gt;= t2.Start &amp;&amp; (t2.IsInfinite &#124;&#124; t1.End &lt;= t2.End))
                    result.Add(new TimePeriod(t1.Start, t1.End));
                // t1 touches t2 on t1&#039;s right side
                else if (t1.Start  t2.Start)
                    result.Add(new TimePeriod(t2.Start, t1.End));
                // t1 touches t2 on t1&#039;s left side
                else if (t1.Start &gt; t2.Start &amp;&amp; t1.Start &lt; t2.End)
                    result.Add(new TimePeriod(t1.Start, t2.End));
            }
        }
        return result;
    }

    /// 
    /// Removes TimePeriods from a timeline
    /// 
    /// Timeline
    /// TimePeriods that (might) overlap and shall be removed from timeline
    /// new timeline without overlaps
    public static IEnumerable RemoveOverlaps(IEnumerable timePeriods, IEnumerable overlaps)
    {
        List result = timePeriods.ToList();

        for (int i = 0; i &lt; result.Count; i++)
        {
            foreach (TimePeriod overlap in overlaps)
            {
                if (result[i].Overlaps(overlap))
                {
                    // Add rest of clash (if exists) to end to be processed as well
                    result.AddRange(result[i].Remove(overlap));

                    // Remove overlapping TimePeriod
                    result.RemoveAt(i);
                }
            }
        }
        return result;
    }
</description>
		<content:encoded><![CDATA[<p>Very nice.<br />
Something alike should be included in .net.</p>
<p>I&#8217;ve added 4 more methods, what do you think of them?</p>
<p>    ///<br />
    /// Splits TimePeriod<br />
    ///<br />
    /// Any Time (within or out of TimePeriod)<br />
    /// 1 or 2 new Elements<br />
    public IEnumerable Split(DateTime splitTime)<br />
    {<br />
        if (splitTime &gt; Start &amp;&amp; (!End.HasValue || End.Value &gt; splitTime))<br />
            return new TimePeriod[] { new TimePeriod(Start, splitTime), new TimePeriod(splitTime, End) };<br />
        else<br />
            return new TimePeriod[] { (TimePeriod)this.MemberwiseClone() };<br />
    }</p>
<p>    ///<br />
    /// Removes/Substracts onther Timeperiod<br />
    ///<br />
    /// To be substracted<br />
    /// returns 0, 1 or 2 new Elements<br />
    public IEnumerable Remove(TimePeriod other)<br />
    {<br />
        List result = new List();</p>
<p>        // everything left over<br />
        if (!Overlaps(other))<br />
            result.Add(new TimePeriod(this.Start, this.End));<br />
        // left side or right side or both sides or nothing left over<br />
        else<br />
        {<br />
            // left ok<br />
            if (this.Start  other.End))<br />
                result.Add(new TimePeriod(other.End.Value, this.End));<br />
        }<br />
        return result;<br />
    }</p>
<p>    ///<br />
    /// Compares 2 timelines and returns overlaps<br />
    ///<br />
    /// Timeline1<br />
    /// Timeline2<br />
    /// new timeline of overlaps<br />
    public static IEnumerable GetOverlaps(IEnumerable timePeriods1, IEnumerable timePeriods2)<br />
    {<br />
        List result = new List();</p>
<p>        foreach (TimePeriod t1 in timePeriods1)<br />
        {<br />
            foreach (TimePeriod t2 in timePeriods2)<br />
            {<br />
                // t1 eats t2<br />
                if (t1.Start = t2.End))<br />
                    result.Add(new TimePeriod(t2.Start, t2.End));<br />
                // t2 eats t1<br />
                else if (t1.Start &gt;= t2.Start &amp;&amp; (t2.IsInfinite || t1.End &lt;= t2.End))<br />
                    result.Add(new TimePeriod(t1.Start, t1.End));<br />
                // t1 touches t2 on t1&#039;s right side<br />
                else if (t1.Start  t2.Start)<br />
                    result.Add(new TimePeriod(t2.Start, t1.End));<br />
                // t1 touches t2 on t1&#8242;s left side<br />
                else if (t1.Start &gt; t2.Start &amp;&amp; t1.Start &lt; t2.End)<br />
                    result.Add(new TimePeriod(t1.Start, t2.End));<br />
            }<br />
        }<br />
        return result;<br />
    }</p>
<p>    ///<br />
    /// Removes TimePeriods from a timeline<br />
    ///<br />
    /// Timeline<br />
    /// TimePeriods that (might) overlap and shall be removed from timeline<br />
    /// new timeline without overlaps<br />
    public static IEnumerable RemoveOverlaps(IEnumerable timePeriods, IEnumerable overlaps)<br />
    {<br />
        List result = timePeriods.ToList();</p>
<p>        for (int i = 0; i &lt; result.Count; i++)<br />
        {<br />
            foreach (TimePeriod overlap in overlaps)<br />
            {<br />
                if (result[i].Overlaps(overlap))<br />
                {<br />
                    // Add rest of clash (if exists) to end to be processed as well<br />
                    result.AddRange(result[i].Remove(overlap));</p>
<p>                    // Remove overlapping TimePeriod<br />
                    result.RemoveAt(i);<br />
                }<br />
            }<br />
        }<br />
        return result;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/comment-page-1/#comment-12673</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Fri, 12 Feb 2010 14:14:55 +0000</pubDate>
		<guid isPermaLink="false">http://richarddingwall.name/?p=2563#comment-12673</guid>
		<description>Thanks, they&#039;re generated live from http://yuml.me</description>
		<content:encoded><![CDATA[<p>Thanks, they&#8217;re generated live from <a href="http://yuml.me" rel="nofollow">http://yuml.me</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/comment-page-1/#comment-12672</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Fri, 12 Feb 2010 14:11:07 +0000</pubDate>
		<guid isPermaLink="false">http://richarddingwall.name/?p=2563#comment-12672</guid>
		<description>What do you use to make your diagram? It&#039;s very nice.</description>
		<content:encoded><![CDATA[<p>What do you use to make your diagram? It&#8217;s very nice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/comment-page-1/#comment-11748</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Thu, 26 Nov 2009 09:40:22 +0000</pubDate>
		<guid isPermaLink="false">http://richarddingwall.name/?p=2563#comment-11748</guid>
		<description>@pozorvlak: you could have a null start for &quot;since the start of time until X&quot; but we haven&#039;t needed that yet.</description>
		<content:encoded><![CDATA[<p>@pozorvlak: you could have a null start for &#8220;since the start of time until X&#8221; but we haven&#8217;t needed that yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pozorvlak</title>
		<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/comment-page-1/#comment-11747</link>
		<dc:creator>pozorvlak</dc:creator>
		<pubDate>Thu, 26 Nov 2009 09:34:35 +0000</pubDate>
		<guid isPermaLink="false">http://richarddingwall.name/?p=2563#comment-11747</guid>
		<description>It makes me nervous that you represent semi-infinite intervals going forwards but not going backwards (&quot;before next Tuesday&quot; as opposed to &quot;from now on&quot;). I suppose you could use the beginning of the epoch, but it seems ugly.

Then again, I can&#039;t see much use for (\infty, n] intervals  in a business context.</description>
		<content:encoded><![CDATA[<p>It makes me nervous that you represent semi-infinite intervals going forwards but not going backwards (&#8220;before next Tuesday&#8221; as opposed to &#8220;from now on&#8221;). I suppose you could use the beginning of the epoch, but it seems ugly.</p>
<p>Then again, I can&#8217;t see much use for (\infty, n] intervals  in a business context.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Gardner</title>
		<link>http://richarddingwall.name/2009/11/25/ddd-making-the-time-period-concept-explicit/comment-page-1/#comment-11726</link>
		<dc:creator>Christopher Gardner</dc:creator>
		<pubDate>Wed, 25 Nov 2009 01:32:34 +0000</pubDate>
		<guid isPermaLink="false">http://richarddingwall.name/?p=2563#comment-11726</guid>
		<description>Very nice stuff.  This class looks remarkably similar to CalendarInterval, a class I wrote for my Java applications.</description>
		<content:encoded><![CDATA[<p>Very nice stuff.  This class looks remarkably similar to CalendarInterval, a class I wrote for my Java applications.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
