diff --git a/components/Message.vue b/components/Message.vue index c699109..b6b38cc 100644 --- a/components/Message.vue +++ b/components/Message.vue @@ -10,6 +10,8 @@ {{ username }} + Yesterday at + {{ date.toLocaleDateString(undefined) }}, {{ date.toLocaleTimeString(undefined, { timeStyle: "short" }) }} @@ -49,6 +51,7 @@ const messageElement = ref(); const dateHidden = ref(true); const date = new Date(props.timestamp); +const currentDate: Date = new Date() console.log("message:", props.text); console.log("author:", props.username); @@ -74,6 +77,20 @@ onMounted(async () => { // showHover.value = !showHover.value; //} +function getDayDifference(date_1: Date, date_2: Date) { +// Normalize both dates to midnight + const midnight1 = new Date(date_1.getFullYear(), date_1.getMonth(), date_1.getDate()); + const midnight2 = new Date(date_2.getFullYear(), date_2.getMonth(), date_2.getDate()); + + // Calculate the difference in time + const timeDifference = midnight2.getTime() - midnight1.getTime(); + + // Convert time difference from milliseconds to days + const dayDifference = timeDifference / (1000 * 60 * 60 * 24); + + return Math.round(dayDifference); // Round to the nearest whole number +} +