forked from Alex/Pterodactyl-Panel
Set the DB timezone on each connection to match the APP_TIMEZONE value
This commit is contained in:
parent
8c6327fd32
commit
996fb5b46f
25
app/Helpers/Time.php
Normal file
25
app/Helpers/Time.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Helpers;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
final class Time
|
||||
{
|
||||
/**
|
||||
* Gets the time offset from the provided timezone relative to UTC as a number. This
|
||||
* is used in the database configuration since we can't always rely on there being support
|
||||
* for named timezones in MySQL.
|
||||
*
|
||||
* Returns the timezone as a string like +08:00 or -05:00 depending on the app timezone.
|
||||
*
|
||||
* @param string $timezone
|
||||
* @return string
|
||||
*/
|
||||
public static function getMySQLTimezoneOffset(string $timezone): string
|
||||
{
|
||||
$offset = round(CarbonImmutable::now($timezone)->getTimezone()->getOffset(CarbonImmutable::now('UTC')) / 3600);
|
||||
|
||||
return sprintf('%s%s:00', $offset > 0 ? '+' : '-', str_pad(abs($offset), 2, '0', STR_PAD_LEFT));
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Pterodactyl\Helpers\Time;
|
||||
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@ -43,6 +45,7 @@ return [
|
||||
'collation' => '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')))
|
||||
],
|
||||
],
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user