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

(-)a/Koha/DateUtils.pm (+9 lines)
Lines 139-150 sub dt_from_string { Link Here
139
                    :
139
                    :
140
                    (?<second>\d{2})
140
                    (?<second>\d{2})
141
                )?
141
                )?
142
                (
143
                    \s
144
                    (?<ampm>\w{2})
145
                )?
142
            )?
146
            )?
143
    |xms;
147
    |xms;
144
    $regex .= $time_re;
148
    $regex .= $time_re;
145
    $fallback_re .= $time_re;
149
    $fallback_re .= $time_re;
146
150
147
    my %dt_params;
151
    my %dt_params;
152
    my $ampm;
148
    if ( $date_string =~ $regex ) {
153
    if ( $date_string =~ $regex ) {
149
        %dt_params = (
154
        %dt_params = (
150
            year   => $+{year},
155
            year   => $+{year},
Lines 154-159 sub dt_from_string { Link Here
154
            minute => $+{minute},
159
            minute => $+{minute},
155
            second => $+{second},
160
            second => $+{second},
156
        );
161
        );
162
        $ampm = $+{ampm};
157
    } elsif ( $date_string =~ $fallback_re ) {
163
    } elsif ( $date_string =~ $fallback_re ) {
158
        %dt_params = (
164
        %dt_params = (
159
            year   => $+{year},
165
            year   => $+{year},
Lines 163-168 sub dt_from_string { Link Here
163
            minute => $+{minute},
169
            minute => $+{minute},
164
            second => $+{second},
170
            second => $+{second},
165
        );
171
        );
172
        $ampm = $+{ampm};
166
    }
173
    }
167
    else {
174
    else {
168
        die "The given date ($date_string) does not match the date format ($date_format)";
175
        die "The given date ($date_string) does not match the date format ($date_format)";
Lines 176-181 sub dt_from_string { Link Here
176
    $dt_params{minute} = 00 unless defined $dt_params{minute};
183
    $dt_params{minute} = 00 unless defined $dt_params{minute};
177
    $dt_params{second} = 00 unless defined $dt_params{second};
184
    $dt_params{second} = 00 unless defined $dt_params{second};
178
185
186
    $dt_params{hour} += 12 if $ampm && $ampm eq 'PM';
187
179
    my $dt = eval {
188
    my $dt = eval {
180
        DateTime->new(
189
        DateTime->new(
181
            %dt_params,
190
            %dt_params,
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 170-176 for my $barcode ( @$barcodes ) { Link Here
170
170
171
my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
171
my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
172
my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
172
my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
173
$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso', timeformat => '24hr' }); }
173
$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso' }); }
174
    if ( $duedatespec );
174
    if ( $duedatespec );
175
my $restoreduedatespec  = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
175
my $restoreduedatespec  = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
176
if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
176
if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
(-)a/t/DateUtils.t (-2 / +12 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 => 72;
7
use Test::More tests => 76;
8
8
9
use Test::MockModule;
9
use Test::MockModule;
10
use Test::Warn;
10
use Test::Warn;
Lines 249-254 is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string s Link Here
249
$dt = dt_from_string('2015-01-31 01:02:03');
249
$dt = dt_from_string('2015-01-31 01:02:03');
250
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' );
250
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' );
251
251
252
# 12hr format
253
$dt = dt_from_string('2015-01-31 01:02 AM');
254
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string ' );
255
$dt = dt_from_string('2015-01-31 01:02:03 AM');
256
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string ' );
257
$dt = dt_from_string('2015-01-31 01:02 PM');
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');
260
is( output_pref( {dt => $dt} ), '31/01/2015 13:02', 'dt_from_string ' );
261
262
252
# output_pref with no parameters, single parameter (no hash)
263
# output_pref with no parameters, single parameter (no hash)
253
is( output_pref(), undef, 'Call output_pref without parameters' );
264
is( output_pref(), undef, 'Call output_pref without parameters' );
254
try {
265
try {
255
- 

Return to bug 25133