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?
Related Issues
#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)
Comments
Comment #1
Hanno CreditAttribution: Hanno commentedThe usability issue of the installer was also mentioned here: #1933614: [META] Locale settings in Drupal make little (UX) sense
Comment #2
klonos...adding same tags as #1933614: [META] Locale settings in Drupal make little (UX) sense and also setting to the same component.
Comment #3
Hanno CreditAttribution: Hanno commentedWill 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:
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:
Comment #4
klonosA step closer! Great ;)
Comment #4.0
klonos...added a few more related issues.
Comment #5
mgiffordComment #17
longwaveClosing as outdated, this was solved by detecting the user's timezone directly where possible in #3016427: Default timezone selection incorrect