[Rt-commit] rt branch 5.0/make-sysconfig-timezone-selectbox created. rt-5.0.2-279-g490d16ea0c

BPS Git Server git at git.bestpractical.com
Thu Jun 23 15:59:20 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/make-sysconfig-timezone-selectbox has been created
        at  490d16ea0ca666328bdd93a67d62c4465504fc4f (commit)

- Log -----------------------------------------------------------------
commit 490d16ea0ca666328bdd93a67d62c4465504fc4f
Author: Brian Conry <bconry at bestpractical.com>
Date:   Thu Jun 23 09:59:17 2022 -0500

    Make the Timezone config option a Select widget
    
    This change converts the Timezone option to a Select widget, from a text
    box, on the System Configuration page.  This restricts the admin to
    choosing from known-valid options.
    
    This is the same list that is built and presented in the User
    Preferences.
    
    Note that while this list does not usually include deprecated timezone
    names, the current value of the configuration option and the file-only
    value of the option (if different from the current value) are both
    added at the top of the list, even when they are deprecated.

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 89276eeba7..0d417125d3 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1952,7 +1952,39 @@ our %META;
         Widget => '/Widgets/Form/String',
     },
     Timezone => {
-        Widget => '/Widgets/Form/String',
+        Widget => '/Widgets/Form/Select',
+        WidgetArguments => {
+            Callback => sub { my $ret = { Values => [], ValuesLabel => {} };
+                              # all_names doesn't include deprecated names,
+                              # but those deprecated names still work
+                              #
+                              # N.B. there are hundreds of deprecated names
+                              # so we probably don't want to include them all
+                              my @names = ( DateTime::TimeZone->all_names );
+
+                              my $cur_value = RT->Config->Get('Timezone');
+                              my $file_value = RT->Config->_GetFromFilesOnly('Timezone');
+
+                              # if the value found in the config files is deprecated then it
+                              # won't appear in the list unless it's also the same as the
+                              # current value (added below), which will break the ability to
+                              # reset the option
+                              unshift @names, $file_value
+                                unless $cur_value eq $file_value or grep { $_ eq $file_value } @names;
+
+                              # if the current value is deprecated then it won't appear in the list
+                              unshift @names, $cur_value
+                                unless grep { $_ eq $cur_value } @names;
+
+                              my $dt = DateTime->now;
+                              foreach my $tzname ( @names ) {
+                                  push @{ $ret->{Values} }, $tzname;
+                                  $dt->set_time_zone( $tzname );
+                                  $ret->{ValuesLabel}{$tzname} = $tzname . ' ' . $dt->strftime('%z');
+                              }
+                              return $ret;
+            },
+        },
     },
     VERPPrefix => {
         Widget => '/Widgets/Form/String',

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list