Bug 11148: remove two superflous routines from Koha::DateUtils

There are 2 useless routines in the Koha::DateUtils
module:output_pref_due and format_sqlduedatetime. We can call
output_pref and format_datetime with dateonly = 0.

format_sqlduedatetime is only used in one place: opac-reserve.pl

Test plan:
1/ Verify on the opac-reserve.pl page that the date is correctly
displayed for for onloan items (you should use the "specific copy"
feature).
2/ Launch prove t/DateUtils.t UT file and verify all UT pass.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Due date on opac-reserve shown correctly. Unit tests pass.
Did a grep on both function names.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
No references to subs found. Passes koha-qa.pl, t and xt

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Jonathan Druart 2013-10-28 15:10:26 +01:00 committed by Galen Charlton
parent f140207808
commit b9492e73f5
3 changed files with 3 additions and 77 deletions

View File

@ -27,7 +27,7 @@ use base 'Exporter';
use version; our $VERSION = qv('1.0.0');
our @EXPORT = (
qw( dt_from_string output_pref format_sqldatetime output_pref_due format_sqlduedatetime)
qw( dt_from_string output_pref format_sqldatetime )
);
=head1 DateUtils
@ -154,31 +154,6 @@ sub output_pref {
}
=head2 output_pref_due
$date_string = output_pref_due({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] });
$date_string = output_pref_due($dt);
Returns a string containing the time & date formatted as per the C4::Context setting
This routine can either be passed a DateTime object or or a hashref. If it is
passed a hashref, the expected keys are a mandatory 'dt' for the DateTime,
an optional 'dateformat' to override the dateformat system preference, an
optional 'timeformat' to override the TimeFormat system preference value,
and an optional 'dateonly' to specify that only the formatted date string
should be returned without the time.
This is effectively a wrapper around output_pref for due dates;
the time portion is stripped if it is '23:59'
=cut
sub output_pref_due {
my $disp_str = output_pref(@_);
$disp_str =~ s/ 23:59//;
return $disp_str;
}
=head2 format_sqldatetime
$string = format_sqldatetime( $string_as_returned_from_db );
@ -208,32 +183,4 @@ sub format_sqldatetime {
return q{};
}
=head2 format_sqlduedatetime
$string = format_sqldatetime( $string_as_returned_from_db );
a convenience routine for calling dt_from_string and formatting the result
with output_pref_due as it is a frequent activity in scripts
=cut
sub format_sqlduedatetime {
my $str = shift;
my $force_pref = shift; # if testing we want to override Context
my $force_time = shift;
my $dateonly = shift;
if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
my $dt = dt_from_string( $str, 'sql' );
$dt->truncate( to => 'minute' );
return output_pref_due({
dt => $dt,
dateformat => $force_pref,
timeformat => $force_time,
dateonly => $dateonly
});
}
return q{};
}
1;

View File

@ -426,7 +426,7 @@ foreach my $biblioNum (@biblionumbers) {
# change the background color.
my $issues= GetItemIssue($itemNum);
if ( $issues->{'date_due'} ) {
$itemLoopIter->{dateDue} = format_sqlduedatetime($issues->{date_due});
$itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issues->{date_due}, 'sql'), dateonly => 1 });
$itemLoopIter->{backgroundcolor} = 'onloan';
}

View File

@ -5,7 +5,7 @@ use DateTime;
use DateTime::TimeZone;
use C4::Context;
use Test::More tests => 31;
use Test::More tests => 27;
use Test::MockModule;
BEGIN { use_ok('Koha::DateUtils'); }
@ -67,16 +67,6 @@ cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => 'notime', dateonly => 1 });
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)';
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
cmp_ok $date_string, 'eq', '16/06/2011 12:00',
'output_pref_due preserves non midnight HH:SS';
$dt->set_hour(23);
$dt->set_minute(59);
$date_string = output_pref_due({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
cmp_ok $date_string, 'eq', '16/06/2011',
'output_pref_due truncates HH:SS at midnight';
my $dear_dirty_dublin = DateTime::TimeZone->new( name => 'Europe/Dublin' );
my $new_dt = dt_from_string( '16/06/2011', 'metric', $dear_dirty_dublin );
isa_ok( $new_dt, 'DateTime', 'Create DateTime with different timezone' );
@ -118,14 +108,3 @@ cmp_ok( $formatted, 'eq', '16/06/2011 12:00', 'format_sqldatetime conversion' );
$formatted = format_sqldatetime( undef, 'metric' );
cmp_ok( $formatted, 'eq', q{},
'format_sqldatetime formats undef as empty string' );
$formatted = format_sqlduedatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
cmp_ok(
$formatted, 'eq',
'16/06/2011 12:00',
'format_sqlduedatetime conversion for hourly loans'
);
$formatted = format_sqlduedatetime( '2011-06-16 23:59:07', 'metric', '24hr' );
cmp_ok( $formatted, 'eq', '16/06/2011',
'format_sqlduedatetime conversion for daily loans' );