From 0942a21db2a82c002c75f5d303561b9c39a24914 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Thu, 29 Dec 2011 21:46:51 +1300 Subject: [PATCH] Bug 929 : Followup fixing date formatting This patch introduces a Filter (KohaDates) for use in templates [% USE KohaDates %] [% somevariable | $KohaDates %] This will format the date in the format specified by the systempreference Signed-off-by: Katrin Fischer (cherry picked from commit 01875b565d7c04b3b00ba1986f824cae7d1fb2a9) Signed-off-by: Chris Nighswonger --- C4/Templates.pm | 1 + Koha/Template/Plugin/KohaDates.pm | 31 +++++++++++++++++++ acqui/ordered.pl | 2 -- acqui/spent.pl | 4 --- .../prog/en/modules/acqui/ordered.tt | 5 +-- .../prog/en/modules/acqui/spent.tt | 5 +-- 6 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 Koha/Template/Plugin/KohaDates.pm diff --git a/C4/Templates.pm b/C4/Templates.pm index 7585727550..d150a16f1e 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -58,6 +58,7 @@ sub new { my $template = Template->new( { EVAL_PERL => 1, ABSOLUTE => 1, + PLUGIN_BASE => 'Koha::Template::Plugin', INCLUDE_PATH => [ "$htdocs/$theme/$lang/includes", "$htdocs/$theme/en/includes" diff --git a/Koha/Template/Plugin/KohaDates.pm b/Koha/Template/Plugin/KohaDates.pm new file mode 100644 index 0000000000..749f6e24f8 --- /dev/null +++ b/Koha/Template/Plugin/KohaDates.pm @@ -0,0 +1,31 @@ +package Koha::Template::Plugin::KohaDates; + +# Copyright Catalyst IT 2011 + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Template::Plugin::Filter; +use base qw( Template::Plugin::Filter ); + +use C4::Dates; + +sub filter { + my ($self,$text) = @_; + my $date = C4::Dates->new( $text, 'iso' ); + return $date->output("syspref"); +} + +1; \ No newline at end of file diff --git a/acqui/ordered.pl b/acqui/ordered.pl index 0ae5dad623..b681afbf4c 100755 --- a/acqui/ordered.pl +++ b/acqui/ordered.pl @@ -97,8 +97,6 @@ while ( my $data = $sth->fetchrow_hashref ) { push @ordered, $data; $total += $subtotal; } - my $entrydate = C4::Dates->new( $data->{'entrydate'}, 'iso' ); - $data->{'entrydate'} = $entrydate->output("syspref"); } $total = sprintf( "%.2f", $total ); diff --git a/acqui/spent.pl b/acqui/spent.pl index 7ea944629e..a50b7aef44 100755 --- a/acqui/spent.pl +++ b/acqui/spent.pl @@ -98,10 +98,6 @@ while ( my $data = $sth->fetchrow_hashref ) { $data->{'freight'} = sprintf( "%.2f", $data->{'freight'} ); $data->{'unitprice'} = sprintf( "%.2f", $data->{'unitprice'} ); $total += $subtotal; - my $entrydate = C4::Dates->new( $data->{'entrydate'}, 'iso' ); - $data->{'entrydate'} = $entrydate->output("syspref"); - my $datereceived = C4::Dates->new( $data->{'datereceived'}, 'iso' ); - $data->{'datereceived'} = $datereceived->output("syspref"); push @spent, $data; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt index 14be1edb34..018d80725a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt @@ -1,3 +1,4 @@ +[% USE KohaDates %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › Ordered [% INCLUDE 'doc-head-close.inc' %] @@ -41,7 +42,7 @@ [% order.title %] - [% order.ordernumber %] + [% order.ordernumber %] [% order.booksellerid %] @@ -56,7 +57,7 @@ [% order.ecost %] - [% order.entrydate %] + [% order.entrydate | $KohaDates %] [% order.subtotal %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt index 78f7cb5a36..49bcedb0cc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt @@ -1,3 +1,4 @@ +[% USE KohaDates %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › Spent [% INCLUDE 'doc-head-close.inc' %] @@ -67,10 +68,10 @@ [% order.freight %] - [% order.entrydate %] + [% order.entrydate | $KohaDates %] - [% order.datereceived %] + [% order.datereceived | $KohaDates %] [% order.subtotal %] -- 2.39.5