Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing datetimes and joining when they are within 5 minutes
    primarykey
    data
    text
    <p>I have a large array of DateTimes. For example:</p> <pre><code>[2013-06-17 19:47:12, 2013-06-17 19:40:01, 2013-06-17 19:42:53, 2013-06-17 19:12:27, 2013-06-17 19:45:42, 2013-06-17 19:14:17]... etc </code></pre> <p>What I'd like to do is iterate through the array and come up with a bunch of ranges for DateTime objects that are within 5 minutes of one another.</p> <p>So, the result I would get is: </p> <pre><code>[ {range_start: 2013-06-17 19:40:01, range_end: 2013-06-17 19:47:12}, {range_start: 2013-06-17 19:12:27, range_end: 2013-06-17 19:14:17}, ] </code></pre> <p>As you can see, the first object in the result set would contain all 4 DateTime objects in the example above by getting the earliest time and latest time and making a range. Likewise for the second.</p> <p>Basically, what I'm trying to do is group together DateTimes that are within 5 minutes of each other, however I'm not sure how to do it without excessive recursion. For example, once I grab the first DateTime and I find another that is within 5 minutes of it, I then need to find all the other DateTime items that are within 5 minutes of the recently found DateTime.</p> <ol> <li>Start at minute 42</li> <li>Search 5 minutes before and after</li> <li>Find another DateTime at minute 44, so now range is 42-44</li> <li>Need to search 5 minutes before and after range of 42-44 (so anything from 38 to 49)</li> <li>If I find something at minute 49, then range goes to 42-49</li> <li>Now search radius is 38 to 54, etc...</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload