<?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: Ranges with dates (in Groovy)</title>
	<atom:link href="http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/feed/" rel="self" type="application/rss+xml" />
	<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/</link>
	<description>Peter Maas's Weblog</description>
	<pubDate>Sat, 30 Aug 2008 10:10:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: peter</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11930</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 03 Dec 2007 10:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11930</guid>
		<description>With a little help from a colleague if figured out how to used Rails' date and time extensions when not running in Rails. Just load active_support:

&lt;pre&gt;
&lt;code&gt;
irb(main):005:0&gt; require 'rubygems'
=&gt; true
irb(main):006:0&gt; require 'active_support'
=&gt; true
&lt;/code&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>With a little help from a colleague if figured out how to used Rails&#8217; date and time extensions when not running in Rails. Just load active_support:</p>
<pre>
<code>
irb(main):005:0> require 'rubygems'
=> true
irb(main):006:0> require 'active_support'
=> true
</code>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Using propertyMissing to enhance Date (in Groovy) at log4p</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11914</link>
		<dc:creator>Using propertyMissing to enhance Date (in Groovy) at log4p</dc:creator>
		<pubDate>Sun, 02 Dec 2007 21:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11914</guid>
		<description>[...] Register          &#171; Ranges with dates (in Groovy) [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Register          &laquo; Ranges with dates (in Groovy) [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: railsguru</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11912</link>
		<dc:creator>railsguru</dc:creator>
		<pubDate>Sun, 02 Dec 2007 20:58:08 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11912</guid>
		<description>Grr, &#60;=&#62; and succ that is..</description>
		<content:encoded><![CDATA[<p>Grr, &lt;=&gt; and succ that is..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: railsguru</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11911</link>
		<dc:creator>railsguru</dc:creator>
		<pubDate>Sun, 02 Dec 2007 20:57:23 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11911</guid>
		<description>Indeed! That's the new thing I learned from this small excercise :)

As long as your class implements  and succ you can use it in Range:

http://ruby-doc.org/core/classes/Range.html</description>
		<content:encoded><![CDATA[<p>Indeed! That&#8217;s the new thing I learned from this small excercise <img src='http://maas-frensch.com/peter/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
As long as your class implements  and succ you can use it in Range:</p>
<p><a href="http://ruby-doc.org/core/classes/Range.html" rel="nofollow">http://ruby-doc.org/core/classes/Range.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11910</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 02 Dec 2007 20:48:14 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11910</guid>
		<description>But hey, interesting... Rails' date object can actually be used in a range?</description>
		<content:encoded><![CDATA[<p>But hey, interesting&#8230; Rails&#8217; date object can actually be used in a range?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11909</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 02 Dec 2007 20:46:56 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11909</guid>
		<description>Aha, makes sense ;) ... I always tend to forget about the fact that Rails uses its' own date and time classes...</description>
		<content:encoded><![CDATA[<p>Aha, makes sense <img src='http://maas-frensch.com/peter/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> &#8230; I always tend to forget about the fact that Rails uses its&#8217; own date and time classes&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: railsguru</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11908</link>
		<dc:creator>railsguru</dc:creator>
		<pubDate>Sun, 02 Dec 2007 20:41:50 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11908</guid>
		<description>The code is mend to be run in a Rails environment e.g. script/console.  Anyway.. not trying to prove a point, just checked to see if the same could be done in Ruby :)</description>
		<content:encoded><![CDATA[<p>The code is mend to be run in a Rails environment e.g. script/console.  Anyway.. not trying to prove a point, just checked to see if the same could be done in Ruby <img src='http://maas-frensch.com/peter/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11902</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 02 Dec 2007 19:08:06 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11902</guid>
		<description>If you execute the code exactly as you pasted it; it wouldn't work. The Groovy code does work without any further 'import' or 'require'.

If I execute:
&lt;pre&gt;
&lt;code&gt;
irb&gt; require 'date/format' 
irb&gt; bd_peter = Date._parse('18-01-1979')
=&gt; {:mon=&gt;1, :year=&gt;1979, :mday=&gt;18}
irb&gt; bd_peter = Date._parse('18-01-1979')
=&gt; {:mon=&gt;1, :year=&gt;1979, :mday=&gt;18}
irb&gt; bd_daan = Date._parse('23-01-1980')
=&gt; {:mon=&gt;1, :year=&gt;1980, :mday=&gt;23}
irb&gt; (bd_peter..bd_daan).each{&#124;d&#124; puts d if d.wday.zero?}
ArgumentError: bad value for range
        from (irb):18
        from :0
&lt;/code&gt;
&lt;/pre&gt;

Did I import the wrong date??

There also is a slight difference in your ruby solution; which I could have used in my example... I build an array of the results and display it in a second each loop... could have been simpler:

&lt;pre&gt;
&lt;code&gt;
sdf = new java.text.SimpleDateFormat("dd-MM-yyyy")

bd_daan = sdf.parse("23-01-1980")    
bd_peter = sdf.parse("18-01-1979") 

t = Calendar.instance  
all_sundays = (bd_peter..bd_daan).each{
	t.time = it; 
	if(t.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
		println sdf.format(it)
}
&lt;/code&gt;
&lt;/pre&gt;

Mind you, the use of a intermediate Calendar object is a bit overkill in this case... as is the use of the full blown Java date formatter. But the advantage is: full locale awareness when needed.</description>
		<content:encoded><![CDATA[<p>If you execute the code exactly as you pasted it; it wouldn&#8217;t work. The Groovy code does work without any further &#8216;import&#8217; or &#8216;require&#8217;.</p>
<p>If I execute:</p>
<pre>
<code>
irb> require 'date/format'
irb> bd_peter = Date._parse('18-01-1979')
=> {:mon=>1, :year=>1979, :mday=>18}
irb> bd_peter = Date._parse('18-01-1979')
=> {:mon=>1, :year=>1979, :mday=>18}
irb> bd_daan = Date._parse('23-01-1980')
=> {:mon=>1, :year=>1980, :mday=>23}
irb> (bd_peter..bd_daan).each{|d| puts d if d.wday.zero?}
ArgumentError: bad value for range
        from (irb):18
        from :0
</code>
</pre>
<p>Did I import the wrong date??</p>
<p>There also is a slight difference in your ruby solution; which I could have used in my example&#8230; I build an array of the results and display it in a second each loop&#8230; could have been simpler:</p>
<pre>
<code>
sdf = new java.text.SimpleDateFormat("dd-MM-yyyy")

bd_daan = sdf.parse("23-01-1980")
bd_peter = sdf.parse("18-01-1979") 

t = Calendar.instance
all_sundays = (bd_peter..bd_daan).each{
	t.time = it;
	if(t.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
		println sdf.format(it)
}
</code>
</pre>
<p>Mind you, the use of a intermediate Calendar object is a bit overkill in this case&#8230; as is the use of the full blown Java date formatter. But the advantage is: full locale awareness when needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: railsguru</title>
		<link>http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11894</link>
		<dc:creator>railsguru</dc:creator>
		<pubDate>Sun, 02 Dec 2007 12:04:26 +0000</pubDate>
		<guid isPermaLink="false">http://maas-frensch.com/peter/2007/12/01/ranges-with-dates/#comment-11894</guid>
		<description>bd_daan = Date.parse("23-01-1980")
bd_peter = Date.parse("18-01-1979")

(bd_peter..bd_daan).each { &#124;d&#124; puts d if d.wday.zero? }</description>
		<content:encoded><![CDATA[<p>bd_daan = Date.parse(&#8221;23-01-1980&#8243;)<br />
bd_peter = Date.parse(&#8221;18-01-1979&#8243;)</p>
<p>(bd_peter..bd_daan).each { |d| puts d if d.wday.zero? }</p>
]]></content:encoded>
	</item>
</channel>
</rss>
