Merge branch 'bug_9014' into 3.12-master
This commit is contained in:
commit
c1f4866312
9 changed files with 69 additions and 33 deletions
|
@ -30,7 +30,6 @@ 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 +613,7 @@ sub _parseletter {
|
|||
}
|
||||
|
||||
if ($letter->{content} && $letter->{content} =~ /<<today>>/) {
|
||||
my @da = localtime();
|
||||
my $todaysdate = "$da[2]:$da[1] " . C4::Dates->today();
|
||||
my $todaysdate = output_pref( DateTime->now() );
|
||||
$letter->{content} =~ s/<<today>>/$todaysdate/go;
|
||||
}
|
||||
|
||||
|
|
|
@ -2415,8 +2415,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;
|
||||
|
||||
|
|
|
@ -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<undef> if C<undef> was provided.
|
||||
|
@ -101,7 +101,9 @@ or C<undef> if C<undef> 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,40 @@ 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;
|
||||
|
||||
$dt->set_time_zone( C4::Context->tz );
|
||||
|
||||
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 +183,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 +207,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{};
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -419,3 +419,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('
|
|||
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('FinesIncludeGracePeriod','1','If enabled, fines calculations will include the grace period.',NULL,'YesNo');
|
||||
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('UNIMARCAuthorsFacetsSeparator',', ', 'UNIMARC authors facets separator', NULL, 'short');
|
||||
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseKohaPlugins','1','Enable or disable the ability to use Koha Plugins.','','YesNo');
|
||||
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('TimeFormat','24hr','12hr|24hr','Defines the global time format for visual output.','Choice');
|
||||
|
|
|
@ -6336,7 +6336,6 @@ if ( CheckVersion($DBversion) ) {
|
|||
$dbh->do("INSERT INTO systempreferences ( variable, value, explanation, type ) VALUES ( 'SCOUserCSS', '', 'Add CSS to be included in the SCO module in an embedded <style> tag.', 'free' )");
|
||||
$dbh->do("INSERT INTO systempreferences ( variable, value, explanation, type ) VALUES ( 'SCOUserJS', '', 'Define custom javascript for inclusion in the SCO module', 'free' )");
|
||||
print "Upgrade to $DBversion done (Bug 9009: Add SCOUserCSS and SCOUserJS sysprefs)\n";
|
||||
SetVersion ($DBversion);
|
||||
}
|
||||
|
||||
$DBversion = "3.11.00.015";
|
||||
|
@ -6655,6 +6654,14 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
|
|||
SetVersion($DBversion);
|
||||
}
|
||||
|
||||
$DBversion = "3.11.00.107";
|
||||
if ( CheckVersion($DBversion) ) {
|
||||
$dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('TimeFormat','24hr','12hr|24hr','Defines the global time format for visual output.','Choice')");
|
||||
print "Upgrade to $DBversion done (Bug 9014: Add syspref TimeFormat)\n";
|
||||
SetVersion ($DBversion);
|
||||
}
|
||||
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 TableExists($table)
|
||||
|
|
|
@ -8,6 +8,14 @@ I18N/L10N:
|
|||
metric: dd/mm/yyyy
|
||||
iso: yyyy-mm-dd
|
||||
- .
|
||||
-
|
||||
- Format times in
|
||||
- pref: TimeFormat
|
||||
default: 24hr
|
||||
choices:
|
||||
24hr: 24 hour format ( e.g. "14:18" )
|
||||
12hr: 12 hour format ( e.g. "02:18 PM" )
|
||||
- .
|
||||
-
|
||||
- Use
|
||||
- pref: CalendarFirstDayOfWeek
|
||||
|
|
|
@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts :
|
|||
use strict;
|
||||
|
||||
sub kohaversion {
|
||||
our $VERSION = '3.11.00.106';
|
||||
our $VERSION = '3.11.00.107';
|
||||
# version needs to be set this way
|
||||
# so that it can be picked up by Makefile.PL
|
||||
# during install
|
||||
|
|
|
@ -5,7 +5,7 @@ use DateTime;
|
|||
use DateTime::TimeZone;
|
||||
|
||||
use C4::Context;
|
||||
use Test::More tests => 28;
|
||||
use Test::More tests => 30;
|
||||
|
||||
BEGIN { use_ok('Koha::DateUtils'); }
|
||||
|
||||
|
@ -23,32 +23,38 @@ 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' );
|
||||
my $date_string = output_pref( $dt, 'iso', '24hr' );
|
||||
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output';
|
||||
|
||||
my $date_string = output_pref( $dt, 'iso',1 );
|
||||
$date_string = output_pref( $dt, 'iso', '12hr' );
|
||||
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr';
|
||||
|
||||
$date_string = output_pref( $dt, 'iso', undef, 1 );
|
||||
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)';
|
||||
|
||||
$date_string = output_pref( $dt, 'us' );
|
||||
$date_string = output_pref( $dt, 'us', '24hr' );
|
||||
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output';
|
||||
|
||||
$date_string = output_pref( $dt, 'us', 1 );
|
||||
$date_string = output_pref( $dt, 'us', '12hr' );
|
||||
cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr';
|
||||
|
||||
$date_string = output_pref( $dt, 'us', undef, 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' );
|
||||
$date_string = output_pref( $dt, 'metric', '24hr' );
|
||||
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
|
||||
|
||||
$date_string = output_pref( $dt, 'metric',1 );
|
||||
$date_string = output_pref( $dt, 'metric', undef, 1 );
|
||||
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)';
|
||||
|
||||
$date_string = output_pref_due( $dt, 'metric' );
|
||||
$date_string = output_pref_due( $dt, 'metric', '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' );
|
||||
$date_string = output_pref_due( $dt, 'metric', '24hr' );
|
||||
cmp_ok $date_string, 'eq', '16/06/2011',
|
||||
'output_pref_due truncates HH:SS at midnight';
|
||||
|
||||
|
@ -87,20 +93,20 @@ cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects iso day 0' );
|
|||
$dt0 = dt_from_string( '0000-00-00', 'iso' );
|
||||
is( $dt0, undef, "undefined returned for 0 iso date" );
|
||||
|
||||
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric' );
|
||||
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
|
||||
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' );
|
||||
|
||||
$formatted = format_sqlduedatetime( '2011-06-16 12:00:07', 'metric' );
|
||||
$formatted = format_sqlduedatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
|
||||
cmp_ok(
|
||||
$formatted, 'eq',
|
||||
'16/06/2011 12:00',
|
||||
'format_sqlduedatetime conversion for hourly loans'
|
||||
);
|
||||
|
||||
$formatted = format_sqlduedatetime( '2011-06-16 23:59:07', 'metric' );
|
||||
$formatted = format_sqlduedatetime( '2011-06-16 23:59:07', 'metric', '24hr' );
|
||||
cmp_ok( $formatted, 'eq', '16/06/2011',
|
||||
'format_sqlduedatetime conversion for daily loans' );
|
||||
|
|
Loading…
Reference in a new issue