检查时间在 9.30 到 4 ruby​​ 之间 [英] check time between 9.30 to 4 ruby

查看:25
本文介绍了检查时间在 9.30 到 4 ruby​​ 之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个错误生成它的代码,我认为必须有更好的方法来检查时间 > 9.30 am 和时间 <4 pm任何想法都受到高度赞赏.

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.

def checkTime

   goodtime=false
   if(Time.now.hour>9 and Time.now.min>30) then

     if(Time.now.hour<16) then
       goodtime=true

     else
       # do nothing
     end
   elsif Time.now.hour>9 and Time.now.hour<16 then
     goodtime=true

   else
      # do nothing
   end
   return goodtime

 end

推荐答案

t = Time.now

Range.new(
  Time.local(t.year, t.month, t.day, 9),
  Time.local(t.year, t.month, t.day, 16, 30)
) === t

这篇关于检查时间在 9.30 到 4 ruby​​ 之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆