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,