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

@ -495,7 +495,7 @@ document.addEventListener('DOMContentLoaded', () => {
function getTimeAgo(timestamp) {
const now = new Date();
// Ensure timestamp is treated as UTC if it doesn't have timezone info
const reportTime = new Date(timestamp.includes('T') ? timestamp : timestamp + 'Z');
const reportTime = parseUTCDate(timestamp);
const diffInMinutes = Math.floor((now - reportTime) / (1000 * 60));
if (diffInMinutes < 1) return 'just now';
@ -510,6 +510,11 @@ document.addEventListener('DOMContentLoaded', () => {
return reportTime.toLocaleDateString();
}
// Helper function to parse UTC date
function parseUTCDate(timestamp) {
return new Date(timestamp.includes('T') ? timestamp : timestamp + 'Z');
}
// Profanity management functions
async function loadProfanityWords() {
if (!profanityTableBody) return;