From 2b5df96028208c8e1ba85f8cebc0f2b3736008e4 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Sun, 9 Nov 2025 13:00:41 +0100 Subject: [PATCH] Change js from moment to luxon style Signed-off-by: yubiuser --- scripts/js/footer.js | 18 +++++----- scripts/js/queries.js | 52 ++++++++++++++--------------- scripts/js/taillog.js | 4 +-- scripts/js/utils.js | 8 ++--- scripts/lua/header_authenticated.lp | 4 +-- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/scripts/js/footer.js b/scripts/js/footer.js index a26b2740..49ccc1a6 100644 --- a/scripts/js/footer.js +++ b/scripts/js/footer.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global utils:false, moment:false */ +/* global utils:false, luxon:false */ "use strict"; @@ -262,9 +262,9 @@ function updateFtlInfo() { ); updateQueryFrequency(intl, ftl.query_frequency); $("#sysinfo-pid-ftl").text(ftl.pid); - const startdate = moment() - .subtract(ftl.uptime, "milliseconds") - .format("dddd, MMMM Do YYYY, HH:mm:ss"); + const startdate = luxon.DateTime.now() + .minus({ milliseconds: ftl.uptime }) + .toFormat("dddd, MMMM Do YYYY, HH:mm:ss"); $("#sysinfo-uptime-ftl").text(startdate); $(".destructive_action").prop("disabled", !ftl.allow_destructive); @@ -371,19 +371,19 @@ function updateSystemInfo() { $("#sysinfo-cpu-ftl").text("(" + system.ftl["%cpu"].toFixed(1) + "% used by FTL)"); $("#sysinfo-ram-ftl").text("(" + system.ftl["%mem"].toFixed(1) + "% used by FTL)"); - const startdate = moment() - .subtract(system.uptime, "seconds") - .format("dddd, MMMM Do YYYY, HH:mm:ss"); + const startdate = luxon.DateTime.now() + .minus({ seconds: system.uptime }) + .toFormat("dddd, MMMM Do YYYY, HH:mm:ss"); $("#status").prop( "title", "System uptime: " + - moment.duration(1000 * system.uptime).humanize() + + luxon.Duration.fromMillis(1000 * system.uptime).toRelative() + " (running since " + startdate + ")" ); $("#sysinfo-uptime").text( - moment.duration(1000 * system.uptime).humanize() + " (running since " + startdate + ")" + luxon.Duration.fromMillis(1000 * system.uptime).toRelative() + " (running since " + startdate + ")" ); $("#sysinfo-system-overlay").hide(); diff --git a/scripts/js/queries.js b/scripts/js/queries.js index b16acbfb..e2997db4 100644 --- a/scripts/js/queries.js +++ b/scripts/js/queries.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false, utils:false, REFRESH_INTERVAL:false */ +/* global luxon:false, utils:false, REFRESH_INTERVAL:false */ "use strict"; @@ -95,25 +95,25 @@ function initDateRangePicker() { timePickerIncrement: 5, timePicker24Hour: true, locale: { format: dateformat }, - startDate: moment(from * 1000), // convert to milliseconds since epoch - endDate: moment(until * 1000), // convert to milliseconds since epoch + startDate: luxon.DateTime.fromMillis(from * 1000), // convert to milliseconds since epoch + endDate: luxon.DateTime.fromMillis(until * 1000), // convert to milliseconds since epoch ranges: { - "Last 10 Minutes": [moment().subtract(10, "minutes"), moment()], - "Last Hour": [moment().subtract(1, "hours"), moment()], - Today: [moment().startOf("day"), maxDateMoment], + "Last 10 Minutes": [luxon.DateTime.now().minus({ minutes: 10 }), luxon.DateTime.now()], + "Last Hour": [luxon.DateTime.now().minus({ hours: 1 }), luxon.DateTime.now()], + Today: [luxon.DateTime.now().startOf("day"), luxon.DateTime.now().endOf("day")], Yesterday: [ - moment().subtract(1, "days").startOf("day"), - moment().subtract(1, "days").endOf("day"), + luxon.DateTime.now().minus({ days: 1 }).startOf("day"), + luxon.DateTime.now().minus({ days: 1 }).endOf("day"), ], - "Last 7 Days": [moment().subtract(6, "days").startOf("day"), maxDateMoment], - "Last 30 Days": [moment().subtract(29, "days").startOf("day"), maxDateMoment], - "This Month": [moment().startOf("month"), maxDateMoment], + "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")], + "This Month": [luxon.DateTime.now().startOf("month"), luxon.DateTime.now().endOf("month")], "Last Month": [ - moment().subtract(1, "month").startOf("month"), - moment().subtract(1, "month").endOf("month"), + luxon.DateTime.now().minus({ months: 1 }).startOf("month"), + luxon.DateTime.now().minus({ months: 1 }).endOf("month"), ], - "This Year": [moment().startOf("year"), maxDateMoment], - "All Time": [minDateMoment, maxDateMoment], + "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 }, // Don't allow selecting dates outside the database range minDate: minDateMoment, @@ -125,8 +125,8 @@ function initDateRangePicker() { (startt, endt) => { // Update global variables // Convert milliseconds (JS) to seconds (API) - from = moment(startt).utc().valueOf() / 1000; - until = moment(endt).utc().valueOf() / 1000; + from = luxon.DateTime.fromMillis(startt).utc().valueOf() / 1000; + until = luxon.DateTime.fromMillis(endt).utc().valueOf() / 1000; } ); } @@ -389,7 +389,7 @@ function formatInfo(data) { ttlInfo = divStart + "Time-to-live (TTL):  " + - moment.duration(data.ttl, "s").humanize() + + luxon.Duration.fromObject({ seconds: data.ttl }).toRelative() + " (" + data.ttl + "s)"; @@ -443,7 +443,7 @@ function formatInfo(data) { '
' + divStart + "Query received on:  " + - moment.unix(data.time).format("Y-MM-DD HH:mm:ss.SSS z") + + luxon.DateTime.fromMillis(data.time * 1000).toFormat("yyyy-MM-dd HH:mm:ss.SSS z") + "
" + clientInfo + dnssecInfo + @@ -603,7 +603,7 @@ $(() => { width: "10%", render(data, type) { if (type === "display") { - return moment.unix(data).format("Y-MM-DD []HH:mm:ss z"); + return luxon.DateTime.fromMillis(data * 1000).toFormat("yyyy-MM-dd []HH:mm:ss z"); } return data; @@ -638,12 +638,12 @@ $(() => { if (querystatus.icon !== false) { $("td:eq(1)", row).html( "" + querystatus.icon + + " " + + querystatus.colorClass + + "' title='" + + utils.escapeHtml(querystatus.fieldtext) + + "'>" ); } else if (querystatus.colorClass !== false) { $(row).addClass(querystatus.colorClass); diff --git a/scripts/js/taillog.js b/scripts/js/taillog.js index 0f9a9e45..1f21ce1f 100644 --- a/scripts/js/taillog.js +++ b/scripts/js/taillog.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment: false, apiFailure: false, utils: false, REFRESH_INTERVAL: false */ +/* global luxon: false, apiFailure: false, utils: false, REFRESH_INTERVAL: false */ "use strict"; @@ -179,7 +179,7 @@ function getData() { // Create and add new log entry to fragment const logEntry = document.createElement("div"); - const logEntryDate = moment(1000 * line.timestamp).format("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 = `${logEntryDate} ${line.message}`; diff --git a/scripts/js/utils.js b/scripts/js/utils.js index dfd5cf9a..aaeabaa1 100644 --- a/scripts/js/utils.js +++ b/scripts/js/utils.js @@ -5,7 +5,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -/* global moment:false, apiFailure: false, updateFtlInfo: false, NProgress:false, WaitMe:false */ +/* global luxon:false, apiFailure: false, updateFtlInfo: false, NProgress:false, WaitMe:false */ "use strict"; @@ -154,14 +154,14 @@ function datetime(date, html, humanReadable) { const format = html === false ? "Y-MM-DD HH:mm:ss z" : "Y-MM-DD []HH:mm:ss z"; - const timestr = moment.unix(Math.floor(date)).format(format).trim(); + const timestr = luxon.DateTime.fromMillis(Math.floor(date)).toFormat(format).trim(); return humanReadable - ? '' + moment.unix(Math.floor(date)).fromNow() + "" + ? '' + luxon.DateTime.fromMillis(Math.floor(date)).toRelative() + "" : timestr; } function datetimeRelative(date) { - return moment.unix(Math.floor(date)).fromNow(); + return luxon.DateTime.fromMillis(Math.floor(date)).toRelative(); } function disableAll() { diff --git a/scripts/lua/header_authenticated.lp b/scripts/lua/header_authenticated.lp index c544cf7a..2518fe26 100644 --- a/scripts/lua/header_authenticated.lp +++ b/scripts/lua/header_authenticated.lp @@ -16,8 +16,8 @@ mg.include('header.lp','r') - - + +