From 372216b9c845660276fc0a97ece8ee4836c79da0 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Thu, 23 Jun 2011 11:35:35 +0100 Subject: [PATCH] Bug 5549 : Don't confuse the users with an irrelevant time If the book is due at 23:59 the due time is irrelevant and potentially confusing to the user add a DateUtils routine that strips that off the returned display date --- Koha/DateUtils.pm | 22 +++++++++++++++++++++- opac/opac-user.pl | 2 +- t/DateUtils.t | 10 +++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 938dc4a454..35043ffa0d 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -26,7 +26,7 @@ use C4::Context; use base 'Exporter'; use version; our $VERSION = qv('1.0.0'); -our @EXPORT = (qw( dt_from_string output_pref format_sqldatetime)); +our @EXPORT = (qw( dt_from_string output_pref format_sqldatetime output_pref_due )); =head1 DateUtils @@ -122,6 +122,26 @@ sub output_pref { return; } +=head2 output_pref_due + +$date_string = output_pref_due($dt, [$format] ); + +Returns a string containing the time & date formatted as per the C4::Context setting + +A second parameter allows overriding of the syspref value. This is for testing only +In usage use the DateTime objects own methods for non standard formatting + +This is effectivelyt 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 ); diff --git a/opac/opac-user.pl b/opac/opac-user.pl index d49f7789a3..11623141aa 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -201,7 +201,7 @@ if ($issues){ $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); $issue->{'description'} = $itemtypes->{$itemtype}->{'description'}; } - $issue->{date_due} = output_pref($issue->{date_due}); + $issue->{date_due} = output_pref_due($issue->{date_due}); push @issuedat, $issue; $count++; diff --git a/t/DateUtils.t b/t/DateUtils.t index 9569cfe4cb..82d499f182 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 => 21; # last test to print +use Test::More tests => 23; BEGIN { use_ok('Koha::DateUtils'); } @@ -33,6 +33,14 @@ cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output'; $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'; + +$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'; + 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' ); -- 2.20.1