Page MenuHomeSealhub

time-units.ts
No OneTemporary

time-units.ts

export type TimeUnit = "h" | "m" | "s" | "ms";
const formats: { [unit in TimeUnit]: number } = {
h: 3600000,
m: 60000,
s: 1000,
ms: 1,
};
export default function time_units(
from: TimeUnit,
to: TimeUnit,
amount: number
) {
if (!formats[from] || !formats[to]) {
throw new Error("Please provide a valid time format");
}
if (!amount || typeof amount.valueOf() !== "number") {
throw new Error("Please provide a valid amount to convert");
}
return (formats[from] / formats[to]).toPrecision(8);
}

File Metadata

Mime Type
text/plain
Expires
Wed, May 7, 19:37 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
624890
Default Alt Text
time-units.ts (510 B)

Event Timeline