I'm trying to create a method to determine whether or not a particular date and time (within a certain timezone) are within a range.
range = between(start_time, end_time)
start_time = "date time timezone"
end_time = "date time timezone"
Here's an example of what the range input will look like:
range => between("2013-12-25 04:45:00 -0800", "2015-12-25 5:00:01 -0800")
I want to return true or false if a particular date and time falls within this range.
Example particular date:
instance = "2014-01-01 16:35:45 -0800"
instance.between("2013-12-25 04:45:00 -0800", "2015-12-25 5:00:01 -0800")
I don't have much experience with time in Ruby. Any suggestions would be greatly appreciated.
require "date"
instance = DateTime.parse("2014-01-01 16:35:45 -0800")
d1 = DateTime.parse("2013-12-25 04:45:00 -0800")
d2 = DateTime.parse("2015-12-25 5:00:01 -0800")
p instance.between?( d1, d2 ) # => true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With