Timezone: add the ability to change it easily (#100)

This commit is contained in:
Cyril Chapellier 2024-01-14 16:36:20 +01:00 committed by GitHub
parent 16ee3a5f09
commit 0b0b6f6021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 64 additions and 10 deletions

2
.env
View File

@ -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

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -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

View File

@ -1,6 +1,8 @@
# For the MariaDB container mainly
DB_ROOT_PASSWORD=notSoSecure
TIMEZONE="Europe/Paris"
# The Davis database, user and password
DB_DATABASE=davis
DB_USER=davis_user

View File

@ -59,9 +59,6 @@ RUN apk --update --virtual build-deps-imap add --no-cache imap-dev openssl-dev k
&& apk del build-deps-imap \
&& rm -rf /tmp/*
# Set timezone correctly
RUN echo 'date.timezone = "Europe/Paris"' > /usr/local/etc/php/conf.d/timezone.ini
# Davis installation
ADD . /var/www/davis
WORKDIR /var/www/davis

View File

@ -50,6 +50,7 @@ services:
- WEBDAV_TMP_DIR=${WEBDAV_TMP_DIR}
- WEBDAV_PUBLIC_DIR=${WEBDAV_PUBLIC_DIR}
- INVITE_FROM_ADDRESS=${INVITE_FROM_ADDRESS}
- APP_TIMEZONE=${TIMEZONE}
depends_on:
- postgresql
volumes:

View File

@ -40,6 +40,7 @@ services:
- WEBDAV_TMP_DIR=${WEBDAV_TMP_DIR}
- WEBDAV_PUBLIC_DIR=${WEBDAV_PUBLIC_DIR}
- INVITE_FROM_ADDRESS=${INVITE_FROM_ADDRESS}
- APP_TIMEZONE=${TIMEZONE}
volumes:
- davis_www:/var/www/davis
- davis_data:/data

View File

@ -51,6 +51,7 @@ services:
- WEBDAV_TMP_DIR=${WEBDAV_TMP_DIR}
- WEBDAV_PUBLIC_DIR=${WEBDAV_PUBLIC_DIR}
- INVITE_FROM_ADDRESS=${INVITE_FROM_ADDRESS}
- APP_TIMEZONE=${TIMEZONE}
depends_on:
- mysql
volumes:

View File

@ -24,13 +24,19 @@ class DashboardController extends AbstractController
$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,
]);

View File

@ -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');

View File

@ -41,8 +41,11 @@
<li class="list-group-item list-group-item-primary">{{ "dashboard.version"|trans }} : <code>{{ version }}</code> (SabreDAV <code>{{ sabredav_version }}</code>)</li>
<li class="list-group-item list-group-item-secondary">{{ "dashboard.auth"|trans }} : <code>{{ authMethod }}</code> ({{ "dashboard.auth_realm"|trans }}: <code>{{ authRealm }}</code>)</li>
<li class="list-group-item list-group-item-secondary">{{ "dashboard.invite_from_address"|trans }} : <code>{{ invite_from_address|default('Not set') }}</code></li>
<li class="list-group-item list-group-item-secondary">{{ "dashboard.server_timezone"|trans }} : <code>{{ timezone }}</code> <a class="small ms-2" target="_blank" href="https://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone">{{ "dashboard.how_to_change_it"|trans }}</a></li>
<li class="list-group-item list-group-item-secondary d-flex justify-content-between align-items-center ">
<span>{{ "dashboard.server_timezone"|trans }} : <code>{{ timezone.actual_default }}</code></span>
{% if timezone.not_set_in_app %}<span class="badge bg-secondary rounded-pill">{{ "dashboard.no_timezone_configuration"|trans }}</span>{% endif %}
{% if timezone.bad_value %}<span class="badge bg-danger rounded-pill">{{ "dashboard.bad_timezone_configuration"|trans }}</span>{% endif %}
</li>
</ul>
</div>

View File

@ -119,11 +119,15 @@
</trans-unit>
<trans-unit id="Ppc629a" resname="dashboard.server_timezone">
<source>dashboard.server_timezone</source>
<target>Server Timezone</target>
<target>App (PHP) Timezone</target>
</trans-unit>
<trans-unit id="vsty3iK" resname="dashboard.how_to_change_it">
<source>dashboard.how_to_change_it</source>
<target>How to change it ?</target>
<trans-unit id="8.dmAfF" resname="dashboard.bad_timezone_configuration">
<source>dashboard.bad_timezone_configuration</source>
<target>Bad timezone configuration env var</target>
</trans-unit>
<trans-unit id="c.1lOsz" resname="dashboard.no_timezone_configuration">
<source>dashboard.no_timezone_configuration</source>
<target>Timezone not enforced by app</target>
</trans-unit>
<trans-unit id="rJf3tq1" resname="dashboard.users">
<source>dashboard.users</source>