mirror of
https://github.com/UiO-Gaming/mustaboard.git
synced 2026-11-05 13:56:52 +01:00
use built in relative time formatter
This commit is contained in:
1 file changed
+8
-3
@@ -219,15 +219,20 @@ const getTimeDifference = (timeDiff: number): string => {
|
||||
const msInHour = 1000 * 60 * 60;
|
||||
const msInDay = msInHour * 24;
|
||||
|
||||
const rtf = new Intl.RelativeTimeFormat("en-US", {
|
||||
numeric: "always", // "auto" will show "tomorrow" if day = 1
|
||||
style: "long",
|
||||
});
|
||||
|
||||
if (timeDiff < msInHour) {
|
||||
const minutesLeft = Math.floor(timeDiff / (1000 * 60));
|
||||
return `in ${minutesLeft} minutes`;
|
||||
return rtf.format(minutesLeft, "minute")
|
||||
} else if (timeDiff < msInDay) {
|
||||
const hoursLeft = Math.floor(timeDiff / msInHour);
|
||||
return `in ${hoursLeft} hours`;
|
||||
return rtf.format(hoursLeft, "hour")
|
||||
} else {
|
||||
const daysLeft = Math.floor(timeDiff / msInDay);
|
||||
return `in ${daysLeft} days`;
|
||||
return rtf.format(daysLeft, "day")
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user