Page MenuHomeSealhub

time-units.ts
No OneTemporary

Authored By
Unknown
Size
510 B
Referenced Files
None
Subscribers
None

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
application/javascript
Expires
Sat, Nov 7, 14:53 (19 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1181836
Default Alt Text
time-units.ts (510 B)

Event Timeline