Working in Python, I've got a list of dicts containing a start date, end date and a list of values.
These may overlap and I need to break them into unique time periods, and merge the values from any overlapping period.
For example:
[
# Cover the space of 1 year
{
"values": ["a", "b", "c"],
"start": "2023-01-01T00:00:00+00:00",
"end": "2024-01-01T00:00:00+00:00",
},
# Overlapping month with new values
{
"values": ["d", "e"],
"start": "2023-02-01T00:00:00+00:00",
"end": "2023-03-01T00:00:00+00:00",
},
]
Should output:
[
{
"values": ["a", "b", "c"],
"start": "2023-01-01T00:00:00+00:00",
"end": "2023-02-01T00:00:00+00:00",
},
{
"values": ["a", "b", "c", "d", "e"],
"start": "2023-02-01T00:00:00+00:00",
"end": "2022-03-01T00:00:00+00:00",
},
{
"values": ["d", "e"],
"start": "2023-03-01T00:00:00+00:00",
"end": "2024-01-01T00:00:00+00:00",
},
]
I've been able to merge all the dates down to a single date range of the min/max, but I'm completely stumped on how I can dynamically work out the overlapping values.