Bug 5549 : Don't confuse the users with an irrelevant time
authorColin Campbell <colin.campbell@ptfs-europe.com>
Thu, 23 Jun 2011 10:35:35 +0000 (11:35 +0100)
committerChris Cormack <chrisc@catalyst.net.nz>
Tue, 20 Mar 2012 00:24:32 +0000 (13:24 +1300)
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
opac/opac-user.pl
t/DateUtils.t

index 938dc4a..35043ff 100644 (file)
@@ -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 );
index d49f778..1162314 100755 (executable)
@@ -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++;
                
index 9569cfe..82d499f 100755 (executable)
@@ -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' );