Refactor: Extract UTC parsing logic to parseUTCDate helper function

- Add parseUTCDate helper function to handle timestamp UTC parsing consistently
- Eliminates code duplication across getTimeAgo, getTimeRemaining, and expiry functions
- Applied to admin.js, app-mapbox.js, app-google.js, and app.js
- Ensures consistent UTC timezone handling throughout all frontend JavaScript
- Addresses Copilot AI feedback for better code maintainability and DRY principles

The parseUTCDate function handles the logic:
timestamp.includes('T') ? timestamp : timestamp + 'Z'

This ensures all timestamp parsing uses the same UTC interpretation logic.
This commit is contained in:
Deco Vander 2025-07-04 13:14:27 -04:00
parent 544766e5dc
commit 45a8d67362
4 changed files with 28 additions and 6 deletions

View file

@ -82,9 +82,15 @@ document.addEventListener('DOMContentLoaded', async () => {
});
};
// Helper function to parse UTC date
const parseUTCDate = (timestamp) => {
return new Date(timestamp.includes('T') ? timestamp : timestamp + 'Z');
};
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 = parseUTCDate(timestamp);
const diffInMinutes = Math.floor((now - reportTime) / (1000 * 60));
if (diffInMinutes < 1) return 'just now';