Within my web service, there is an API that provides information on the days when a shop is available for delivery. The API returns an object containing an ID (which is necessary to obtain hours based on the selected day) and the abbreviated day name (in Italian).
Prior to integrating the API, I had been utilizing the following function to generate an array of days, with 'Today' tagged onto the current day.
times(maxDays: number, days: ShopDays[]): void {
const options = { weekday: 'short', day: 'numeric', month: 'short' };
const today = new Date();
this.days.push({ // including today in the days array
formatted: 'Oggi, ' + today.toLocaleString('it-IT', options),
time: today.toLocaleDateString(),
});
for (let i = 0; i < maxDays; i++) { // adding other days based on the maximum days per week variable 'maxDays'
today.setDate(today.getDate() + 1);
this.days.push({
formatted: today.toLocaleDateString('it-IT', options),
time: today.toLocaleDateString(),
});
}
}
Now that I have access to the API which provides the available days of the week in days.day
, I am interested in generating a similar array using the available days from the days
array...
This is what the ShopDays[]
looks like:
[{id: 1, day: "TUE"}, {id: 2, day: "WED"}, {id: 3, day: "THU"}, {id: 4, day: "FRI"}]
Based on the data returned by the function times(), the resulting array should look something like this:
Today, Wed 23 Sep - Thu 24 Sep - Fri 25 Sep - Tue 29 Sep
If Today is not included, simply display the following days in the array..