0

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.

Matt
  • 105
  • 7
  • Firstly do NOT calculate on the format you display. Please show the code you tried if it is not like the dupe. Click edit, then `[<>]` snippet editor and provide a [mcve] – mplungjan Jan 09 '21 at 19:22
  • It is not clear what you mean by setting the array to [] and then something else. Please give input and exact expected output. Sounds to me you can just make an array of 14 days and then slice it to fit – mplungjan Jan 09 '21 at 19:24

0 Answers0