我有一个具有start_date
和stop_date
属性的订阅对象。我想看看当前日期是否在这些时间范围之间。我做到了:
Time.now # => 2018-09-20 22:07:15 -0500
subscription.start_date # => Wed, 19 Sep 2018
subscription.stop_date # => Fri, 21 Sep 2018
Time.now.between? subscription.start_date, subscription.stop_date # => false
Time.now.between?
似乎不准确,我也不知道为什么。怎么了这似乎应该工作。 9月20日介于9月19日至9月21日之间,但仍显示为false。
答案 0 :(得分:2)
因此,我找到了解决问题的方法。我必须使用Time.now.to_date.between?
而不是Time.now.between?
进行此更改后,它终于按预期返回了true
。