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

(-)a/Koha/Template/Plugin/KohaTimes.pm (-1 / +1 lines)
Lines 26-32 sub filter { Link Here
26
    return "" unless $text;
26
    return "" unless $text;
27
27
28
    my ( $hours, $minutes, $seconds ) = split( ':', $text );
28
    my ( $hours, $minutes, $seconds ) = split( ':', $text );
29
    if ( C4::Context->preference('TimeFormat') == "12hr" ) {
29
    if ( C4::Context->preference('TimeFormat') eq "12hr" ) {
30
        my $ampm = ( $hours >= 12 ) ? 'pm' : 'am';
30
        my $ampm = ( $hours >= 12 ) ? 'pm' : 'am';
31
        $hours = ( $hours == 0 ) ? "12"            : $hours;
31
        $hours = ( $hours == 0 ) ? "12"            : $hours;
32
        $hours = ( $hours > 12 ) ? ( $hours - 12 ) : $hours;
32
        $hours = ( $hours > 12 ) ? ( $hours - 12 ) : $hours;
(-)a/t/db_dependent/Template/Plugin/KohaTimes.t (-1 / +38 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use C4::Context;
6
7
use Test::MockModule;
8
use Test::More tests => 5;
9
use t::lib::Mocks;
10
11
BEGIN {
12
    use_ok('Koha::Template::Plugin::KohaTimes');
13
}
14
15
my $module_context = Test::MockModule->new('C4::Context');
16
17
my $test_time     = "21:45:32";
18
my $test_midnight = "00:00:00";
19
20
my $context = C4::Context->new();
21
22
my $filter = Koha::Template::Plugin::KohaTimes->new();
23
ok( $filter, "new()" );
24
25
t::lib::Mocks::mock_preference( "TimeFormat", '24hr' );
26
$context->clear_syspref_cache();
27
28
my $filtered_time = $filter->filter($test_time);
29
is( $filtered_time, "21:45", "24-hour conversion" ) or diag("24-hour conversion failed");
30
31
t::lib::Mocks::mock_preference( "TimeFormat", '12hr' );
32
$context->clear_syspref_cache();
33
34
$filtered_time = $filter->filter($test_time);
35
is( $filtered_time, "09:45 pm", "12-hour conversion" ) or diag("12-hour conversion failed");
36
37
$filtered_time = $filter->filter($test_midnight);
38
is( $filtered_time, "12:00 am", "12-hour midnight/AM conversion" ) or diag("12-hour midnight/AM conversion failed");

Return to bug 38043