Ruby 区间 日期数组 step by day or hour

step by day

end_ats = '2019-08-01'.to_date.upto('2019-09-15'.to_date)
end_ats.each do |end_at|
  Daily::SignIn.store(end_at: end_at)
end

Step by hour

Date.today.beginning_of_day.to_datetime.step((DateTime.now),Rational(1,24)){|d| puts d}
2019-09-12 at 3.02 PM.png

每月第一天和每月最后一天

(Date.new(2008, 12)..Date.new(2011, 12)).select {|d| d.day == 1}

(Date.new(2008, 12)..Date.new(2012, 01)).select {|d| d.day == 1}.map {|d| d - 1}.drop(1)

你可能感兴趣的:(Ruby 区间 日期数组 step by day or hour)