Enhancement: use duration for audiobookshelf tottal, refactor uptime (#4229)
Some checks are pending
Docker / Linting Checks (push) Waiting to run
Docker / Docker Build & Push (push) Blocked by required conditions

This commit is contained in:
shamoon
2024-10-31 22:09:23 -07:00
committed by GitHub
parent 3736c1fcab
commit e6cf86ed4a
11 changed files with 20 additions and 23 deletions

View File

@@ -84,12 +84,12 @@ function prettyBytes(number, options) {
return `${prefix + numberString} ${unit}`;
}
function uptime(uptimeInSeconds, i18next) {
const mo = Math.floor(uptimeInSeconds / (3600 * 24 * 31));
const d = Math.floor((uptimeInSeconds % (3600 * 24 * 31)) / (3600 * 24));
const h = Math.floor((uptimeInSeconds % (3600 * 24)) / 3600);
const m = Math.floor((uptimeInSeconds % 3600) / 60);
const s = Math.floor(uptimeInSeconds % 60);
function duration(durationInSeconds, i18next) {
const mo = Math.floor(durationInSeconds / (3600 * 24 * 31));
const d = Math.floor((durationInSeconds % (3600 * 24 * 31)) / (3600 * 24));
const h = Math.floor((durationInSeconds % (3600 * 24)) / 3600);
const m = Math.floor((durationInSeconds % 3600) / 60);
const s = Math.floor(durationInSeconds % 60);
const moDisplay = mo > 0 ? mo + i18next.t("common.months") : "";
const dDisplay = d > 0 ? d + i18next.t("common.days") : "";
@@ -156,7 +156,7 @@ module.exports = {
i18next.services.formatter.add("relativeDate", (value, lng, options) =>
relativeDate(new Date(value), new Intl.RelativeTimeFormat(lng, { ...options })),
);
i18next.services.formatter.add("uptime", (value, lng) => uptime(value, i18next));
i18next.services.formatter.add("duration", (value, lng) => duration(value, i18next));
},
type: "3rdParty",
},