Generating Chunks of Time Using Ruby

The problem was iterating over a large amount of time series data. I figured generating a series of time chunks within certain start and end parameters, and of a certain time interval size could help scan through this data.

I wrote the following method to help generate these chunks of time which can then be passed to an ActiveRecord query to search within that time chunk for relevant data.

What is returned is an array of arrays where each internal array contains a start time and an end time which can then be used in further methods.

It escapes early if there is only one possible chunk for the given parameters. It also makes sure that the start time of the first interval is the given start parameter and the same is true for the end time of the last chunk.