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

(-)a/Koha/DateUtils.pm (-4 / +10 lines)
Lines 16-26 package Koha::DateUtils; Link Here
16
# Koha; if not, write to the Free Software Foundation, Inc.,
16
# Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
19
use strict;
19
use Modern::Perl;
20
use warnings;
21
use 5.010;
22
use DateTime;
20
use DateTime;
23
use C4::Context;
21
use C4::Context;
22
use Carp;
24
23
25
use base 'Exporter';
24
use base 'Exporter';
26
use version; our $VERSION = qv('1.0.0');
25
use version; our $VERSION = qv('1.0.0');
Lines 189-197 should be returned without the time. Link Here
189
188
190
sub output_pref {
189
sub output_pref {
191
    my $params = shift;
190
    my $params = shift;
192
    my ( $dt, $force_pref, $force_time, $dateonly, $as_due_date );
191
    my ( $dt, $str, $force_pref, $force_time, $dateonly, $as_due_date );
193
    if ( ref $params eq 'HASH' ) {
192
    if ( ref $params eq 'HASH' ) {
194
        $dt         = $params->{dt};
193
        $dt         = $params->{dt};
194
        $str        = $params->{str};
195
        $force_pref = $params->{dateformat};         # if testing we want to override Context
195
        $force_pref = $params->{dateformat};         # if testing we want to override Context
196
        $force_time = $params->{timeformat};
196
        $force_time = $params->{timeformat};
197
        $dateonly   = $params->{dateonly} || 0;    # if you don't want the hours and minutes
197
        $dateonly   = $params->{dateonly} || 0;    # if you don't want the hours and minutes
Lines 200-205 sub output_pref { Link Here
200
        $dt = $params;
200
        $dt = $params;
201
    }
201
    }
202
202
203
    carp "output_pref should not be called with both dt and str parameters"
204
        and return
205
            if $dt and $str;
206
207
    $dt = eval { dt_from_string( $str ) } if $str;
208
203
    return unless defined $dt;
209
    return unless defined $dt;
204
210
205
    # FIXME: see bug 13242 => no TZ for dates 'infinite'
211
    # FIXME: see bug 13242 => no TZ for dates 'infinite'
(-)a/t/DateUtils.t (-2 / +9 lines)
Lines 3-10 use DateTime; Link Here
3
use DateTime::TimeZone;
3
use DateTime::TimeZone;
4
4
5
use C4::Context;
5
use C4::Context;
6
use Test::More tests => 55;
6
use Test::More tests => 58;
7
use Test::MockModule;
7
use Test::MockModule;
8
use Test::Warn;
8
use Time::HiRes qw/ gettimeofday /;
9
use Time::HiRes qw/ gettimeofday /;
9
use t::lib::Mocks;
10
use t::lib::Mocks;
10
11
Lines 215-217 is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string s Link Here
215
# fallback
216
# fallback
216
$dt = dt_from_string('2015-01-31 01:02:03');
217
$dt = dt_from_string('2015-01-31 01:02:03');
217
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' );
218
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' );
218
- 
219
220
# output_pref with str parameter
221
is( output_pref( { 'str' => $testdate_iso,  dateformat => 'iso', dateonly => 1 } ), $testdate_iso, 'output_pref should handle correctly the iso parameter' );
222
is( output_pref( { 'str' => 'invalid_date', dateformat => 'iso', dateonly => 1 } ), undef,         'output_pref should return undef if an invalid date is passed' );
223
warning_is { output_pref( { 'str' => $testdate_iso, dt => $dt, dateformat => 'iso', dateonly => 1 } ) }
224
           { carped => 'output_pref should not be called with both dt and str parameters' },
225
           'output_pref should carp if str and dt parameters are passed together';

Return to bug 15166