Problem/Motivation

This came up in #1031450-16: Use Geolocation API for timezone detection. This is an issue dedicated to exactly that matter:

In D7, if one goes through the installer and selects a country, they also have to set the timezone. This might be a desired feature for some countries that span over various timezones (though it would be great to limit the list of values in the drop-down to only the timezones that apply to that country), but it would be great if it was so that if a country is within a single timezone, the respective timezone is auto-selected.

For example, I always select Greece for the country, but the timezone is set to "Europe/Helsinki" instead of "Europe/Athens" (??). So, I always have to take an extra step to select the proper timezone too. I always mumble that Drupal should be smart enough to understand that if I set the site's country to Greece, then the timezone is most likely Europe/Athens. This doesn't happen despite the fact that I've set this in my php.ini date.timezone parameter. So, I'd also like to take the opportunity to suggest that we also read this parameter and preselect the value from the drop-downs. This would provide "sensible defaults" for most installations and require less clicks during setup.

...

...just to support my claim that this in far from an edge case: this list shows that there's only 21 countries with multiple timezones and the rest of the 175 countries have a single timezone. ...

Proposed resolution

- Preselect respective timezone when a user selects a country with a single timezone.
- Limit the list of available timezones to only the valid ones when a user selects a country with multiple timezones.

Remaining tasks

...

User interface changes

Users no longer take an additional step to select the timezone unless the country they selected spans over multiple timezones. In the later case they have to scroll less because the drop-down is limited to timezones only valid for the corresponding country they selected.

API changes

??? - If there are none, then perhaps backport to D7?

#1031450-16: Use Geolocation API for timezone detection
#1345758: META: Provide locale (regional) formats framework for automated translation of non textual data
#1787540: Improve the Timezone Picker
#2083575: Provide better UX when selecting Country/timezone. (depends/postponed on #675446: Use jQuery UI Autocomplete)

Original report by klonos

Comments

Hanno’s picture

The usability issue of the installer was also mentioned here: #1933614: [META] Locale settings in Drupal make little (UX) sense

klonos’s picture

Component: install system » language system
Issue tags: +Usability, +installer, +country list, +D8MI, +Sunrise Sanity Cruise

...adding same tags as #1933614: [META] Locale settings in Drupal make little (UX) sense and also setting to the same component.

Hanno’s picture

Will drop the code here as this might help to build the function. This code gives an array of all the timezones in a specific country:

$timezones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $countrycode);

for example:
$timezones_FR = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, "FR");
returns
[0] => Europe/Paris
and
$timezones_US = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, "US");
returns
[0] => America/Adak [1] => America/Anchorage [2] => America/Boise [3] => America/Chicago [4] => America/Denver [5] => America/Detroit [6] => America/Indiana/Indianapolis [7] => America/Indiana/Knox [8] => America/Indiana/Marengo [9] => America/Indiana/Petersburg [10] => America/Indiana/Tell_City [11] => America/Indiana/Vevay [12] => America/Indiana/Vincennes [13] => America/Indiana/Winamac [14] => America/Juneau [15] => America/Kentucky/Louisville [16] => America/Kentucky/Monticello [17] => America/Los_Angeles [18] => America/Menominee [19] => America/Metlakatla [20] => America/New_York [21] => America/Nome [22] => America/North_Dakota/Beulah [23] => America/North_Dakota/Center [24] => America/North_Dakota/New_Salem [25] => America/Phoenix [26] => America/Shiprock [27] => America/Sitka [28] => America/Yakutat [29] => Pacific/Honolulu

And this is the other way around, if the timezone is selected, you'll get the country code of that timezone with:

$tz = new DateTimeZone($timezonename);
$countrycode = $tz->getLocation()['country_code'];
klonos’s picture

A step closer! Great ;)

klonos’s picture

Issue summary: View changes

...added a few more related issues.

mgifford’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Active » Closed (outdated)

Closing as outdated, this was solved by detecting the user's timezone directly where possible in #3016427: Default timezone selection incorrect