mirror of
https://github.com/arthur-pbty/New-discord-bot-coins.git
synced 2026-06-14 15:55:12 +02:00
20 lines
701 B
JavaScript
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;
|
|
}; |