Bug 33029: Add wrapper method for dt_from_string to KohaDates template toolkit plugin
It would be very useful to have direct access to dt_from_string in our templates. This would allow for us to handle custom date and time formatting. It would, for example, allow us to output the month name for a given date via Template Toolkit easily. Test Plan: 1) Apply this patch 2) In a notice add '[% Use KohaDates %][% KohaDates.datetime_from_string().ymd %]' to the top of a notice 3) Generate that notice for a patron 4) Note today's date in iso format is rendered at the top of the notice Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
4e1a2f148c
commit
720dec3f45
|
|
@ -53,6 +53,11 @@ sub _parse_config_for_durations {
|
|||
return @results;
|
||||
}
|
||||
|
||||
sub datetime_from_string {
|
||||
my ( $self, @params ) = @_;
|
||||
return dt_from_string( @params );
|
||||
}
|
||||
|
||||
sub output_preference {
|
||||
my ( $self, @params ) = @_;
|
||||
return output_pref( @params );
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
use Test::More tests => 31;
|
||||
use Test::More tests => 32;
|
||||
use Test::MockModule;
|
||||
use Test::Warn;
|
||||
|
||||
|
|
@ -1193,6 +1193,32 @@ EOF
|
|||
is( $letter->{content}, $expected_content );
|
||||
};
|
||||
|
||||
subtest 'KohaDates::dt_from_string' => sub {
|
||||
plan tests => 1;
|
||||
my $code = 'TEST_DATE';
|
||||
t::lib::Mocks::mock_preference('dateformat', 'metric'); # MM/DD/YYYY
|
||||
my $biblio = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Biblios',
|
||||
value => {
|
||||
timestamp => '2018-12-13 20:21:22',
|
||||
datecreated => '2018-12-13'
|
||||
}
|
||||
}
|
||||
);
|
||||
my $template = q{[% USE KohaDates %][% KohaDates.datetime_from_string('2000-12-01').dmy %]};
|
||||
|
||||
reset_template({ template => $template, code => $code, module => 'test' });
|
||||
my $letter = GetPreparedLetter(
|
||||
module => 'test',
|
||||
letter_code => $code,
|
||||
tables => {
|
||||
biblio => $biblio->biblionumber,
|
||||
}
|
||||
);
|
||||
is( $letter->{content}, '01-12-2000' );
|
||||
};
|
||||
|
||||
subtest 'Execute TT process in a DB transaction' => sub {
|
||||
plan tests => 2;
|
||||
my $code = 'TEST_TXN';
|
||||
|
|
|
|||
Loading…
Reference in New Issue