如何在Ruby中按编号选择当前年份的季度?

时间:2013-10-18 10:54:34

标签: ruby-on-rails ruby date

我希望有像

这样的方法
Shift.by_quarter(1) => each shift in first quarter of current year

现在我按日期选择四分之一班次

Shift
  scope :by_quarter, lambda{|date| 
    where starts_at: date.beginning_of_quarter..date.end_of_quarter}

1 个答案:

答案 0 :(得分:4)

我的解决方案:

scope :by_quarter, lambda{|quarter| 
    date = Date.new(Date.today.year, quarter * 3)
    where starts_at: date.beginning_of_quarter..date.end_of_quarter }