I have tickets object and each ticket has its own date:
tickets: [
{
id: 0,
time: "09:45",
date: new Date("2021-01-01"),
name: "Swimming in the hillside pond",
},
{
id: 1,
time: "09:45",
date: new Date("2021-01-08"),
name: "Swimming in the hillside pond",
},
],
So what I am trying to do is to find the number of the week of each ticket, but also if the week number is different than the current ones. For example, if the ticket date is 01.01 2021
, the number of the week should be 1 and if it is 08.01.2021
, it should be 2. So if I have 3 tickets and if the dates for these tickets are [01.01.2021, 08.01.2021, 09.01.2021], I want to have an array like [1,2].
For this, I created function:
currentNumberOfWeek(tickets) {
return tickets.find((ticket, result) => {
const oneJan = new Date(ticket.date.getFullYear(), 0, 1);
const numberOfDays = Math.floor((ticket.date - oneJan) / (24 * 60 * 60 * 1000));
result = Math.ceil((ticket.date.getDay() + 1 + numberOfDays) / 7);
console.log(result);
return result;
});
},
But first, it returns the ticket not the result and also, in console it doesn't show the right number of the week.
Could you please have a look? Thanks...