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 );
72
    my ( %encoding_attr, $encoding_query, $tz_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 'utf8'";
76
        $encoding_query = "set NAMES 'utf8'";
(-)a/t/timezones.t (-1 / +19 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use DateTime;
3
use DateTime::TimeZone;
4
5
use C4::Context;
6
7
use Test::More tests => 3;
8
9
use t::lib::Mocks;
10
11
$ENV{TZ} = q{};
12
t::lib::Mocks::mock_config( 'timezone', q{} );
13
is( C4::Context->timezone, 'local', 'Got local timezone with no env or config timezone set' );
14
15
$ENV{TZ} = 'Antarctica/Macquarie';
16
is( C4::Context->timezone, 'Antarctica/Macquarie', 'Got correct timezone using ENV, overrides local time' );
17
18
t::lib::Mocks::mock_config( 'timezone', 'Antarctica/South_Pole' );
19
is( C4::Context->timezone, 'Antarctica/South_Pole', 'Got correct timezone using config, overrides env' );

Return to bug 20123