mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 23:25:24 +00:00
feat: unify alerts into one plugin, channels, rules and inbox
This commit is contained in:
1 parent
fbe736bc20
commit
7c02daccf4
129 files changed
+20957
-2687
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { ANNOUNCEMENT_SOURCE } from "../types";
|
||||
|
||||
export function timeAgo(iso: string, language: string): string {
|
||||
// SQLite's CURRENT_TIMESTAMP has no zone; it is UTC.
|
||||
const normalized = /[zZ]|[+-]\d\d:?\d\d$/.test(iso)
|
||||
? iso
|
||||
: `${iso.replace(" ", "T")}Z`;
|
||||
const ms = Date.parse(normalized);
|
||||
if (!Number.isFinite(ms)) return "";
|
||||
const seconds = Math.round((ms - Date.now()) / 1000);
|
||||
const format = new Intl.RelativeTimeFormat(language || "en", {
|
||||
numeric: "auto",
|
||||
});
|
||||
const abs = Math.abs(seconds);
|
||||
if (abs < 60) return format.format(seconds, "second");
|
||||
if (abs < 3600) return format.format(Math.round(seconds / 60), "minute");
|
||||
if (abs < 86400) return format.format(Math.round(seconds / 3600), "hour");
|
||||
return format.format(Math.round(seconds / 86400), "day");
|
||||
}
|
||||
|
||||
export function sourceLabel(
|
||||
source: string,
|
||||
t: (key: string, options?: Record<string, unknown>) => string,
|
||||
): string {
|
||||
if (source === ANNOUNCEMENT_SOURCE) return t("inbox.sourceTermix");
|
||||
return source
|
||||
.split("-")
|
||||
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
||||
.join(" ");
|
||||
}
|
||||
Reference in new issue
Block a user