Recursive algorithm for coalescing / collapsing list of dates into ranges.

Posted by Dycey on Stack Overflow See other posts from Stack Overflow or by Dycey
Published on 2010-05-18T12:58:04Z Indexed on 2010/05/18 13:00 UTC
Read the original article Hit count: 173

Given a list of dates

12/07/2010
13/07/2010
14/07/2010
15/07/2010
12/08/2010
13/08/2010
14/08/2010
15/08/2010
19/08/2010
20/08/2010
21/08/2010

I'm looking for pointers towards a recursive pseudocode algorithm (which I can translate into a FileMaker custom function) for producing a list of ranges, i.e.

12/07/2010 to 15/07/2010, 12/08/2010 to 15/08/2010, 19/08/2010 to 20/08/2010

The list is presorted and de-deuplicated. I've tried starting from both the first value and working forwards, and the last value and working backwards but I just can't seem to get it to work. Having one of those frustrating days... It would be nice if the signature was something like

CollapseDateList( dateList, separator, ellipsis )

:-)

© Stack Overflow or respective owner

Related posts about recursive

Related posts about date-range