diff --git a/config/config.php b/config/config.php index aa95ef9..606a7e4 100644 --- a/config/config.php +++ b/config/config.php @@ -65,6 +65,20 @@ $GLOBALS['config'] = [ 'RATE_LIMIT_API' => 60, // Requests per minute for API // Audit log settings - 'AUDIT_LOG_RETENTION_DAYS' => 90 + 'AUDIT_LOG_RETENTION_DAYS' => 90, + + // Timezone settings + // Default: America/New_York (EST/EDT) + // Common options: America/Chicago (CST), America/Denver (MST), America/Los_Angeles (PST), UTC + 'TIMEZONE' => $envVars['TIMEZONE'] ?? 'America/New_York', + 'TIMEZONE_OFFSET' => null // Will be calculated below ]; + +// Set PHP default timezone +date_default_timezone_set($GLOBALS['config']['TIMEZONE']); + +// Calculate UTC offset for JavaScript (in minutes, negative for west of UTC) +$now = new DateTime('now', new DateTimeZone($GLOBALS['config']['TIMEZONE'])); +$GLOBALS['config']['TIMEZONE_OFFSET'] = $now->getOffset() / 60; // Convert seconds to minutes +$GLOBALS['config']['TIMEZONE_ABBREV'] = $now->format('T'); // e.g., "EST", "EDT" ?> \ No newline at end of file diff --git a/views/DashboardView.php b/views/DashboardView.php index 6e41ede..31ad6c4 100644 --- a/views/DashboardView.php +++ b/views/DashboardView.php @@ -20,6 +20,10 @@ require_once __DIR__ . '/../middleware/CsrfMiddleware.php'; echo CsrfMiddleware::getToken(); ?>'; + // Timezone configuration (from server) + window.APP_TIMEZONE = ''; + window.APP_TIMEZONE_OFFSET = ; // minutes from UTC + window.APP_TIMEZONE_ABBREV = '';
@@ -693,13 +697,25 @@ } }); + // Helper function to get date in server timezone + function getServerDate() { + // Get current UTC time + const now = new Date(); + // Apply server timezone offset (APP_TIMEZONE_OFFSET is in minutes) + const serverTime = new Date(now.getTime() + (window.APP_TIMEZONE_OFFSET * 60000) + (now.getTimezoneOffset() * 60000)); + return serverTime.getFullYear() + '-' + + String(serverTime.getMonth() + 1).padStart(2, '0') + '-' + + String(serverTime.getDate()).padStart(2, '0'); + } + // Stat card click handlers for filtering document.querySelectorAll('.stat-card').forEach(card => { card.style.cursor = 'pointer'; card.addEventListener('click', function() { const classList = this.classList; let url = '/?'; - const today = new Date().toISOString().split('T')[0]; + // Use server timezone date (default: EST) + const today = getServerDate(); if (classList.contains('stat-open')) { url += 'status=Open'; diff --git a/views/TicketView.php b/views/TicketView.php index 12b9bf4..a6db0a2 100644 --- a/views/TicketView.php +++ b/views/TicketView.php @@ -58,6 +58,10 @@ function formatDetails($details, $actionType) { require_once __DIR__ . '/../middleware/CsrfMiddleware.php'; echo CsrfMiddleware::getToken(); ?>'; + // Timezone configuration (from server) + window.APP_TIMEZONE = ''; + window.APP_TIMEZONE_OFFSET = ; // minutes from UTC + window.APP_TIMEZONE_ABBREV = '';