DateTime format based on TIMEZONE #1044

This commit is contained in:
jokob-sk
2025-05-10 15:23:02 +10:00
parent 01f7a18dce
commit 03822ac8fa
5 changed files with 53 additions and 3 deletions

View File

@@ -173,7 +173,7 @@
// Additional form elements like the random MAC address button for devMac
let inlineControl = "";
// handle rendom mac
// handle random mac
if (setting.setKey == "NEWDEV_devMac" && deviceData["devIsRandomMAC"] == true) {
inlineControl += `<span class="input-group-addon pointer"
title="${getString("RandomMAC_hover")}">

View File

@@ -47,9 +47,28 @@
{visible: false, targets: [0]},
// Replace HTML codes
{targets: [1,2,3,5],
{targets: [3,5],
'createdCell': function (td, cellData, rowData, row, col) {
$(td).html (translateHTMLcodes (cellData));
} },
// Date
{targets: [1,2],
"createdCell": function (td, cellData, rowData, row, col) {
console.log(cellData);
if (!cellData.includes("missing event") && !cellData.includes("..."))
{
if (cellData.includes("+")) { // Check if timezone offset is present
cellData = cellData.split('+')[0]; // Remove timezone offset
}
console.log(cellData);
result = localizeTimestamp(cellData);
} else
{
result = translateHTMLcodes(cellData)
}
$(td).html (result);
} }
],

View File

@@ -216,7 +216,7 @@ function initializeDatatable () {
} },
// Replace HTML codes
{targets: [3,4,5,6,7],
{targets: [4,5,6,7],
"createdCell": function (td, cellData, rowData, row, col) {
$(td).html (translateHTMLcodes (cellData));
} },
@@ -226,6 +226,12 @@ function initializeDatatable () {
"createdCell": function (td, cellData, rowData, row, col) {
// console.log(cellData);
$(td).html (cellData);
} },
// Date
{targets: [3],
"createdCell": function (td, cellData, rowData, row, col) {
// console.log(cellData);
$(td).html (localizeTimestamp(cellData));
} }
],

View File

@@ -353,6 +353,28 @@ function getLangCode() {
// String utilities
// -----------------------------------------------------------------------------
function localizeTimestamp(result)
{
// contains TZ in format Europe/Berlin
tz = getSetting("TIMEZONE")
const date = new Date(result); // Assumes result is a timestamp or ISO string
const formatter = new Intl.DateTimeFormat('default', {
timeZone: tz,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false // change to true if you want AM/PM format
});
return formatter.format(date);
}
// ----------------------------------------------------
/**
* Replaces double quotes within single-quoted strings, then converts all single quotes to double quotes,

View File

@@ -78,6 +78,9 @@ require 'php/templates/header.php';
if (result.includes("+")) { // Check if timezone offset is present
result = result.split('+')[0]; // Remove timezone offset
}
result = localizeTimestamp(result);
return result;
}
},