Fix timezone handling for accurate 48-hour expiry display
- Fixed getTimeAgo(), getTimeRemaining(), and getRemainingClass() functions - Database stores UTC timestamps but frontend was treating them as local time - Added logic to append 'Z' to timestamps without timezone info to force UTC interpretation - Now properly shows 48-hour countdown instead of incorrect 52-hour or 28-hour values - Affects both main app (app-mapbox.js) and admin panel (admin.js)
This commit is contained in:
parent
276dc65195
commit
58b6a13106
2 changed files with 8 additions and 4 deletions
|
@ -494,7 +494,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
|
||||
function getTimeAgo(timestamp) {
|
||||
const now = new Date();
|
||||
const reportTime = new Date(timestamp);
|
||||
// Ensure timestamp is treated as UTC if it doesn't have timezone info
|
||||
const reportTime = new Date(timestamp.includes('T') ? timestamp : timestamp + 'Z');
|
||||
const diffInMinutes = Math.floor((now - reportTime) / (1000 * 60));
|
||||
|
||||
if (diffInMinutes < 1) return 'just now';
|
||||
|
|
|
@ -95,7 +95,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
|
||||
const getTimeAgo = (timestamp) => {
|
||||
const now = new Date();
|
||||
const reportTime = new Date(timestamp);
|
||||
// Ensure timestamp is treated as UTC if it doesn't have timezone info
|
||||
const reportTime = new Date(timestamp.includes('T') ? timestamp : timestamp + 'Z');
|
||||
const diffInMinutes = Math.floor((now - reportTime) / (1000 * 60));
|
||||
|
||||
if (diffInMinutes < 1) return 'just now';
|
||||
|
@ -172,7 +173,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
}
|
||||
|
||||
const now = new Date();
|
||||
const reportTime = new Date(timestamp);
|
||||
// Ensure timestamp is treated as UTC if it doesn't have timezone info
|
||||
const reportTime = new Date(timestamp.includes('T') ? timestamp : timestamp + 'Z');
|
||||
const expirationTime = new Date(reportTime.getTime() + 48 * 60 * 60 * 1000);
|
||||
const remaining = expirationTime - now;
|
||||
|
||||
|
@ -195,7 +197,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
}
|
||||
|
||||
const now = new Date();
|
||||
const reportTime = new Date(timestamp);
|
||||
// Ensure timestamp is treated as UTC if it doesn't have timezone info
|
||||
const reportTime = new Date(timestamp.includes('T') ? timestamp : timestamp + 'Z');
|
||||
const expirationTime = new Date(reportTime.getTime() + 48 * 60 * 60 * 1000);
|
||||
const remaining = expirationTime - now;
|
||||
const hoursRemaining = remaining / (1000 * 60 * 60);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue