In my calendar, the structure is as follows:
const calendar = [{
"Title": "Go Shopping",
"dates": [
{
"DateBeginn": "19.02.2021",
"DateEnd": "22.02.2021",
"Where": "Supermarket",
},
{
"DateBeginn": "23.02.2021",
"DateEnd": "23.02.2021",
"Where": "Biomarket"
}]
}]
const calendarData = calendar.map(main => main.dates.map(d => ({
Title: main.Title,
DateBeginn: d.DateBeginn,
DateEnd: d.DateEnd,
Where: d.Where,
}))).flat()
console.log(calendarData)
The output of this code snippet looks like this:
[
{
"Title": "Go Shopping",
"DateBeginn": "19.02.2021",
"DateEnd": "22.02.2021",
"Where": "Supermarket"
},
{
"Title": "Go Shopping",
"DateBeginn": "23.02.2021",
"DateEnd": "23.02.2021",
"Where": "Biomarket"
}
]
Now, my goal is to expand this data into a detailed schedule:
[
{
"Title": "Go Shopping",
"DateBeginn": "19.02.2021",
"DateEnd": "22.02.2021",
"Where": "Supermarket"
},
{
"Title": "Go Shopping",
"DateBeginn": "20.02.2021",
"DateEnd": "22.02.2021",
"Where": "Supermarket"
},
{
"Title": "Go Shopping",
"DateBeginn": "21.02.2021",
"DateEnd": "22.02.2021",
"Where": "Supermarket"
},
{
"Title": "Go Shopping",
"DateBeginn": "22.02.2021",
"DateEnd": "22.02.2021",
"Where": "Supermarket"
},
{
"Title": "Go Shopping",
"DateBeginn": "23.02.2021",
"DateEnd": "23.02.2021",
"Where": "Biomarket"
}
]
To achieve this, I would like to iterate through the dates range and create multiple entities for each date if the difference between start and end dates is more than 1 day.