> It's become painfully obvious that having end users choosea timezone based on the huge list that is provided natively by DateTime::TimeZone::all_names just isn't very practical at this time. (Perhaps in the future when more people are used to dealing with the Olson names.)
<snip>
Is there anyway to do some work on TimeZoneCatalog to get some different kinds of lists (for instance, a shortened list of timezones that removes zones that only have historical differnces)? Would anyone be opposed to/in favor of that?
At 10:31 PM -1000 22/9/03, Joshua Hoblitt replied:
I think you want DateTime::TimeZone::names_in_category(). Which accepts a scalar from the array returned by categories() and itself returns a list of Olson timezones.
Maybe there should be a method to get the list of zones as a Hash-of-Hashes-of-Hashes such that we have:
$time_zones = { 'Oceania' => { 'Australia' => { Melbourne => 'Australia/Melbourne', Sydney => 'Australia/Sydney', }, 'New Zealand' => { Auckland => 'NewZealand/Auckland', }, }, 'North America' => { 'United States' => { 'New York' => 'America/NewYork', }, } }
This would mean that we have tree data that can be used in forms. This code will turn it into a HTML select:
function make_select {
my %time_zones = (ref $_[0]) ? %{$_[0]} : @_;
foreach my $key ( sort keys %time_zones ) {
if (ref $time_zones{$key}) {
print qq|\t<optgroup label="$key">\n|;
foreach my $subkey( sort keys %{$time_zones{$key}} ) {
if (ref $time_zones{$key}{$subkey}) {
print qq|\t\t<optgroup label="$subkey">\n|;
foreach my $subsubkey( sort keys %{$time_zones{$key}{$subkey}} ) {
print qq|\t\t\t<option value="$time_zones{$key}{$subkey}{$subsubkey}">$subsubkey</option>\n|;
}
print qq|\t\t</optgroup>\n|;
} else {
print qq|\t\t<option value="$time_zones{$key}{$subkey}">$subkey</option>\n|;
}
}
print qq|\t</optgroup>\n|;
} else {
print qq|\t<option value="$time_zones{$key}">$key</option>\n|;
}
}
The above code would allow you to feed it with a sub group of the data hash or the whole hash:
$select = make_select( %time_zones );
$select_usa = make_select( $time_zones{'North America'}{'United States'} );