From 996fb5b46f6ebaa9e38d58d3aeeb2feae654e814 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 25 Oct 2020 15:07:11 -0700 Subject: [PATCH] Set the DB timezone on each connection to match the APP_TIMEZONE value --- app/Helpers/Time.php | 25 +++++++++++++++++++++++++ config/database.php | 4 ++++ 2 files changed, 29 insertions(+) create mode 100644 app/Helpers/Time.php diff --git a/app/Helpers/Time.php b/app/Helpers/Time.php new file mode 100644 index 000000000..248ff55f0 --- /dev/null +++ b/app/Helpers/Time.php @@ -0,0 +1,25 @@ +getTimezone()->getOffset(CarbonImmutable::now('UTC')) / 3600); + + return sprintf('%s%s:00', $offset > 0 ? '+' : '-', str_pad(abs($offset), 2, '0', STR_PAD_LEFT)); + } +} diff --git a/config/database.php b/config/database.php index 32fca7581..5a4e8bc77 100644 --- a/config/database.php +++ b/config/database.php @@ -1,5 +1,7 @@ 'utf8mb4_unicode_ci', 'prefix' => env('DB_PREFIX', ''), 'strict' => env('DB_STRICT_MODE', false), + 'timezone' => env('DB_TIMEZONE', Time::getMySQLTimezoneOffset(env('APP_TIMEZONE'))) ], /* @@ -65,6 +68,7 @@ return [ 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => false, + 'timezone' => env('DB_TIMEZONE', Time::getMySQLTimezoneOffset(env('APP_TIMEZONE'))) ], ],