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

(-)a/C4/Context.pm (-1 / +17 lines)
Lines 969-974 sub get_versions { Link Here
969
    return %versions;
969
    return %versions;
970
}
970
}
971
971
972
=head2 timezone
973
974
  my $C4::Context->timzone
975
976
  Returns a timezone code for the instance of Koha
977
978
=cut
979
980
sub timezone {
981
    my $self = shift;
982
983
    my $timezone = C4::Context->config('timezone') || $ENV{TZ} || 'local';
984
985
    return $timezone;
986
}
972
987
973
=head2 tz
988
=head2 tz
974
989
Lines 981-987 sub get_versions { Link Here
981
sub tz {
996
sub tz {
982
    my $self = shift;
997
    my $self = shift;
983
    if (!defined $context->{tz}) {
998
    if (!defined $context->{tz}) {
984
        $context->{tz} = DateTime::TimeZone->new(name => 'local');
999
        my $timezone = $self->timezone;
1000
        $context->{tz} = DateTime::TimeZone->new(name => $timezone);
985
    }
1001
    }
986
    return $context->{tz};
1002
    return $context->{tz};
987
}
1003
}
(-)a/Koha/Database.pm (-1 / +1 lines)
Lines 70-76 sub _new_schema { Link Here
70
70
71
71
72
    my ( %encoding_attr, $encoding_query, $tz_query, $sql_mode_query );
72
    my ( %encoding_attr, $encoding_query, $tz_query, $sql_mode_query );
73
    my $tz = $ENV{TZ};
73
    my $tz = C4::Context->timezone;
74
    if ( $db_driver eq 'mysql' ) {
74
    if ( $db_driver eq 'mysql' ) {
75
        %encoding_attr = ( mysql_enable_utf8 => 1 );
75
        %encoding_attr = ( mysql_enable_utf8 => 1 );
76
        $encoding_query = "set NAMES 'utf8mb4'";
76
        $encoding_query = "set NAMES 'utf8mb4'";
(-)a/t/timezones.t (-1 / +25 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
3
use C4::Context;
4
5
use Test::More tests => 3;
6
use t::lib::Mocks;
7
8
$ENV{TZ} = q{};
9
t::lib::Mocks::mock_config( 'timezone', q{} );
10
is( C4::Context->timezone, 'local',
11
    'Got local timezone with no env or config timezone set' );
12
13
$ENV{TZ} = 'Antarctica/Macquarie';
14
is(
15
    C4::Context->timezone,
16
    'Antarctica/Macquarie',
17
    'Got correct timezone using ENV, overrides local time'
18
);
19
20
t::lib::Mocks::mock_config( 'timezone', 'Antarctica/South_Pole' );
21
is(
22
    C4::Context->timezone,
23
    'Antarctica/South_Pole',
24
    'Got correct timezone using config, overrides env'
25
);

Return to bug 20123