Bug 38758: Add strftime as TT virtual method

Test plan:
Try things like [% borrower.dateexpiry.strftime('%d-%m-%y') %] in
a notice. Also test datetime fields like borrower.lastseen.
Add locale support with strftime('%d %B', 'nl_NL') etc.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
(cherry picked from commit 9a2042c3e9cb975273e6c17e111b4baeb5278006)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Marcel de Rooy 2024-12-18 15:56:50 +00:00 committed by Paul Derscheid
parent 1846baab52
commit 34a01f1894
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 15 additions and 0 deletions

View File

@ -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},

View File

@ -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;