mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
small fix, don't worry about it
This commit is contained in:
1 parent
08bd0c6e5c
commit
08cb5754f3
638 files changed
+57330
-34704
No files matched your search
@@ -0,0 +1,47 @@
|
||||
export function formatRelative(iso?: string): string {
|
||||
if (!iso) {
|
||||
return 'n/a';
|
||||
}
|
||||
|
||||
const timestamp = Date.parse(iso);
|
||||
if (Number.isNaN(timestamp)) {
|
||||
return 'n/a';
|
||||
}
|
||||
|
||||
const diffMs = Date.now() - timestamp;
|
||||
const minute = 60_000;
|
||||
const hour = 60 * minute;
|
||||
const day = 24 * hour;
|
||||
|
||||
if (diffMs < minute) {
|
||||
return 'just now';
|
||||
}
|
||||
if (diffMs < hour) {
|
||||
return `${Math.floor(diffMs / minute)}m ago`;
|
||||
}
|
||||
if (diffMs < day) {
|
||||
return `${Math.floor(diffMs / hour)}h ago`;
|
||||
}
|
||||
return `${Math.floor(diffMs / day)}d ago`;
|
||||
}
|
||||
|
||||
export function formatDate(iso?: string): string {
|
||||
if (!iso) {
|
||||
return 'n/a';
|
||||
}
|
||||
const dt = new Date(iso);
|
||||
if (Number.isNaN(dt.getTime())) {
|
||||
return 'n/a';
|
||||
}
|
||||
return dt.toLocaleString();
|
||||
}
|
||||
|
||||
export function seededMetric(seed: string, min: number, max: number): number {
|
||||
let hash = 0;
|
||||
for (let idx = 0; idx < seed.length; idx += 1) {
|
||||
hash = (hash * 31 + seed.charCodeAt(idx)) & 0xffffffff;
|
||||
}
|
||||
|
||||
const ratio = Math.abs(hash) % 10_000 / 10_000;
|
||||
return Math.round(min + (max - min) * ratio);
|
||||
}
|
||||
Reference in new issue
Block a user