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

(-)a/Koha/DateUtils.pm (-1 / +8 lines)
Lines 183-189 sub dt_from_string { Link Here
183
    $dt_params{minute} = 00 unless defined $dt_params{minute};
183
    $dt_params{minute} = 00 unless defined $dt_params{minute};
184
    $dt_params{second} = 00 unless defined $dt_params{second};
184
    $dt_params{second} = 00 unless defined $dt_params{second};
185
185
186
    $dt_params{hour} += 12 if $ampm && $ampm eq 'PM';
186
    if ( $ampm ) {
187
        if ( $ampm eq 'AM' ) {
188
            $dt_params{hour} = 00 if $dt_params{hour} == 12;
189
        } elsif ( $dt_params{hour} != 12 ) { # PM
190
            $dt_params{hour} += 12;
191
            $dt_params{hour} = 00 if $dt_params{hour} == 24;
192
        }
193
    }
187
194
188
    my $dt = eval {
195
    my $dt = eval {
189
        DateTime->new(
196
        DateTime->new(
(-)a/t/DateUtils.t (-3 / +25 lines)
Lines 4-10 use DateTime::TimeZone; Link Here
4
4
5
use C4::Context;
5
use C4::Context;
6
6
7
use Test::More tests => 76;
7
use Test::More tests => 79;
8
8
9
use Test::MockModule;
9
use Test::MockModule;
10
use Test::Warn;
10
use Test::Warn;
Lines 258-264 $dt = dt_from_string('2015-01-31 01:02 PM'); Link Here
258
is( output_pref( {dt => $dt} ), '31/01/2015 13:02', 'dt_from_string ' );
258
is( output_pref( {dt => $dt} ), '31/01/2015 13:02', 'dt_from_string ' );
259
$dt = dt_from_string('2015-01-31 01:02:03 PM');
259
$dt = dt_from_string('2015-01-31 01:02:03 PM');
260
is( output_pref( {dt => $dt} ), '31/01/2015 13:02', 'dt_from_string ' );
260
is( output_pref( {dt => $dt} ), '31/01/2015 13:02', 'dt_from_string ' );
261
261
$dt = dt_from_string('2015-01-31 12:02 AM');
262
is( output_pref( {dt => $dt} ), '31/01/2015 00:02', 'dt_from_string ' );
263
$dt = dt_from_string('2015-01-31 12:02:03 AM');
264
is( output_pref( {dt => $dt} ), '31/01/2015 00:02', 'dt_from_string ' );
265
266
subtest 'TimeFormat 12hr' => sub {
267
    plan tests => 4;
268
269
    $dt = DateTime->new( year => 2020, month => 5, day => 28, hour => 12, minute => 49 );
270
    t::lib::Mocks::mock_preference('TimeFormat', '12hr');
271
    my $output = output_pref({ dt => $dt, dateformat => 'iso' });
272
    $dt = dt_from_string( $output, 'iso' );
273
    is( output_pref( {dt => $dt} ), '28/05/2020 12:49 PM' );
274
    t::lib::Mocks::mock_preference('TimeFormat', '24hr');
275
    is( output_pref( {dt => $dt} ), '28/05/2020 12:49' );
276
277
    $dt = DateTime->new( year => 2020, month => 5, day => 28, hour => 0, minute => 49 );
278
    t::lib::Mocks::mock_preference('TimeFormat', '12hr');
279
    $output = output_pref({ dt => $dt, dateformat => 'iso' });
280
    $dt = dt_from_string( $output, 'iso' );
281
    is( output_pref( {dt => $dt} ), '28/05/2020 12:49 AM' );
282
    t::lib::Mocks::mock_preference('TimeFormat', '24hr');
283
    is( output_pref( {dt => $dt} ), '28/05/2020 00:49' );
284
};
262
285
263
# output_pref with no parameters, single parameter (no hash)
286
# output_pref with no parameters, single parameter (no hash)
264
is( output_pref(), undef, 'Call output_pref without parameters' );
287
is( output_pref(), undef, 'Call output_pref without parameters' );
265
- 

Return to bug 25617