Bugzilla – Attachment 148261 Details for
Bug 33242
Allow passing things like add_days => 3 to KohaDates filter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33242: Allow passing add_{duration} options to KohaDates
Bug-33242-Allow-passing-addduration-options-to-Koh.patch (text/plain), 2.21 KB, created by
Nick Clemens (kidclamp)
on 2023-03-16 12:49:55 UTC
(
hide
)
Description:
Bug 33242: Allow passing add_{duration} options to KohaDates
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-03-16 12:49:55 UTC
Size:
2.21 KB
patch
obsolete
>From baf64b40f439ba85b5f15113461262997830f6d7 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 16 Mar 2023 09:53:20 +0100 >Subject: [PATCH] Bug 33242: Allow passing add_{duration} options to KohaDates > >For example, if I want to add a few days to the issuedate in a >TT template, I could do this: > [% checkout.issuedate | $KohaDates add_days => 3 %] > >This development allows you to pass add/subtract years, months, weeks, >days, hours, minutes and seconds. > >Test plan: >Pick a notice like CHECKOUT. >Add a line like: > [% checkout.date_due | $KohaDates with_hours => 1, add_minutes => 15 %] >Do a checkout. Verify that the notice generated contains a time that >shifted 15 minutes. >Undo your change. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/Template/Plugin/KohaDates.pm | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > >diff --git a/Koha/Template/Plugin/KohaDates.pm b/Koha/Template/Plugin/KohaDates.pm >index 8fa5abb73d..79406cfb7b 100644 >--- a/Koha/Template/Plugin/KohaDates.pm >+++ b/Koha/Template/Plugin/KohaDates.pm >@@ -32,6 +32,7 @@ sub filter { > $config->{with_hours} //= 0; > > my $dt = dt_from_string( $text, 'iso' ); >+ $dt->add( %$_ ) for _parse_config_for_durations($config); # Allow date add/subtract; see _parse_config_for_durations > > return $config->{as_due_date} ? > output_pref({ dt => $dt, as_due_date => 1, dateformat => $config->{dateformat} }) : >@@ -42,6 +43,19 @@ sub datetime_from_string { > my ( $self, @params ) = @_; > return dt_from_string( @params ); > } >+sub _parse_config_for_durations { >+# Supports passing things like add_years => 1 or subtract_years => 1 >+# Same for months, weeks, days, hours, minutes or seconds >+# Returns a list of hashrefs like { years => 1 }, { days => -1 } that can be passed to dt->add >+ my $config = shift; >+ my @results; >+ foreach my $entry ( keys %$config ) { >+ if( $entry =~ /^(add|subtract)_(years|months|weeks|days|hours|minutes|seconds)$/ ) { >+ push @results, { $2 => ( $1 eq 'add' ? 1 : -1 ) * $config->{$entry} }; >+ } >+ } >+ return @results; >+} > > sub output_preference { > my ( $self, @params ) = @_; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33242
:
148256
|
148257
|
148261
|
148262
|
148264
|
148265
|
150390
|
150391
|
150392