From 0625b5c0dfb2b46092c88665a287cc71bf58cf63 Mon Sep 17 00:00:00 2001 From: Niklas Deutschmann Date: Sat, 11 Apr 2026 16:19:18 +0200 Subject: [PATCH] Display timestamps using the timezone that is stored at the activity (fix 'new Date()' invocation) --- src/main/resources/static/js/fitpub.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/resources/static/js/fitpub.js b/src/main/resources/static/js/fitpub.js index f903d08..6258fa2 100644 --- a/src/main/resources/static/js/fitpub.js +++ b/src/main/resources/static/js/fitpub.js @@ -434,7 +434,7 @@ function formatDateTimeWithTimezone(timestamp, timezone, options = {}) { // Parse the timestamp - backend sends LocalDateTime without 'Z' // We need to interpret it in the specified timezone - const date = new Date(timestamp); + const date = new Date(ensureUTC(timestamp)); // Default options for date/time display const defaultOptions = { @@ -473,6 +473,17 @@ function formatDateWithTimezone(timestamp, timezone) { }); } +/** + * Ensures that a timestamp will be interpreted as UTC by new Date() + * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date (Date time string format) + * + * @param {string} timestamp - ISO timestamp or LocalDateTime string + * @returns {string} The input string, but with a trailing 'Z' + */ +function ensureUTC(timestamp) { + return timestamp.endsWith('Z') ? timestamp : timestamp + 'Z'; +} + // Make functions available globally for inline scripts window.FitPub = { createActivityMap,