Thanks to everyone who tried to help me. I already got the answer, pls check it out in case you need this function too :)
I created a new function for the time:
const wasItemPurchasedWithinLastOneDay = (lastPurchasedOn) => {
const oneDayInMilliseconds = 24 * 60 * 60 * 1000;
return (Date.now() - lastPurchasedOn) <= oneDayInMilliseconds;
}
I used Date.now() in the if/else statement, to set the value of the actual date the item was purchased:
const markItemAsPurchased = (index) => {
const { items, documentId } = shoppingList[0];
const shoppingListObject = items[index];
if (shoppingListObject.lastPurchasedOn === null) {
shoppingListObject.lastPurchasedOn = Date.now();
} else {
shoppingListObject.lastPurchasedOn = null;
}
I changed the function on checked as followed:
checked={
shoppingItemObject.lastPurchasedOn === null
? false : wasItemPurchasedWithinLastOneDay(shoppingItemObject.lastPurchasedOn) }
It now checks if the date of the last value is more than 24 hours and unchecks the checkbox if it is.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…