Ruby, check if date is a weekend?

后端 未结 7 1548
灰色年华
灰色年华 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:46

    class Time
      def is_weekend?
        [0, 6, 7].include?(wday)
      end
    end
    
    time = Time.new
    
    puts "Current Time : " + time.inspect
    puts time.is_weekend?
    

提交回复
热议问题