Display timestamps using the timezone that is stored at the activity (fix 'new Date()' invocation)

This commit is contained in:
Niklas Deutschmann 2026-04-11 16:19:18 +02:00
parent 5f85417c80
commit 0625b5c0df

View file

@ -434,7 +434,7 @@ function formatDateTimeWithTimezone(timestamp, timezone, options = {}) {
// Parse the timestamp - backend sends LocalDateTime without 'Z' // Parse the timestamp - backend sends LocalDateTime without 'Z'
// We need to interpret it in the specified timezone // 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 // Default options for date/time display
const defaultOptions = { 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 // Make functions available globally for inline scripts
window.FitPub = { window.FitPub = {
createActivityMap, createActivityMap,