how can i get a list of DateTime objects which match the following criteria:
- they are between two instances of DateTime
- they fall on a fraction of an hour/min. eg. they are a full quarter of an hour
with active support a possible solution is:
(my_datetime_ob_a.to_i .. my_datetime_ob_b.to_i).each { |timestamp|
puts timestamp if (timestamp % (3600/4) == 0)
}
this is not nice: too many iterations and too much conversion (you would need to reconvert timestamp to a DateTime object.
Here is an alternative approach:
my_datetime_ob_awhich is a full quarter of an hour (i.e. round up to 15 minute interval)my_datetime_ob_bput it in your list, add 15 minutes and loopImplementation:
Example: