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

(-)a/t/Koha/DateTime/Format/SQL.t (-1 / +84 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use DateTime::TimeZone;
5
use Test::Exception;
6
use Test::MockModule;
7
use Test::More;
8
9
BEGIN { use_ok('Koha::DateTime::Format::SQL'); }
10
11
my $local_timezone = DateTime::TimeZone->new( name => 'local' );
12
my $koha_config_mock = Test::MockModule->new('Koha::Config');
13
my $config = { timezone => '' };
14
$koha_config_mock->mock('get', sub { $config->{$_[1]} });
15
16
subtest 'normal datetime, no timezone configured' => sub {
17
    plan tests => 7;
18
19
    $config->{timezone} = '';
20
    $Koha::DateTime::Format::SQL::timezone = undef;
21
22
    my $dt = Koha::DateTime::Format::SQL->parse_datetime('2024-01-02 10:11:12');
23
24
    is( $dt->year,   2024 );
25
    is( $dt->month,  1 );
26
    is( $dt->day,    2 );
27
    is( $dt->hour,   10 );
28
    is( $dt->minute, 11 );
29
    is( $dt->second, 12 );
30
    is( $dt->time_zone->name, $local_timezone->name );
31
};
32
33
subtest 'normal datetime, with timezone configured' => sub {
34
    plan tests => 7;
35
36
    $config->{timezone} = 'Pacific/Auckland';
37
    $Koha::DateTime::Format::SQL::timezone = undef;
38
39
    my $dt = Koha::DateTime::Format::SQL->parse_datetime('2024-01-02 10:11:12');
40
41
    is( $dt->year,   2024 );
42
    is( $dt->month,  1 );
43
    is( $dt->day,    2 );
44
    is( $dt->hour,   10 );
45
    is( $dt->minute, 11 );
46
    is( $dt->second, 12 );
47
    is( $dt->time_zone->name, 'Pacific/Auckland' );
48
};
49
50
subtest 'infinite datetime, no timezone configured' => sub {
51
    plan tests => 7;
52
53
    $config->{timezone} = '';
54
    $Koha::DateTime::Format::SQL::timezone = undef;
55
56
    my $dt = Koha::DateTime::Format::SQL->parse_datetime('9999-01-02 10:11:12');
57
58
    is( $dt->year,   9999 );
59
    is( $dt->month,  1 );
60
    is( $dt->day,    2 );
61
    is( $dt->hour,   10 );
62
    is( $dt->minute, 11 );
63
    is( $dt->second, 12 );
64
    is( $dt->time_zone->name, 'floating' );
65
};
66
67
subtest 'normal datetime, with timezone configured' => sub {
68
    plan tests => 7;
69
70
    $config->{timezone} = 'Pacific/Auckland';
71
    $Koha::DateTime::Format::SQL::timezone = undef;
72
73
    my $dt = Koha::DateTime::Format::SQL->parse_datetime('9999-01-02 10:11:12');
74
75
    is( $dt->year,   9999 );
76
    is( $dt->month,  1 );
77
    is( $dt->day,    2 );
78
    is( $dt->hour,   10 );
79
    is( $dt->minute, 11 );
80
    is( $dt->second, 12 );
81
    is( $dt->time_zone->name, 'floating' );
82
};
83
84
done_testing;

Return to bug 36486