View | Details | Raw Unified | Return to bug 18674
Collapse All | Expand All

(-)a/C4/Context.pm (+5 lines)
Lines 97-102 use POSIX (); Link Here
97
use DateTime::TimeZone;
97
use DateTime::TimeZone;
98
use Module::Load::Conditional qw(can_load);
98
use Module::Load::Conditional qw(can_load);
99
use Carp;
99
use Carp;
100
use DateTime::TimeZone;
100
101
101
use C4::Boolean;
102
use C4::Boolean;
102
use C4::Debug;
103
use C4::Debug;
Lines 981-986 sub timezone { Link Here
981
    my $self = shift;
982
    my $self = shift;
982
983
983
    my $timezone = C4::Context->config('timezone') || $ENV{TZ} || 'local';
984
    my $timezone = C4::Context->config('timezone') || $ENV{TZ} || 'local';
985
    if ( !DateTime::TimeZone->is_valid_name( $timezone ) ) {
986
        warn "Invalid timezone in koha-conf.xml ($timezone)";
987
        $timezone = 'local';
988
    }
984
989
985
    return $timezone;
990
    return $timezone;
986
}
991
}
(-)a/about.pl (-3 / +25 lines)
Lines 23-28 Link Here
23
use Modern::Perl;
23
use Modern::Perl;
24
24
25
use CGI qw ( -utf8 );
25
use CGI qw ( -utf8 );
26
use DateTime::TimeZone;
26
use List::MoreUtils qw/ any /;
27
use List::MoreUtils qw/ any /;
27
use LWP::Simple;
28
use LWP::Simple;
28
use XML::Simple;
29
use XML::Simple;
Lines 61-70 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
61
    }
62
    }
62
);
63
);
63
64
65
my $config_timezone = C4::Context->config('timezone');
66
my $config_invalid  = !DateTime::TimeZone->is_valid_name( $config_timezone );
67
my $env_timezone    = $ENV{TZ};
68
my $env_invalid     = !DateTime::TimeZone->is_valid_name( $env_timezone );
69
my $actual_bad_tz_fallback = 0;
70
71
if ( $config_timezone ne '' &&
72
     $config_invalid ) {
73
    # Bad config
74
    $actual_bad_tz_fallback = 1;
75
}
76
elsif ( $config_timezone eq '' &&
77
        $env_timezone    ne '' &&
78
        $env_invalid ) {
79
    # No config, but bad ENV{TZ}
80
    $actual_bad_tz_fallback = 1;
81
}
82
64
my $time_zone = {
83
my $time_zone = {
65
    actual      => C4::Context->timezone(),
84
    actual                 => C4::Context->timezone(),
66
    config      => C4::Context->config('timezone'),
85
    actual_bad_tz_fallback => $actual_bad_tz_fallback,
67
    environment => $ENV{TZ},
86
    config                 => $config_timezone,
87
    config_invalid         => $config_invalid,
88
    environment            => $env_timezone,
89
    environment_invalid    => $env_invalid
68
};
90
};
69
$template->param( 'time_zone' => $time_zone );
91
$template->param( 'time_zone' => $time_zone );
70
92
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (-3 / +17 lines)
Lines 112-121 Link Here
112
            <tr><th scope="row"><b>Warning</b> </th><td>Error message from Zebra: [% ( errZebraConnection ) %] </td></tr>
112
            <tr><th scope="row"><b>Warning</b> </th><td>Error message from Zebra: [% ( errZebraConnection ) %] </td></tr>
113
            [% END %]
113
            [% END %]
114
            <tr>
114
            <tr>
115
              [% timezone_config_class = (time_zone.config_invalid) ? 'status_warn' : '' %]
116
              [% timezone_env_class    = (time_zone.env_invalid)    ? 'status_warn' : '' %]
115
              <th scope="row">Time zone: </th>
117
              <th scope="row">Time zone: </th>
116
              <td>Used: <span class="status_ok">[% time_zone.actual %]</span> |
118
              <td>Used: <span>[% time_zone.actual %]</span>
117
                  Config: [% IF time_zone.config != '' %][% time_zone.config %][% ELSE %]<span>Undefined</span>[% END %] |
119
                          [% IF time_zone.actual_bad_tz_fallback %]
118
                  ENV: [% IF time_zone.environment != '' %][% time_zone.environment %][% ELSE %]<span>Undefined</span>[% END %]
120
                             <span>(This is a fallback value due to a bad configuration)</span>
121
                          [% END %]
122
                           |
123
                  Config: [% IF time_zone.config != '' %]
124
                            <span class="[% timezone_config_class %]">[% time_zone.config %]</span>
125
                          [% ELSE %]
126
                            <span>Undefined</span>
127
                          [% END %] |
128
                  Environment (TZ):  [% IF time_zone.environment != '' %]
129
                          <span class="[% timezone_env_class %]">[% time_zone.environment %]</span>
130
                        [% ELSE %]
131
                          <span>Undefined</span>
132
                        [% END %]
119
              </td>
133
              </td>
120
            </tr>
134
            </tr>
121
        </table>
135
        </table>
(-)a/t/timezones.t (-2 / +10 lines)
Lines 2-10 use Modern::Perl; Link Here
2
2
3
use C4::Context;
3
use C4::Context;
4
4
5
use Test::More tests => 3;
5
use Test::More tests => 5;
6
use Test::Warn;
6
use t::lib::Mocks;
7
use t::lib::Mocks;
7
8
9
use DateTime::TimeZone;
10
8
$ENV{TZ} = q{};
11
$ENV{TZ} = q{};
9
t::lib::Mocks::mock_config( 'timezone', q{} );
12
t::lib::Mocks::mock_config( 'timezone', q{} );
10
is( C4::Context->timezone, 'local',
13
is( C4::Context->timezone, 'local',
Lines 23-25 is( Link Here
23
    'Antarctica/South_Pole',
26
    'Antarctica/South_Pole',
24
    'Got correct timezone using config, overrides env'
27
    'Got correct timezone using config, overrides env'
25
);
28
);
26
- 
29
30
t::lib::Mocks::mock_config( 'timezone', 'Your/Timezone' );
31
warning_is {
32
    is( C4::Context->timezone, 'local', 'Invalid timezone falls back to local' ); }
33
    'Invalid timezone in koha-conf.xml (Your/Timezone)',
34
    'Invalid timezone raises a warning';

Return to bug 18674