detect date intervals and aggregate