diff --git a/C4/Letters.pm b/C4/Letters.pm index ce8ffda7e1..bfcaacbe90 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -40,6 +40,7 @@ use Koha::Patrons; use Koha::SMS::Providers; use Koha::SMTP::Servers; use Koha::Subscriptions; +use Koha::Template::Plugin::KohaDates; use constant SERIALIZED_EMAIL_CONTENT_TYPE => 'message/rfc822'; @@ -638,6 +639,10 @@ sub GetPreparedLetter { $lang = shift @languages; } + $Template::Stash::SCALAR_OPS->{strftime} = sub { + return Koha::Template::Plugin::KohaDates->strftime(@_); + }; + $letter->{content} = _process_tt( { content => $letter->{content}, diff --git a/Koha/Template/Plugin/KohaDates.pm b/Koha/Template/Plugin/KohaDates.pm index d8c31beec5..e3f39c2eb2 100644 --- a/Koha/Template/Plugin/KohaDates.pm +++ b/Koha/Template/Plugin/KohaDates.pm @@ -67,4 +67,14 @@ sub tz { return C4::Context->tz->name; } +sub strftime { # used as TT virtual method for scalars, wrapper around DateTime counterpart + my ( $self, $value, $format, $locale ) = @_; + my $dt = eval { dt_from_string($value) }; + if ($dt) { + $dt->set_locale($locale) if $locale; + return $dt->strftime($format); + } + return $value; +} + 1;