How can I check for inclusion of a datetime in a range in Rails? -


using ruby's range#include? datetime range throws exception:

> (time.zone.now.beginning_of_day..time.zone.now.end_of_day).include?(time.zone.now) typeerror: can't iterate activesupport::timewithzone 

while using rails' range#overlaps? works:

> (time.zone.now.beginning_of_day..time.zone.now.end_of_day).overlaps?(time.zone.now..time.zone.now) => true 

i dislike fact have create single-element range check inclusion using overlaps? there way use include? datetime range in rails?

aha!

how this?

time.zone.now.between?(time.zone.now.beginning_of_day,time.zone.now.end_of_day) 

result:

2.3.0 :001 > time.zone.now.between?(time.zone.now.beginning_of_day,time.zone.tomorrow.end_of_day)  => true  2.3.0 :002 > time.zone.tomorrow.between?(time.zone.now.beginning_of_day,time.zone.now.end_of_day)  => false  2.3.0 :003 > time.zone.yesterday.between?(time.zone.now.beginning_of_day,time.zone.now.end_of_day) 

reference: http://apidock.com/rails/activesupport/timewithzone/between%3f


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -