From: Colin Campbell Date: Thu, 23 Jun 2011 10:58:09 +0000 (+0100) Subject: Bug 5549 : Format due dates in opac X-Git-Url: http://git.rot13.org/?p=koha.git;a=commitdiff_plain;h=b946d16ec51467ffd4fd0f710b45e822b980033d Bug 5549 : Format due dates in opac Further change to ensure that where dates are formatted from the db form the duedate loses the 23:59 --- diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 35043ffa0d..e2e92bd494 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -26,7 +26,9 @@ use C4::Context; use base 'Exporter'; use version; our $VERSION = qv('1.0.0'); -our @EXPORT = (qw( dt_from_string output_pref format_sqldatetime output_pref_due )); +our @EXPORT = ( + qw( dt_from_string output_pref format_sqldatetime output_pref_due format_sqlduedatetime) +); =head1 DateUtils @@ -138,7 +140,7 @@ the time portion is stripped if it is '23:59' sub output_pref_due { my $disp_str = output_pref(@_); - $disp_str=~s/ 23:59//; + $disp_str =~ s/ 23:59//; return $disp_str; } @@ -162,4 +164,24 @@ 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 + if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) { + my $dt = dt_from_string( $str, 'sql' ); + $dt->truncate( to => 'minutes' ); + return output_pref_due( $dt, $force_pref ); + } + return q{}; +} + 1; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index b5702159db..b45250dc37 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -495,7 +495,7 @@ for my $itm (@items) { # I can't actually find any case in which this is defined. --amoore 2008-12-09 $itm->{ $itm->{'publictype'} } = 1; } - $itm->{datedue} = format_sqldatetime($itm->{datedue}); + $itm->{datedue} = format_sqlduedatetime($itm->{datedue}); $itm->{datelastseen} = format_date($itm->{datelastseen}); # get collection code description, too diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index 5a10fb5b82..6872660c30 100755 --- a/opac/opac-readingrecord.pl +++ b/opac/opac-readingrecord.pl @@ -89,7 +89,7 @@ foreach my $issue (@{$issues} ) { $line{title} = $issue->{'title'}; $line{author} = $issue->{'author'}; $line{itemcallnumber} = $issue->{'itemcallnumber'}; - $line{date_due} = format_sqldatetime( $issue->{date_due} ); + $line{date_due} = format_sqlduedatetime( $issue->{date_due} ); $line{returndate} = format_sqldatetime( $issue->{returndate} ); $line{volumeddesc} = $issue->{'volumeddesc'}; $issue->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $issue->{'itype'} : $issue->{'itemtype'}; diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 04b66f6ce0..bcf623da2d 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -398,7 +398,7 @@ foreach my $biblioNum (@biblionumbers) { # change the background color. my $issues= GetItemIssue($itemNum); if ( $issues->{'date_due'} ) { - $itemLoopIter->{dateDue} = format_sqldatetime$issues->{date_due}); + $itemLoopIter->{dateDue} = format_sqlduedatetime$issues->{date_due}); $itemLoopIter->{backgroundcolor} = 'onloan'; } diff --git a/t/DateUtils.t b/t/DateUtils.t index 82d499f182..dbf38a6a68 100755 --- a/t/DateUtils.t +++ b/t/DateUtils.t @@ -5,7 +5,7 @@ use DateTime; use DateTime::TimeZone; use C4::Context; -use Test::More tests => 23; +use Test::More tests => 25; BEGIN { use_ok('Koha::DateUtils'); } @@ -34,12 +34,14 @@ $date_string = output_pref( $dt, 'metric' ); cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output'; $date_string = output_pref_due( $dt, 'metric' ); -cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'output_pref_due preserves non midnight HH:SS'; +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, 'metric' ); -cmp_ok $date_string, 'eq', '16/06/2011', 'output_pref_due truncates HH:SS at midnight'; +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 ); @@ -82,3 +84,14 @@ 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' ); +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' ); +cmp_ok( $formatted, 'eq', '16/06/2011', + 'format_sqlduedatetime conversion for daily loans' );