From 67d6c469a98ec5b39dabfb6c38feaf560727fc6e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 13 Nov 2018 11:09:05 -0500 Subject: [PATCH] Bug 21824: Add ability to format dates in various formats in templates This patch adds the ability to set a date format for the Template Toolkit filter KohaDates Test plan: 1) Apply this patch 2) In a template, use the filter param "dateformat => 'iso'" 3) Note the output is in ISO format Signed-off-by: Owen Leonard Signed-off-by: Bouzid Fergani Signed-off-by: Martin Renvoize --- Koha/Template/Plugin/KohaDates.pm | 4 ++-- t/db_dependent/Template/Plugin/KohaDates.t | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Koha/Template/Plugin/KohaDates.pm b/Koha/Template/Plugin/KohaDates.pm index 712c89f938..13ebec8926 100644 --- a/Koha/Template/Plugin/KohaDates.pm +++ b/Koha/Template/Plugin/KohaDates.pm @@ -33,8 +33,8 @@ sub filter { my $dt = dt_from_string( $text, 'iso' ); return $config->{as_due_date} ? - output_pref({ dt => $dt, as_due_date => 1 }) : - output_pref({ dt => $dt, dateonly => !$config->{with_hours} }); + output_pref({ dt => $dt, as_due_date => 1, dateformat => $config->{dateformat} }) : + output_pref({ dt => $dt, dateonly => !$config->{with_hours}, dateformat => $config->{dateformat} }); } 1; diff --git a/t/db_dependent/Template/Plugin/KohaDates.t b/t/db_dependent/Template/Plugin/KohaDates.t index fe188362a3..36857a65dd 100644 --- a/t/db_dependent/Template/Plugin/KohaDates.t +++ b/t/db_dependent/Template/Plugin/KohaDates.t @@ -3,7 +3,7 @@ use Modern::Perl; use C4::Context; use Koha::DateUtils; -use Test::More tests => 7; +use Test::More tests => 8; use Test::MockModule; use t::lib::Mocks; @@ -46,7 +46,10 @@ $module_context->mock( ); $filtered_date = $filter->filter('1979-04-01'); -is( $filtered_date, '01/04/1979', 'us: dt_from_string should return the valid date if a DST is given' ); +is( $filtered_date, '01/04/1979', 'us: dt_from_string should return the valid date if a dst is given' ); + +$filtered_date = $filter->filter('1979-04-01', undef, { dateformat => 'iso' } ); +is( $filtered_date, '1979-04-01', 'date should be returned in ISO if dateformat is passed with a value of iso' ); $module_context->mock( 'tz', -- 2.39.5