Newbie: dates by week and year

Hi Everybody,

Am a newbie to ruby, so forgive me if this is a stupid question,

I’m looking for a way to get a series of dates (monday - sunday or
sunday - saturday) , but I’m only having
the year and the week number…

Hopefully someone can help,
Kind regards,
Jeroen van Doorn

Jeroen van Doorn wrote:

Jeroen van Doorn

http://www.rubycentral.com/book/ref_c_time.html#Time.strftime

On Fri, 7 Apr 2006, Jeroen van Doorn wrote:

Jeroen van Doorn
this ought to get you going:

 harp:~ > cat a.rb
 require 'date'

 def weekno year, week
   jjj = (7 * (week - 1)) + 1
   jd = Date.ordinal_to_jd year, jjj
   yyyy, m, d = Date.jd_to_civil jd
   a = Date.new yyyy, m, d
   b = Date.new yyyy, m, d + 7
   (a ... b)
 end

 first = weekno 2006, 1
 p first.map{|day| day.to_s}

 second = weekno 2006, 2
 p second.map{|day| day.to_s}

 third = weekno 2006, 3
 p third.map{|day| day.to_s}



 harp:~ > ruby a.rb
 ["2006-01-01", "2006-01-02", "2006-01-03", "2006-01-04", 

“2006-01-05”, “2006-01-06”, “2006-01-07”]
[“2006-01-08”, “2006-01-09”, “2006-01-10”, “2006-01-11”,
“2006-01-12”, “2006-01-13”, “2006-01-14”]
[“2006-01-15”, “2006-01-16”, “2006-01-17”, “2006-01-18”,
“2006-01-19”, “2006-01-20”, “2006-01-21”]

regards.

-a

Thanks for the answer!

This one really gave me a headache …

Kind regards,
Jeroen van Doorn