Ruby, check if date is a weekend?

后端 未结 7 1546
灰色年华
灰色年华 2021-02-02 08:51

I have a DailyQuote model in my rails application which has a date and price for a stock. Data in the database has been captured for this model

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-02 09:31

    weekend_days = [0,6]
    if (self.start_date.to_date..self.end_date.to_date).to_a.select {|k| weekend_days.include?(k.wday)}.present?
      # you code
    end
    

提交回复
热议问题