Figure out how to handle the site timezone

Created on 12 November 2024, about 1 month ago

Problem/Motivation

Since we are skipping the standard installer, we don't prompt the user to set their timezone. So it defaults to UTC, which is weird since that doesn't apply to anyone.

Proposed resolution

Not sure, open to ideas. I think we either need to add this to the onboarding steps, or prompt users post install, perhaps via the dashboard.

Remaining tasks

TBC

User interface changes

TBC

πŸ“Œ Task
Status

Active

Component

Base Recipe

Created by

πŸ‡¦πŸ‡ΊAustralia pameeela

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @pameeela
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    This should be possible with a little tweak of core. It already gathers the host's default timezone in \Drupal\Core\Installer\Form\SiteConfigureForm::buildForm:

        $default_timezone = $this->config('system.date')->get('timezone.default') ?: @date_default_timezone_get();
        $form['regional_settings']['date_default_timezone'] = [
          '#type' => 'select',
          '#title' => $this->t('Default time zone'),
          '#default_value' => $default_timezone,
          '#options' => TimeZoneFormHelper::getOptionsListByRegion(),
          '#weight' => 5,
          '#attributes' => ['class' => ['timezone-detect']],
          '#access' => empty($install_state['config_install_path']),
        ];
    

    That assumes that the correct timezone is set on the host, but I mean that's what we should expect. If not even that is configured correctly, there's hardly anything one can do.

    Now, this approach in core only works if the config form is opened and saved.

    This should instead be done during installation. Then we should get the correct time zone for "most" new installations.

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    The only problem with using the host is that for the trial it would be the trial host, which I assume is probably just the US. This may just be something we have to live with but worth considering, in case we would rather ask the user to select it.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Idea: what if we changed the installer such that:

    • Turned the timezone selection into a hidden field, whose default value is the server-detected timezone
    • Use some JavaScript to ask the browser what timezone it is, and update the value of that hidden field
    • Set Drupal's timezone to whatever that hidden field submits
  • πŸ‡¦πŸ‡ΊAustralia pameeela

    That sounds great if we can swing it! But, this only works if we keep the onboarding as a pre-install step, and I think we have decided to decouple it to allow pre-installing, right?

    In that case, it's tricky because we also default to users can select their own timezone. This means that even if you update the site timezone, user 1 (or any other users who already exist before it is changed) are still set to UTC.

  • πŸ‡¦πŸ‡ΊAustralia pameeela
  • πŸ‡¦πŸ‡ΊAustralia pameeela
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    So it turns out that core already implements automatic client-size timezone detection, as proposed in #4. The only difference is that it shows the user a select field in a fieldset, so all we need to do is make that a hidden field, which is what my MR does.

    This is squarely ready for review.

  • Merge request !294Use core timezone detection β†’ (Merged) created by phenaproxima
  • Pipeline finished with Canceled
    15 days ago
    Total: 237s
    #363534
  • Pipeline finished with Canceled
    15 days ago
    Total: 64s
    #363540
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Looks good. Marking as RTBC

  • Pipeline finished with Skipped
    15 days ago
    #363765
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Merged, thanks everyone!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024