Bugzilla – Attachment 18597 Details for
Bug 10380
output_pref should use a hashref for parameters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 10380: Change prototype for output_pref routine
SIGNED-OFF-Bug-10380-Change-prototype-for-outputpr.patch (text/plain), 9.77 KB, created by
Srdjan Jankovic
on 2013-06-03 03:40:24 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 10380: Change prototype for output_pref routine
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2013-06-03 03:40:24 UTC
Size:
9.77 KB
patch
obsolete
>From 6deca4e9d55a3d661a866f60bd7ef425d8864909 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Thu, 30 May 2013 14:32:33 +0200 >Subject: [PATCH] [SIGNED-OFF] Bug 10380: Change prototype for output_pref > routine > >Koha::DateUtils::output_pref takes 4 parameters and the last one is a >boolean, so some calls are: > output_pref($dt, undef, undef, 1) > >This patch changes it prototype to > output_pref({ > dt => $dt, > dateformat => $dateformat, > timeformat => $timeformat, > dateonly => $boolean > }); >an alternative is to call the output_pref routine with a datetime >object, without using an hashref: > output_pref($dt); > >Signed-off-by: Srdjan <srdjan@catalyst.net.nz> >--- > C4/Letters.pm | 4 ++-- > C4/Reserves.pm | 2 +- > Koha/DateUtils.pm | 33 +++++++++++++++++++++++++-------- > Koha/Template/Plugin/KohaDates.pm | 2 +- > acqui/lateorders.pl | 4 ++-- > members/member.pl | 2 +- > t/DateUtils.t | 30 +++++++++++++++++++----------- > 7 files changed, 51 insertions(+), 26 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 0349efe..27814d0 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -612,9 +612,9 @@ sub _parseletter { > > my $dt = dt_from_string(); > $dt->add( days => C4::Context->preference('ReservesMaxPickUpDelay') ); >- $values->{'expirationdate'} = output_pref( $dt, undef, 1 ); >+ $values->{'expirationdate'} = output_pref({ dt => $dt, dateonly => 1 }); > >- $values->{'waitingdate'} = output_pref( dt_from_string( $values->{'waitingdate'} ), undef, 1 ); >+ $values->{'waitingdate'} = output_pref({ dt => dt_from_string( $values->{'waitingdate'} ), dateonly => 1 }); > > } > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index 5ff12e4..b67766b 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -1546,7 +1546,7 @@ be cleared when it is unsuspended. > sub ToggleSuspend { > my ( $borrowernumber, $biblionumber, $suspend_until ) = @_; > >- $suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until ); >+ $suspend_until = output_pref({ dt => dt_from_string( $suspend_until ), dateformat => 'iso' }) if ( $suspend_until ); > > my $do_until = ( $suspend_until ) ? '?' : 'NULL'; > >diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm >index 714b171..5a62307 100644 >--- a/Koha/DateUtils.pm >+++ b/Koha/DateUtils.pm >@@ -93,7 +93,8 @@ 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, [$date_format], [$time_format] ); >+$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] }); >+$date_string = output_pref( $dt ); > > Returns a string containing the time & date formatted as per the C4::Context setting, > or C<undef> if C<undef> was provided. >@@ -109,10 +110,16 @@ If it is not defined, the default value is 0; > =cut > > sub output_pref { >- my $dt = shift; >- my $force_pref = shift; # if testing we want to override Context >- my $force_time = shift; >- my $dateonly = shift || 0; # if you don't want the hours and minutes >+ my $params = shift; >+ my ( $dt, $force_pref, $force_time, $dateonly ); >+ 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 >+ } else { >+ $dt = $params; >+ } > > return unless defined $dt; > >@@ -153,7 +160,7 @@ sub output_pref { > > =head2 output_pref_due > >-$date_string = output_pref_due($dt, [$format] ); >+$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] }); > > Returns a string containing the time & date formatted as per the C4::Context setting > >@@ -190,7 +197,12 @@ sub format_sqldatetime { > my $dt = dt_from_string( $str, 'sql' ); > return q{} unless $dt; > $dt->truncate( to => 'minute' ); >- return output_pref( $dt, $force_pref, $force_time, $dateonly ); >+ return output_pref({ >+ dt => $dt, >+ dateformat => $force_pref, >+ timeformat => $force_time, >+ dateonly => $dateonly >+ }); > } > return q{}; > } >@@ -213,7 +225,12 @@ sub format_sqlduedatetime { > if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) { > my $dt = dt_from_string( $str, 'sql' ); > $dt->truncate( to => 'minute' ); >- return output_pref_due( $dt, $force_pref, $force_time, $dateonly ); >+ return output_pref_due({ >+ dt => $dt, >+ dateformat => $force_pref, >+ timeformat => $force_time, >+ dateonly => $dateonly >+ }); > } > return q{}; > } >diff --git a/Koha/Template/Plugin/KohaDates.pm b/Koha/Template/Plugin/KohaDates.pm >index 882d51e..134712f 100644 >--- a/Koha/Template/Plugin/KohaDates.pm >+++ b/Koha/Template/Plugin/KohaDates.pm >@@ -30,7 +30,7 @@ sub filter { > return "" unless $text; > $config->{with_hours} //= 0; > my $dt = dt_from_string( $text, 'iso' ); >- return output_pref( $dt, undef, undef, !$config->{with_hours} ); >+ return output_pref({ dt => $dt, dateonly => !$config->{with_hours} }); > } > > 1; >diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl >index 7c2b3f3..0f7af71 100755 >--- a/acqui/lateorders.pl >+++ b/acqui/lateorders.pl >@@ -86,10 +86,10 @@ my $estimateddeliverydateto_dt = $estimateddeliverydateto > > # Format the output of "date from" and "date to" > if ($estimateddeliverydatefrom_dt) { >- $estimateddeliverydatefrom = output_pref($estimateddeliverydatefrom_dt, undef, undef, 1); >+ $estimateddeliverydatefrom = output_pref({dt => $estimateddeliverydatefrom_dt, dateonly => 1}); > } > if ($estimateddeliverydateto_dt) { >- $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt, undef, undef, 1); >+ $estimateddeliverydateto = output_pref({dt => $estimateddeliverydateto_dt, dateonly => 1}); > } > > my $branch = $input->param('branch'); >diff --git a/members/member.pl b/members/member.pl >index 47f7cb7..9152651 100755 >--- a/members/member.pl >+++ b/members/member.pl >@@ -108,7 +108,7 @@ if ($member || keys %$patron) { > my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" ); > > if ( $searchfields eq "dateofbirth" ) { >- $member = output_pref(dt_from_string($member), 'iso', undef, 1); >+ $member = output_pref({dt => dt_from_string($member), dateformat => 'iso', dateonly => 1}); > } > > my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" ); >diff --git a/t/DateUtils.t b/t/DateUtils.t >index eab8424..cdff2af 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 => 30; >+use Test::More tests => 31; > > BEGIN { use_ok('Koha::DateUtils'); } > >@@ -23,40 +23,48 @@ cmp_ok( $dt->ymd(), 'eq', $testdate_iso, 'Returned object matches input' ); > $dt->set_hour(12); > $dt->set_minute(0); > >-my $date_string = output_pref( $dt, 'iso', '24hr' ); >+my $date_string; >+ >+my $dateformat = C4::Context->preference('dateformat'); >+cmp_ok output_pref({ dt => $dt, dateformat => $dateformat }), >+ 'eq', >+ output_pref($dt), >+ 'output_pref gives an hashref or a dt'; >+ >+$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '24hr' }); > cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output'; > >-$date_string = output_pref( $dt, 'iso', '12hr' ); >+$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '12hr' }); > cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr'; > > # "notime" doesn't actually mean anything in this context, but we > # can't pass undef or output_pref will try to access the database >-$date_string = output_pref( $dt, 'iso', 'notime', 1 ); >+$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => 'notime', dateonly => 1 }); > cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)'; > >-$date_string = output_pref( $dt, 'us', '24hr' ); >+$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '24hr' }); > cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output'; > >-$date_string = output_pref( $dt, 'us', '12hr' ); >+$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '12hr' }); > cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr'; > >-$date_string = output_pref( $dt, 'us', 'notime', 1 ); >+$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => 'notime', dateonly => 1 }); > cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)'; > > # metric should return the French Revolutionary Calendar Really >-$date_string = output_pref( $dt, 'metric', '24hr' ); >+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' }); > cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output'; > >-$date_string = output_pref( $dt, 'metric', 'notime', 1 ); >+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => 'notime', dateonly => 1 }); > cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)'; > >-$date_string = output_pref_due( $dt, 'metric', '24hr' ); >+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' }); > 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', '24hr' ); >+$date_string = output_pref_due({ dt => $dt, dateformat => 'metric', timeformat => '24hr' }); > cmp_ok $date_string, 'eq', '16/06/2011', > 'output_pref_due truncates HH:SS at midnight'; > >-- >1.8.1.2
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 10380
:
18517
|
18597
|
19188
|
20906