#Date duration calculator broken
1 messages · Page 1 of 1 (latest)
export function getTimeRemainingString(endDate) {
if (endDate == null) return "Permanent";
const now = new Date();
endDate = new Date(endDate);
let years = endDate.getFullYear() - now.getFullYear();
let months = endDate.getMonth() - now.getMonth();
let days = endDate.getDate() - now.getDate();
let hours = endDate.getHours() - now.getHours();
let minutes = endDate.getMinutes() - now.getMinutes();
if (minutes < 0) {
minutes += 60;
hours -= 1;
}
if (hours < 0) {
hours += 24;
days -= 1;
}
if (days < 0) {
const prevMonth = new Date(endDate.getFullYear(), endDate.getMonth(), 0);
days += prevMonth.getDate();
months -= 1;
}
if (months < 0) {
months += 12;
years -= 1;
}
const timeComponents = [
years ? `${years}y` : "",
months ? `${months}mo` : "",
days ? `${days}d` : "",
hours ? `${hours}h` : "",
minutes ? `${minutes}m` : ""
].filter(Boolean);
return timeComponents.join(", ") || "Mute expired";
}
i did a ban test for 10 mins and for some reason the duration is showing as -1y, 11mo, 29d, 23h, 46m
Hmm is that a server or a world
world