Files
2024-06-25 13:45:14 +02:00

20 lines
701 B
JavaScript

module.exports = function formatDate(timestamp) {
const currentDate = new Date();
const targetDate = new Date(timestamp);
const diffTime = Math.abs(targetDate - currentDate);
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
const diffHours = Math.floor((diffTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const diffMinutes = Math.floor((diffTime % (1000 * 60 * 60)) / (1000 * 60));
let result = "";
if (diffDays > 0) {
result += `${diffDays} jour${diffDays > 1 ? "s" : ""}, `;
}
if (diffHours > 0) {
result += `${diffHours} heure${diffHours > 1 ? "s" : ""} et `;
}
result += `${diffMinutes} minute${diffMinutes > 1 ? "s" : ""}`;
return result;
};