ghost-dao-interface/src/helpers/timeUtil.js
Uncle Fatso d4446f6fb1
version 0.0.22
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2025-04-28 14:03:56 +03:00

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;
}