I store certain dates of events in an array, of up to 7 elements, where the first element gets deleted if an 8th element needs to be added.
I format them as such: 9th Jan 2021
.
I've been struggling with finding a solution to this problem:
If an event hasn't been added in the previous day, I need to add this event anyway.
Example: if a user sets an event on the 9th Jan 2021
, and the most recent has been on the 30th Dec 2020
, I need to add the most recent 7
days to the array, as the gap is over a week. If the gap isn't over a week, I just need to add whatever dates are in between, e.g. 9th Jan 2021
and 5th Jan 2021
.
At an event update on 12th Jan 2021
such that the array = ["29th Dec 2020", "30th Dec 2020", ... , "4th Jan 2021"]
, the array needs to be set to []
, then set to: ["6th Jan 2021", ... , "12th Jan 2021"]
.
I have tried writing very long algorithms for this, but just keep running into so many errors that I figured there has to be an easier way to do this.
I'd appreciate any help.
Thank you.