开发者

get next 12 weeks of fridays

开发者 https://www.devze.com 2023-03-25 00:46 出处:网络
I am currently doing this: x = Date.today y = x + 12.weeks (x..y).each do |date| next unless date.strftime(\"%A\") == \'Friday\'

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

精彩评论

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