factor out date aggregation