Committer: ailyin
LJSUP-8202 (Variable with Time Zone for translation system)U trunk/cgi-bin/LJ/Setting/TimeZone.pm U trunk/htdocs/manage/profile/index.bml
Modified: trunk/cgi-bin/LJ/Setting/TimeZone.pm =================================================================== --- trunk/cgi-bin/LJ/Setting/TimeZone.pm 2011-03-31 03:21:55 UTC (rev 18754) +++ trunk/cgi-bin/LJ/Setting/TimeZone.pm 2011-03-31 08:36:08 UTC (rev 18755) @@ -21,19 +21,45 @@ return $class->ml('setting.timezone.label'); } +# this one returns a $key => $value list, ordered by keys this way: +# US goes first, then Canada, then all the rest +sub timezone_options { + my ($class) = @_; + + my $map = DateTime::TimeZone::links(); + + my ( @options, %options ); + + foreach my $key ( sort keys %$map ) { + if ( $key =~ m!^US/! && $key ne 'US/Pacific-New' ) { + $options{ $map->{$key} } = $key; + push @options, $map->{$key} => $key; + } + } + + foreach my $key ( sort keys %$map ) { + if ( $key =~ m!^Canada/! ) { + $options{ $map->{$key} } = $key; + push @options, $map->{$key} => $key; + } + } + + foreach my $key ( DateTime::TimeZone::all_names() ) { + next if $options{$key}; + push @options, $key => $key; + } + + return @options; +} + sub option { my ($class, $u, $errs, $args) = @_; my $key = $class->pkgkey; my $timezone = $class->get_arg($args, "timezone") || $u->prop("timezone"); - my $map = DateTime::TimeZone::links(); - my $usmap = { map { $_ => $map->{$_} } grep { m!^US/! && $_ ne "US/Pacific-New" } keys %$map }; - my $camap = { map { $_ => $map->{$_} } grep { m!^Canada/! } keys %$map }; + my @options = $class->timezone_options; - my @options = ("", $class->ml('setting.timezone.option.select')); - push @options, (map { $usmap->{$_}, $_ } sort keys %$usmap), (map { $camap->{$_}, $_ } sort keys %$camap), (map { $_, $_ } DateTime::TimeZone::all_names()); - my $ret = LJ::html_select({ name => "${key}timezone", selected => $timezone, Modified: trunk/htdocs/manage/profile/index.bml =================================================================== --- trunk/htdocs/manage/profile/index.bml 2011-03-31 03:21:55 UTC (rev 18754) +++ trunk/htdocs/manage/profile/index.bml 2011-03-31 08:36:08 UTC (rev 18755) @@ -600,8 +600,10 @@ $ret .= LJ::html_select({ 'name' => 'sms_interval_end', 'selected' => $end || 23, }, @sms_time); + + my %timezone_options = LJ::Setting::TimeZone->timezone_options; $ret .= " " . BML::ml(".fn.smsinterval.localtime2", { - 'timezone' => $u->prop('timezone'), + 'timezone' => $timezone_options{ $u->prop('timezone') }, }); $ret .= '</div>';