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

BPS Git Server git at git.bestpractical.com
Fri Jun 24 13:43:06 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  b0cee87509c18826d1aec0b96c510ab387d6b7c5 (commit)

- Log -----------------------------------------------------------------
commit b0cee87509c18826d1aec0b96c510ab387d6b7c5
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..6797a6fba3 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1952,7 +1952,40 @@ 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 current value is deprecated then it won't appear in the list
+                              if ($cur_value and !grep { $_ eq $cur_value } @names) {
+                                  unshift @names, $cur_value
+                              }
+
+                              # 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, which will break the ability to reset the option
+                              if ($file_value and $file_value ne $cur_value and !grep { $_ eq $file_value } @names) {
+                                  unshift @names, $file_value
+                              }
+
+                              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