From 9efe46962db6375080a48ac4c7390834b1385ca3 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 6 Nov 2012 14:00:06 -0500 Subject: [PATCH] Bug 9014 - Add time due to slips This patch modifies Koha::DateUtils::output_pref to support the new system preference TimeFormat, which defines the visual format for a time as either the 24 hour format ( default ), or the 12 hour format (HH:MM AM/PM). The patch also modifies C4::Members::IssueSlip to use output_pref rather than format_date. Test Plan: 1) Apply patch 2) Run updatedatabase.pl 3) Issue an item to a patron, verify the times are in 24 hour format. 4) Switch TimeFormat to the 12 hour format. 5) Revisit the patron record you issued an item to, times should now be in a 12 hour format. 6) Print a slip for this patron, you should now see the time as well as the date. Katrin Fischer Passes all tests after fixing the test count in t/DateUtils.t. Fixed conflicts in syspref.sql and updatedatabase.pl. --- C4/Letters.pm | 4 +-- C4/Members.pm | 4 +-- Koha/DateUtils.pm | 38 +++++++++++++------- acqui/lateorders.pl | 4 +-- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 6 ++++ .../en/modules/admin/preferences/i18n_l10n.pref | 8 +++++ t/DateUtils.t | 30 +++++++++------- 8 files changed, 65 insertions(+), 30 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 36e6213..b250f9f 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -29,6 +29,7 @@ use C4::Branch; use C4::Log; use C4::SMS; use C4::Debug; +use Koha::DateUtils; use Date::Calc qw( Add_Delta_Days ); use Encode; use Carp; @@ -614,8 +615,7 @@ sub _parseletter { } if ($letter->{content} && $letter->{content} =~ /<>/) { - my @da = localtime(); - my $todaysdate = "$da[2]:$da[1] " . C4::Dates->today(); + my $todaysdate = output_pref( DateTime->now() ); $letter->{content} =~ s/<>/$todaysdate/go; } diff --git a/C4/Members.pm b/C4/Members.pm index 81b014b..3b1615f 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -2318,8 +2318,8 @@ sub IssueSlip { elsif ((substr $it->{'date_due'}, 0, 10) le $now) { $it->{'overdue'} = 1; } - - $it->{'date_due'}=format_date($it->{'date_due'}); + my $dt = dt_from_string( $it->{'date_due'} ); + $it->{'date_due'} = output_pref( $dt );; } my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist; diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 4ffc160..382e184 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, [$format] ); +$date_string = output_pref($dt, [$date_format], [$time_format] ); Returns a string containing the time & date formatted as per the C4::Context setting, or C if C was provided. @@ -101,7 +101,9 @@ or C if C was provided. 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 -A third parameter allows to specify if the output format contains the hours and minutes. +A third parameter allows overriding of the TimeFormat syspref value + +A fourth parameter allows to specify if the output format contains the hours and minutes. If it is not defined, the default value is 0; =cut @@ -109,32 +111,38 @@ If it is not defined, the default value is 0; 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 return unless defined $dt; my $pref = defined $force_pref ? $force_pref : C4::Context->preference('dateformat'); + + my $time_format = $force_time || C4::Context->preference('TimeFormat'); + my $time = ( $time_format eq '12hr' ) ? '%I:%M %p' : '%H:%M'; + given ($pref) { when (/^iso/) { return $dateonly - ? $dt->strftime('%Y-%m-%d') - : $dt->strftime('%Y-%m-%d %H:%M'); + ? $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 %H:%M'); + ? $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 %H:%M'); + ? $dt->strftime("%m/%d/%Y") + : $dt->strftime("%m/%d/%Y $time"); } default { return $dateonly - ? $dt->strftime('%Y-%m-%d') - : $dt->strftime('%Y-%m-%d %H:%M'); + ? $dt->strftime("%Y-%m-%d") + : $dt->strftime("%Y-%m-%d $time"); } } @@ -173,11 +181,14 @@ with output_pref as it is a frequent activity in scripts sub format_sqldatetime { my $str = shift; my $force_pref = shift; # if testing we want to override Context + my $force_time = shift; + my $dateonly = shift; + if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) { my $dt = dt_from_string( $str, 'sql' ); return q{} unless $dt; $dt->truncate( to => 'minute' ); - return output_pref( $dt, $force_pref ); + return output_pref( $dt, $force_pref, $force_time, $dateonly ); } return q{}; } @@ -194,10 +205,13 @@ with output_pref_due as it is a frequent activity in scripts sub format_sqlduedatetime { my $str = shift; my $force_pref = shift; # if testing we want to override Context + my $force_time = shift; + my $dateonly = shift; + 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 ); + return output_pref_due( $dt, $force_pref, $force_time, $dateonly ); } return q{}; } diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl index 544370d..497242f 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, 1); + $estimateddeliverydatefrom = output_pref($estimateddeliverydatefrom_dt, undef, undef, 1); } if ($estimateddeliverydateto_dt) { - $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt, undef, 1); + $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt, undef, undef, 1); } my $branch = $input->param('branch'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index d5d15d7..63ae0e5 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -406,3 +406,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('NotesBlacklist','','List of notes fields that should not appear in the title notes/description separator of details',NULL,'free'); INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserCSS', '', NULL, 'Add CSS to be included in the SCO module in an embedded