mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-28 15:28:04 +00:00
Rename frontend directory (#472)
* Rename directory * Cleanup * Recover lost images * remove lint
This commit is contained in:
29
frontend/src/timeUtils.ts
Normal file
29
frontend/src/timeUtils.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { DateTime, type DurationLikeObject } from "luxon";
|
||||
import { ReleaseRevision } from "./data/types";
|
||||
|
||||
export function getAge(obj1: ReleaseRevision, obj2?: ReleaseRevision) {
|
||||
const date = DateTime.fromISO(obj1.updated);
|
||||
let dateNext = DateTime.now();
|
||||
if (obj2) {
|
||||
dateNext = DateTime.fromISO(obj2.updated);
|
||||
}
|
||||
const diff = dateNext.diff(date);
|
||||
|
||||
const map: Record<string, string> = {
|
||||
years: "yr",
|
||||
months: "mo",
|
||||
days: "d",
|
||||
hours: "h",
|
||||
minutes: "m",
|
||||
seconds: "s",
|
||||
milliseconds: "ms",
|
||||
};
|
||||
|
||||
for (const unit of Object.keys(map)) {
|
||||
const val = diff.as(unit as keyof DurationLikeObject);
|
||||
if (val >= 1) {
|
||||
return Math.round(val) + map[unit];
|
||||
}
|
||||
}
|
||||
return "n/a";
|
||||
}
|
||||
Reference in New Issue
Block a user