check time between 9.30 to 4 ruby

后端 未结 4 733
刺人心
刺人心 2020-12-31 11:41

i have a code that erroneously produces it and i am thinking that there must be a better way to check for time >9.30 am and time <4 pm any ideas is highly appreicated.<

4条回答
  •  爱一瞬间的悲伤
    2020-12-31 12:18

    Working in a mixed version environment and needing this exact method here's what I put in my code:

    if RUBY_VERSION == "1.9.3"
      def check_time(starthour,endhour,t=Time.now)
        early = Time.new(t.year, t.month, t.day, starthour, 0, 0)
        late  = Time.new(t.year, t.month, t.day, endhour, 0, 0)
        t.between?(early, late)
      end
    elsif RUBY_VERSION == "1.8.7"
      def check_time(starthour,endhour,t=Time.now)
        early = Time.local(t.year, t.month, t.day, starthour, 0, 0)
        late  = Time.local(t.year, t.month, t.day, endhour, 0, 0)
        t.between?(early, late)
      end
    end
    

提交回复
热议问题