37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import { useQuery } from "@tanstack/react-query";
|
|
|
|
export function prettifySecondsInDays(seconds) {
|
|
let prettifiedSeconds = "";
|
|
if (seconds > 86400) {
|
|
prettifiedSeconds = prettifySeconds(seconds, "day");
|
|
} else {
|
|
prettifiedSeconds = prettifySeconds(seconds);
|
|
}
|
|
return prettifiedSeconds === "" ? "now" : prettifiedSeconds;
|
|
}
|
|
|
|
export function prettifySeconds(seconds, resolution) {
|
|
if (seconds !== 0 && !seconds) {
|
|
return "";
|
|
}
|
|
|
|
const d = Math.floor(seconds / (3600 * 24));
|
|
const h = Math.floor((seconds % (3600 * 24)) / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
|
|
if (resolution === "day") {
|
|
return d + (d == 1 ? " day" : " days");
|
|
}
|
|
|
|
const dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
|
|
const hDisplay = h > 0 ? h + (h == 1 ? " hr, " : " hrs, ") : "";
|
|
const mDisplay = m > 0 ? m + (m == 1 ? " min" : " mins") : "";
|
|
|
|
let result = dDisplay + hDisplay + mDisplay;
|
|
if (mDisplay === "") {
|
|
result = result.slice(0, result.length - 2);
|
|
}
|
|
|
|
return result;
|
|
}
|