Bugzilla – Attachment 25974 Details for
Bug 11148
Two routines are useless in Koha::DateUtils
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11148: Add a as_due_date parameter to the output_pref routine
Bug-11148-Add-a-asduedate-parameter-to-the-outputp.patch (text/plain), 5.11 KB, created by
Jonathan Druart
on 2014-03-10 08:51:57 UTC
(
hide
)
Description:
Bug 11148: Add a as_due_date parameter to the output_pref routine
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-03-10 08:51:57 UTC
Size:
5.11 KB
patch
obsolete
>From bf005f12f045e4c2a48603e0966803787c2ce5f6 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Mon, 2 Dec 2013 17:21:13 +0100 >Subject: [PATCH] Bug 11148: Add a as_due_date parameter to the output_pref > routine > >This parameter is a boolean, if true, the hours won't be displayed if >the time is 23:59 (24hr format) or 11:59 PM (12hr format). >--- > Koha/DateUtils.pm | 23 +++++++++++++++-------- > opac/opac-reserve.pl | 2 +- > t/DateUtils.t | 22 +++++++++++++++++++++- > 3 files changed, 37 insertions(+), 10 deletions(-) > >diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm >index 85c90d6..b372a3a 100644 >--- a/Koha/DateUtils.pm >+++ b/Koha/DateUtils.pm >@@ -93,7 +93,7 @@ s/(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})/$1-$2-$3T$4:$5:$6/; > > =head2 output_pref > >-$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] }); >+$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1, as_due_date => 0|1 ] }); > $date_string = output_pref( $dt ); > > Returns a string containing the time & date formatted as per the C4::Context setting, >@@ -110,12 +110,13 @@ should be returned without the time. > > sub output_pref { > my $params = shift; >- my ( $dt, $force_pref, $force_time, $dateonly ); >+ my ( $dt, $force_pref, $force_time, $dateonly, $as_due_date ); > if ( ref $params eq 'HASH' ) { > $dt = $params->{dt}; > $force_pref = $params->{dateformat}; # if testing we want to override Context > $force_time = $params->{timeformat}; > $dateonly = $params->{dateonly} || 0; # if you don't want the hours and minutes >+ $as_due_date = $params->{as_due_date} || 0; # don't display the hours and minutes if eq to 23:59 or 11:59 (depending the TimeFormat value) > } else { > $dt = $params; > } >@@ -129,29 +130,35 @@ 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; > if ( $pref =~ m/^iso/ ) { >- return $dateonly >+ $date = $dateonly > ? $dt->strftime("%Y-%m-%d") > : $dt->strftime("%Y-%m-%d $time"); > } > elsif ( $pref =~ m/^metric/ ) { >- return $dateonly >+ $date = $dateonly > ? $dt->strftime("%d/%m/%Y") > : $dt->strftime("%d/%m/%Y $time"); > } > elsif ( $pref =~ m/^us/ ) { >- >- return $dateonly >+ $date = $dateonly > ? $dt->strftime("%m/%d/%Y") > : $dt->strftime("%m/%d/%Y $time"); > } > else { >- return $dateonly >+ $date = $dateonly > ? $dt->strftime("%Y-%m-%d") > : $dt->strftime("%Y-%m-%d $time"); > } > >+ if ( $as_due_date ) { >+ $time_format eq '12hr' >+ ? $date =~ s| 11:59 PM$|| >+ : $date =~ s| 23:59$||; >+ } >+ >+ return $date; > } > > =head2 format_sqldatetime >diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl >index 9649231..473ead8 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'), as_due_date => 1 }); > $itemLoopIter->{backgroundcolor} = 'onloan'; > } > >diff --git a/t/DateUtils.t b/t/DateUtils.t >index 00dc402..de34d70 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 => 31; > use Test::MockModule; > > BEGIN { use_ok('Koha::DateUtils'); } >@@ -108,3 +108,23 @@ 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' ); >+ >+# Test the as_due_date parameter >+$dt = DateTime->new( >+ year => 2013, >+ month => 12, >+ day => 11, >+ hour => 23, >+ minute => 59, >+); >+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr', as_due_date => 1 }); >+cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date with hours and timeformat 24hr'; >+ >+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr', dateonly => 1, as_due_date => 1}); >+cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date without hours and timeformat 24hr'; >+ >+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '12hr', as_due_date => 1 }); >+cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date with hours and timeformat 12hr'; >+ >+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '12hr', dateonly => 1, as_due_date => 1}); >+cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date without hours and timeformat 12hr'; >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11148
:
22470
|
22759
|
23092
|
23239
|
23253
|
24219
|
25973
|
25974
|
25975
|
26212
|
26213
|
26214
|
26278
|
26279
|
26280