Add timezone support to last updated timestamp formatting

Updated the `updateLastUpdated()` function in `workers.js` to include timezone configuration for formatting the last updated timestamp. Introduced a `configuredTimezone` variable with a default value of 'America/Los_Angeles'. The timestamp is now formatted using this timezone, and a console log statement indicates the timezone used. Added a fallback to the current date and time in case of formatting errors.
This commit is contained in:
DJObleezy 2025-04-18 11:28:18 -07:00
parent 97fe19d61d
commit f166126525

View File

@ -532,6 +532,11 @@ function updateLastUpdated() {
try {
const timestamp = new Date(workerData.timestamp);
// Get the configured timezone with a fallback
const configuredTimezone = window.dashboardTimezone || 'America/Los_Angeles';
// Format with the configured timezone
const options = {
year: 'numeric',
month: 'short',
@ -539,12 +544,22 @@ function updateLastUpdated() {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true
hour12: true,
timeZone: configuredTimezone // Explicitly use the configured timezone
};
// Format the timestamp and update the DOM
const formattedTime = timestamp.toLocaleString('en-US', options);
$("#lastUpdated").html("<strong>Last Updated:</strong> " +
timestamp.toLocaleString('en-US', options) + "<span id='terminal-cursor'></span>");
formattedTime + "<span id='terminal-cursor'></span>");
console.log(`Last updated timestamp using timezone: ${configuredTimezone}`);
} catch (e) {
console.error("Error formatting timestamp:", e);
// Fallback to basic timestamp if there's an error
$("#lastUpdated").html("<strong>Last Updated:</strong> " +
new Date().toLocaleString() + "<span id='terminal-cursor'></span>");
}
}