Fix tests

Signed-off-by: yubiuser <github@yubiuser.dev>
This commit is contained in:
yubiuser
2025-11-09 14:36:27 +01:00
committed by Adam Warner
parent f34135b47f
commit ee3a2f47c2
4 changed files with 109 additions and 68 deletions

View File

@@ -377,13 +377,24 @@ function updateSystemInfo() {
$("#status").prop(
"title",
"System uptime: " +
luxon.Duration.fromMillis(1000 * system.uptime).toHuman({smallestUnit: "seconds", maxUnits: 2, stripZeroUnits: "all"}) +
luxon.Duration.fromMillis(1000 * system.uptime).toHuman({
smallestUnit: "seconds",
maxUnits: 2,
stripZeroUnits: "all",
}) +
" (running since " +
startdate +
")"
);
$("#sysinfo-uptime").text(
luxon.Duration.fromMillis(1000 * system.uptime).toHuman({smallestUnit: "seconds", maxUnits: 2, stripZeroUnits: "all"}) + " (running since " + startdate + ")"
luxon.Duration.fromMillis(1000 * system.uptime).toHuman({
smallestUnit: "seconds",
maxUnits: 2,
stripZeroUnits: "all",
}) +
" (running since " +
startdate +
")"
);
$("#sysinfo-system-overlay").hide();

View File

@@ -106,14 +106,20 @@ function initDateRangePicker() {
luxon.DateTime.now().minus({ days: 1 }).endOf("day"),
],
"Last 7 Days": [luxon.DateTime.now().minus({ days: 6 }), luxon.DateTime.now().endOf("day")],
"Last 30 Days": [luxon.DateTime.now().minus({ days: 29 }), luxon.DateTime.now().endOf("day")],
"Last 30 Days": [
luxon.DateTime.now().minus({ days: 29 }),
luxon.DateTime.now().endOf("day"),
],
"This Month": [luxon.DateTime.now().startOf("month"), luxon.DateTime.now().endOf("month")],
"Last Month": [
luxon.DateTime.now().minus({ months: 1 }).startOf("month"),
luxon.DateTime.now().minus({ months: 1 }).endOf("month"),
],
"This Year": [luxon.DateTime.now().startOf("year"), luxon.DateTime.now().endOf("year")],
"All Time": [luxon.DateTime.fromMillis(beginningOfTime * 1000), luxon.DateTime.fromMillis(endOfTime * 1000)], // convert to milliseconds since epoch
"All Time": [
luxon.DateTime.fromMillis(beginningOfTime * 1000),
luxon.DateTime.fromMillis(endOfTime * 1000),
], // convert to milliseconds since epoch
},
// Don't allow selecting dates outside the database range
minDate: minDateMoment,
@@ -389,7 +395,11 @@ function formatInfo(data) {
ttlInfo =
divStart +
"Time-to-live (TTL):&nbsp;&nbsp;" +
luxon.Duration.fromObject({ seconds: data.ttl }).toHuman({smallestUnit: "seconds", maxUnits: 2, stripZeroUnits: "all"}) +
luxon.Duration.fromObject({ seconds: data.ttl }).toHuman({
smallestUnit: "seconds",
maxUnits: 2,
stripZeroUnits: "all",
}) +
" (" +
data.ttl +
"s)</div>";
@@ -603,7 +613,9 @@ $(() => {
width: "10%",
render(data, type) {
if (type === "display") {
return luxon.DateTime.fromMillis(data * 1000).toFormat("yyyy-MM-dd [<br class='hidden-lg'>]HH:mm:ss z");
return luxon.DateTime.fromMillis(data * 1000).toFormat(
"yyyy-MM-dd [<br class='hidden-lg'>]HH:mm:ss z"
);
}
return data;

View File

@@ -179,7 +179,9 @@ function getData() {
// Create and add new log entry to fragment
const logEntry = document.createElement("div");
const logEntryDate = luxon.DateTime.fromMillis(1000 * line.timestamp).toFormat("yyyy-MM-dd HH:mm:ss.SSS");
const logEntryDate = luxon.DateTime.fromMillis(1000 * line.timestamp).toFormat(
"yyyy-MM-dd HH:mm:ss.SSS"
);
logEntry.className = `log-entry${fadeIn ? " hidden-entry" : ""}`;
logEntry.innerHTML = `<span class="text-muted">${logEntryDate}</span> ${line.message}`;

View File

@@ -156,7 +156,15 @@ function datetime(date, html, humanReadable) {
html === false ? "Y-MM-DD HH:mm:ss z" : "Y-MM-DD [<br class='hidden-lg'>]HH:mm:ss z";
const timestr = luxon.DateTime.fromMillis(Math.floor(date)).toFormat(format).trim();
return humanReadable
? '<span title="' + timestr + '">' + luxon.DateTime.fromMillis(Math.floor(date)).toHuman({smallestUnit: "seconds", maxUnits: 2, stripZeroUnits: "all"}) + "</span>"
? '<span title="' +
timestr +
'">' +
luxon.DateTime.fromMillis(Math.floor(date)).toHuman({
smallestUnit: "seconds",
maxUnits: 2,
stripZeroUnits: "all",
}) +
"</span>"
: timestr;
}
@@ -671,69 +679,77 @@ function toggleBoxCollapse(box, expand = true) {
// This is a wrapper that extends the Duration prototype
const Duration = luxon.Duration;
Duration.prototype.__toHuman__ = Duration.prototype.toHuman;
Duration.prototype.toHuman = function(opts = {}) {
let duration = this.normalize();
let durationUnits = [];
let precision;
if (typeof opts.precision == "object") {
precision = Duration.fromObject(opts.precision);
}
let remainingDuration = duration;
//list of all available units
const allUnits = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
let smallestUnitIndex;
let biggestUnitIndex;
// check if user has specified a smallest unit that should be displayed
if (opts.smallestUnit) {
smallestUnitIndex = allUnits.indexOf(opts.smallestUnit);
}
// check if user has specified a biggest unit
if (opts.biggestUnit) {
biggestUnitIndex = allUnits.indexOf(opts.biggestUnit);
}
// use seconds and years as default for smallest and biggest unit
if (!((smallestUnitIndex >= 0) && (smallestUnitIndex < allUnits.length))) smallestUnitIndex = allUnits.indexOf("seconds");
if (!((biggestUnitIndex <= smallestUnitIndex) && (biggestUnitIndex < allUnits.length))) biggestUnitIndex = allUnits.indexOf("years");
Duration.prototype.toHuman = function (opts = {}) {
let duration = this.normalize();
let durationUnits = [];
let precision;
if (typeof opts.precision === "object") {
precision = Duration.fromObject(opts.precision);
}
for (let unit of allUnits.slice(biggestUnitIndex, smallestUnitIndex + 1)) {
const durationInUnit = remainingDuration.as(unit);
if (durationInUnit >= 1) {
durationUnits.push(unit);
let tmp = {};
tmp[unit] = Math.floor(remainingDuration.as(unit));
remainingDuration = remainingDuration.minus(Duration.fromObject(tmp)).normalize();
let remainingDuration = duration;
//list of all available units
const allUnits = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
let smallestUnitIndex;
let biggestUnitIndex;
// check if user has specified a smallest unit that should be displayed
if (opts.smallestUnit) {
smallestUnitIndex = allUnits.indexOf(opts.smallestUnit);
}
// check if remaining duration is smaller than precision
if (remainingDuration < precision) {
// ok, we're allowed to remove the remaining parts and to round the current unit
break;
}
}
// check if user has specified a biggest unit
if (opts.biggestUnit) {
biggestUnitIndex = allUnits.indexOf(opts.biggestUnit);
}
// check if we have already the maximum count of units allowed
if (durationUnits.length >= opts.maxUnits) {
break;
}
}
// after gathering of units that shall be displayed has finished, remove the remaining duration to avoid non-integers
duration = duration.minus(remainingDuration).normalize();
duration = duration.shiftTo(...durationUnits);
if (opts.stripZeroUnits == "all") {
durationUnits = durationUnits.filter(unit => duration.values[unit] > 0);
} else if (opts.stripZeroUnits == "end") {
let mayStrip = true;
durationUnits = durationUnits.reverse().filter((unit, index) => {
if (!mayStrip) return true;
if (duration.values[unit] == 0) {
return false;
} else {
mayStrip = false;
}
return true;
});
}
return duration.shiftTo(...durationUnits).__toHuman__(opts);
}
// use seconds and years as default for smallest and biggest unit
if (!(smallestUnitIndex >= 0 && smallestUnitIndex < allUnits.length))
smallestUnitIndex = allUnits.indexOf("seconds");
if (!(biggestUnitIndex <= smallestUnitIndex && biggestUnitIndex < allUnits.length))
biggestUnitIndex = allUnits.indexOf("years");
for (const unit of allUnits.slice(biggestUnitIndex, smallestUnitIndex + 1)) {
const durationInUnit = remainingDuration.as(unit);
if (durationInUnit >= 1) {
durationUnits.push(unit);
const tmp = {};
tmp[unit] = Math.floor(remainingDuration.as(unit));
remainingDuration = remainingDuration.minus(Duration.fromObject(tmp)).normalize();
// check if remaining duration is smaller than precision
if (remainingDuration < precision) {
// ok, we're allowed to remove the remaining parts and to round the current unit
break;
}
}
// check if we have already the maximum count of units allowed
if (durationUnits.length >= opts.maxUnits) {
break;
}
}
// after gathering of units that shall be displayed has finished, remove the remaining duration to avoid non-integers
duration = duration.minus(remainingDuration).normalize();
duration = duration.shiftTo(...durationUnits);
if (opts.stripZeroUnits === "all") {
durationUnits = durationUnits.filter(unit => duration.values[unit] > 0);
} else if (opts.stripZeroUnits === "end") {
let mayStrip = true;
durationUnits = durationUnits.reverse().filter((unit, _index) => {
if (!mayStrip) return true;
if (duration.values[unit] === 0) {
return false;
}
mayStrip = false;
return true;
});
}
return duration.shiftTo(...durationUnits).__toHuman__(opts);
};
globalThis.utils = (function () {
return {