为清晰起见更新:我的星期三或星期六的开始日期为一张彩票,而星期二或星期五为另一张彩票。鉴于开始日期,我需要无限期的门票抽奖日期,在相应门票的给定日期之间交替。开始日期已经过验证,可以在本周的这几天进行比赛。
我想检查强力球图纸是在星期三或星期六的正确日期连续安排的:
# Increment zero is the first subsequent drawing
if increment.zero?
if starting_date.saturday? or starting_date.friday?
starting_date + 4.days
else
starting_date + 3.days
end
elsif increment == 1
starting_date + 1.week
else
if starting_date.saturday? or starting_date.friday?
starting_date + (increment / 2.0).ceil.weeks + 4.days
else
starting_date + (increment / 2.0).ceil.weeks + 3.days
end
end
我得到了一些结果......
t.lines[0].draw_date #=> Wed, 09 Mar 2016
t.lines[1].draw_date #=> Sat, 12 Mar 2016
t.lines[2].draw_date #=> Wed, 16 Mar 2016
t.lines[3].draw_date #=> Sat, 19 Mar 2016
t.lines[4].draw_date #=> Sat, 26 Mar 2016
t.lines[5].draw_date #=> Sat, 26 Mar 2016
t.lines[6].draw_date #=> Sat, 02 Apr 2016
t.lines[7].draw_date #=> Sat, 02 Apr 2016
似乎应该有一个简单的解决方案。
答案 0 :(得分:0)
loop do
break d if d.wednesday? || d.saturday?
d += 1.day
end
答案 1 :(得分:0)
我找到了解决方案......
if increment.even?
if starting_date.saturday? or starting_date.friday?
starting_date + (increment / 2).weeks + 4.days
else
starting_date + (increment / 2).weeks + 3.days
end
elsif increment.odd?
if starting_date.saturday? or starting_date.friday?
starting_date + (increment / 2.0).ceil.weeks
else
starting_date + (increment / 2.0).ceil.weeks
end
end