I'm trying to calculate the dates of the current and the previous 6 days. This should work by simply subtracting 1 from the previous date, so I implemented my current solution like this:
let currentDay = new Date();
let nextDay = new Date();
for (let i = 0; i < 7; i++) {
nextDay.setDate(currentDay.getDate() - i);
console.log("i=" + i + "->" + nextDay);
}
However, this is the output:
i = 0 -> Thu Dec 03 2020 10: 20: 51 GMT + 0100(Central European Standard Time) //today
i = 1 -> Wed Dec 02 2020 10: 20: 51 GMT + 0100(Central European Standard Time) //yesterday
i = 2 -> Tue Dec 01 2020 10: 20: 51 GMT + 0100(Central European Standard Time) //day before yesterday
i = 3 -> Mon Nov 30 2020 10: 20: 51 GMT + 0100(Central European Standard Time) //3 days ago
i = 4 -> Fri Oct 30 2020 10: 20: 51 GMT + 0100(Central European Standard Time) //skips an entire month
i = 5 -> Mon Sep 28 2020 10: 20: 51 GMT + 0200(Central European Summer Time) //skips another month, 2 days and switches to summertime
i = 6 -> Fri Aug 28 2020 10: 20: 51 GMT + 0200(Central European Summer Time) //skips another month
It worked as expected when running during the end of last month (where the current month was not escaped). It fails as it enters November. I can't seem to find the cause.