diff --git a/.env b/.env index 7209c02..971e669 100644 --- a/.env +++ b/.env @@ -20,6 +20,8 @@ APP_SECRET=630dc0d699fd37e720aff268f75583ed #TRUSTED_HOSTS='^localhost|example\.com$' ###< symfony/framework-bundle ### +APP_TIMEZONE="Europe/Paris" + ###> doctrine/doctrine-bundle ### DATABASE_DRIVER=mysql # or postgresql, or sqlite # Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url diff --git a/README.md b/README.md index 8fce978..f7c214d 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,20 @@ You can use an absolute file path here, and you can use Symfony's `%kernel.logs_ LOG_FILE_PATH="%kernel.logs_dir%/%kernel.environment%.log" ``` +h. The timezone you want for the app + +This must comply with the [official list](https://www.php.net/manual/en/timezones.php) + +``` +APP_TIMEZONE="Australia/Lord_Howe" +``` + +> Set a void value like so: +> ``` +> APP_TIMEZONE= +> ``` +> in your environment file if you wish to use the **actual default timezone of the server**, and not enforcing it. + ### Specific environment variables for IMAP and LDAP authentication methods In case you use the `IMAP` auth type, you must specify the auth url (_the "mailbox" url_) in `IMAP_AUTH_URL`. See https://www.php.net/manual/en/function.imap-open.php for more details. @@ -427,6 +441,14 @@ Depending on how you run Davis, logs are either: > > It's `./var/log` (relative to the Davis installation), not `/var/log` +### I have a "Bad timezone configuration env var" error on the dashboard + +If you see this: + +![Bad timezone configuration env var error](_screenshots/bad_timezone_configuration_env_var.png) + +It means that the value you set for the `APP_TIMEZONE` env var is not a correct timezone, as per [the official list](https://www.php.net/manual/en/timezones.php). Your timezone has thus not been set and is the server's default (Here, UTC). Adjust the setting accordingly. + ### I have a 500 and no tables have been created You probably forgot to run the migration once to create the necessary DB schema diff --git a/_screenshots/bad_timezone_configuration_env_var.png b/_screenshots/bad_timezone_configuration_env_var.png new file mode 100644 index 0000000..1944d96 Binary files /dev/null and b/_screenshots/bad_timezone_configuration_env_var.png differ diff --git a/config/services.yaml b/config/services.yaml index ab946fc..fbe5695 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -5,6 +5,7 @@ # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: default_database_driver: "mysql" + timezone: '%env(APP_TIMEZONE)%' services: # default configuration for services in *this* file diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php index 8ea9056..0222b7f 100644 --- a/src/Controller/Admin/DashboardController.php +++ b/src/Controller/Admin/DashboardController.php @@ -24,13 +24,19 @@ public function dashboard(ManagerRegistry $doctrine) $events = $doctrine->getRepository(CalendarObject::class)->findAll(); $contacts = $doctrine->getRepository(Card::class)->findAll(); + $timezoneParameter = $this->getParameter('timezone'); + return $this->render('dashboard.html.twig', [ 'users' => $users, 'calendars' => $calendars, 'addressbooks' => $addressbooks, 'events' => $events, 'contacts' => $contacts, - 'timezone' => date_default_timezone_get(), + 'timezone' => [ + 'actual_default' => date_default_timezone_get(), + 'not_set_in_app' => '' === $timezoneParameter, + 'bad_value' => '' !== $timezoneParameter && !in_array($timezoneParameter, \DateTimeZone::listIdentifiers()), + ], 'version' => \App\Version::VERSION, 'sabredav_version' => \Sabre\DAV\Version::VERSION, ]); diff --git a/src/Kernel.php b/src/Kernel.php index b016861..0f43d2f 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -11,6 +11,20 @@ class Kernel extends BaseKernel { use MicroKernelTrait; + public function boot(): void + { + parent::boot(); + $timezone = $this->getContainer()->getParameter('timezone'); + if ('' === $timezone) { + return; + } + try { + date_default_timezone_set($timezone); + } catch (\Exception $e) { + // We don't crash the app, the setting will be flagged as incorrect in the dashboard + } + } + protected function configureContainer(ContainerConfigurator $container): void { $container->import('../config/{packages}/*.yaml'); diff --git a/templates/dashboard.html.twig b/templates/dashboard.html.twig index 737f48e..474b1b5 100644 --- a/templates/dashboard.html.twig +++ b/templates/dashboard.html.twig @@ -41,8 +41,11 @@
{{ version }}
(SabreDAV {{ sabredav_version }}
){{ authMethod }}
({{ "dashboard.auth_realm"|trans }}: {{ authRealm }}
){{ invite_from_address|default('Not set') }}
{{ timezone }}
{{ "dashboard.how_to_change_it"|trans }}{{ timezone.actual_default }}
+ {% if timezone.not_set_in_app %}{{ "dashboard.no_timezone_configuration"|trans }}{% endif %}
+ {% if timezone.bad_value %}{{ "dashboard.bad_timezone_configuration"|trans }}{% endif %}
+