From ce93233e683bea4f716b0b8f8a7629f7549ac3ae Mon Sep 17 00:00:00 2001 From: Dave Earley Date: Mon, 28 Oct 2024 21:07:33 -0700 Subject: [PATCH] Fix: Handle deprecated timezones --- backend/app/Http/Kernel.php | 2 ++ .../Middleware/HandleDeprecatedTimezones.php | 27 +++++++++++++++++++ backend/config/timezones.php | 18 +++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 backend/app/Http/Middleware/HandleDeprecatedTimezones.php create mode 100644 backend/config/timezones.php diff --git a/backend/app/Http/Kernel.php b/backend/app/Http/Kernel.php index 9891f7b2..c8fbb3ba 100644 --- a/backend/app/Http/Kernel.php +++ b/backend/app/Http/Kernel.php @@ -4,6 +4,7 @@ use HiEvents\Http\Middleware\Authenticate; use HiEvents\Http\Middleware\EncryptCookies; +use HiEvents\Http\Middleware\HandleDeprecatedTimezones; use HiEvents\Http\Middleware\PreventRequestsDuringMaintenance; use HiEvents\Http\Middleware\RedirectIfAuthenticated; use HiEvents\Http\Middleware\SetAccountContext; @@ -45,6 +46,7 @@ class Kernel extends HttpKernel ValidatePostSize::class, TrimStrings::class, ConvertEmptyStringsToNull::class, + HandleDeprecatedTimezones::class, ]; /** diff --git a/backend/app/Http/Middleware/HandleDeprecatedTimezones.php b/backend/app/Http/Middleware/HandleDeprecatedTimezones.php new file mode 100644 index 00000000..1b9985be --- /dev/null +++ b/backend/app/Http/Middleware/HandleDeprecatedTimezones.php @@ -0,0 +1,27 @@ +has('timezone')) { + $timezone = $request->input('timezone'); + + if (array_key_exists($timezone, $timezoneMapping)) { + $request->merge(['timezone' => $timezoneMapping[$timezone]]); + } elseif (!in_array($timezone, timezone_identifiers_list(), true)) { + Log::warning("Unexpected timezone received: $timezone"); + } + } + + return $next($request); + } +} diff --git a/backend/config/timezones.php b/backend/config/timezones.php new file mode 100644 index 00000000..54a80be5 --- /dev/null +++ b/backend/config/timezones.php @@ -0,0 +1,18 @@ + [ + 'Asia/Calcutta' => 'Asia/Kolkata', + 'Asia/Saigon' => 'Asia/Ho_Chi_Minh', + 'America/Buenos_Aires' => 'America/Argentina/Buenos_Aires', + 'Europe/Kiev' => 'Europe/Kyiv', + 'Africa/Asmera' => 'Africa/Asmara', + 'America/Indianapolis' => 'America/Indiana/Indianapolis', + 'Asia/Chongqing' => 'Asia/Shanghai', + 'Asia/Macao' => 'Asia/Macau', + 'Pacific/Samoa' => 'Pacific/Pago_Pago', + 'Pacific/Yap' => 'Pacific/Chuuk', + 'Etc/GMT+0' => 'Etc/GMT', + 'Etc/Greenwich' => 'Etc/GMT', + ], +];