开发者

get next 12 weeks of fridays

I am currently doing this:

x = Date.today
y = x + 12.weeks
(x..y).each do |date|
  next unless date.strftime("%A") == 'Friday'
  @dates << date
end

There has to be better code to do this, can anyone give it to me or give me the right thing to开发者_开发技巧 look for to find how to do it?

Thanks


Nice one-liner: (Date.today..Date.today + 12.weeks).select(&:friday?) - Voila!


  x = Date.today
  x += 1.day while x.wday < 5
  @dates = (0...12).map{|i| x+i.weeks}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜