From 31cecd3aa9157df33e74fde2fe51203acaf51977 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 2 Dec 2013 17:21:13 +0100 Subject: [PATCH] Bug 11148: Followup only display the hours unless "23:59" --- Koha/DateUtils.pm | 48 +++++++++++++++++++++++++----------------------- opac/opac-reserve.pl | 2 +- t/DateUtils.t | 15 ++++++++++++++- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index f7d6fe1..c7c5651 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -129,32 +129,34 @@ sub output_pref { my $time_format = $force_time || C4::Context->preference('TimeFormat'); my $time = ( $time_format eq '12hr' ) ? '%I:%M %p' : '%H:%M'; + my $date = do { + given ($pref) { + when (/^iso/) { + $dateonly + ? $dt->strftime("%Y-%m-%d") + : $dt->strftime("%Y-%m-%d $time"); + } + when (/^metric/) { + $dateonly + ? $dt->strftime("%d/%m/%Y") + : $dt->strftime("%d/%m/%Y $time"); + } + when (/^us/) { + $dateonly + ? $dt->strftime("%m/%d/%Y") + : $dt->strftime("%m/%d/%Y $time"); + } + default { + $dateonly + ? $dt->strftime("%Y-%m-%d") + : $dt->strftime("%Y-%m-%d $time"); + } - given ($pref) { - when (/^iso/) { - return $dateonly - ? $dt->strftime("%Y-%m-%d") - : $dt->strftime("%Y-%m-%d $time"); - } - when (/^metric/) { - return $dateonly - ? $dt->strftime("%d/%m/%Y") - : $dt->strftime("%d/%m/%Y $time"); - } - when (/^us/) { - - return $dateonly - ? $dt->strftime("%m/%d/%Y") - : $dt->strftime("%m/%d/%Y $time"); - } - default { - return $dateonly - ? $dt->strftime("%Y-%m-%d") - : $dt->strftime("%Y-%m-%d $time"); } + }; - } - return; + $date =~ s| 23:59$||; + return $date; } =head2 format_sqldatetime diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index c07a648..86e68e6 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -426,7 +426,7 @@ foreach my $biblioNum (@biblionumbers) { # change the background color. my $issues= GetItemIssue($itemNum); if ( $issues->{'date_due'} ) { - $itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issues->{date_due}, 'sql'), dateonly => 1 }); + $itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issues->{date_due}, 'sql') }); $itemLoopIter->{backgroundcolor} = 'onloan'; } diff --git a/t/DateUtils.t b/t/DateUtils.t index 00dc402..ef1cce9 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 => 27; +use Test::More tests => 29; use Test::MockModule; BEGIN { use_ok('Koha::DateUtils'); } @@ -108,3 +108,16 @@ 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' ); + +$dt = DateTime->new( + year => 2013, + month => 12, + day => 11, + hour => 23, + minute => 59, +); +$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' }); +cmp_ok $date_string, 'eq', '11/12/2013', 'metric output'; + +$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr', dateonly => 1 }); +cmp_ok $date_string, 'eq', '11/12/2013', 'metric output'; -- 1.7.10.4