I am trying to find the number of the week. So for this my function is:
getWeekNumber(date) {
const temp_date = new Date(date.valueOf());
const dayn = (date.getDay() + 6) % 7;
temp_date.setDate(temp_date.getDate() - dayn + 3);
const firstThursday = temp_date.valueOf();
temp_date.setMonth(0, 1);
if (temp_date.getDay() !== 4) {
temp_date.setMonth(0, 1 + ((4 - temp_date.getDay() + 7) % 7));
}
return 1 + Math.ceil((firstThursday - temp_date) / 604800000);
},
And I am using this function in my other function to find the products:
findProducts(products, date) {
return products.filter((product) => {
const formated_date = this.setDateFormat(product.attributes.date);
console.log(formated_date);
console.log(formated_date.valueOf());
return (
formated_date.getDate() === date.getDate() &&
formated_date.getMonth() === date.getMonth() &&
formated_date.getFullYear() === date.getFullYear() &&
this.getWeekNumber(formated_date) === this.currentWeekNumber
);
});
},
But my problem is inside of the findProducts function in console I can see the output like this: Tue Sep 28 2021 02:00:00 GMT+0200 (Central European Summer Time) Table.vue:144 1632787200000
But whenever it goes to getWeekNumber function I am getting this error: vue.esm.js:1897 TypeError: Cannot read properties of undefined (reading 'valueOf')
Do you have any idea why it can be?
Thanks...