Skip to content

Commit

Permalink
Timezone: step2
Browse files Browse the repository at this point in the history
  • Loading branch information
tchapi committed Nov 18, 2023
1 parent 8ea1d5c commit 4f84438
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/Controller/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
14 changes: 14 additions & 0 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 5 additions & 2 deletions templates/dashboard.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
12 changes: 8 additions & 4 deletions translations/messages+intl-icu.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 4f84438

Please sign in to comment.