From ea6c0c8b7a09c2ffb0fb863d90f26d472e67f2a4 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 20 Oct 2017 17:46:28 +0100 Subject: include patched Template::Plugin::DateTime::Format --- Makefile.PL | 2 +- lib/Template/Plugin/DateTimeFormat.pm | 38 +++++++++++++++++++++++++++++++++++ t/test-site/src/common/base-feed.tt | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 lib/Template/Plugin/DateTimeFormat.pm diff --git a/Makefile.PL b/Makefile.PL index 6734da3..8ca8458 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -20,7 +20,7 @@ WriteMakefile( 'Path::Class' => '0', 'Slay::Maker' => '0', 'Template' => '0', - 'Template::Plugin::DateTime::Format' => '0', + #'Template::Plugin::DateTime::Format' => '0', 'Test::Exception' => '0', 'Test::More' => '0', 'Text::Restructured' => '0', diff --git a/lib/Template/Plugin/DateTimeFormat.pm b/lib/Template/Plugin/DateTimeFormat.pm new file mode 100644 index 0000000..8c6d592 --- /dev/null +++ b/lib/Template/Plugin/DateTimeFormat.pm @@ -0,0 +1,38 @@ +package Template::Plugin::DateTimeFormat; +$Template::Plugin::DateTimeFormat::VERSION = '0.04'; +use 5.006; +use strict; +use warnings; +use DateTime; +use Class::Load; + +# hacked Template::Plugin::DateTime::Format with patch from +# https://rt.cpan.org/Public/Bug/Display.html?id=120391 + +use base 'Template::Plugin'; + +sub new { + my ($class, $context, $formatter_class, $new_args, $format_args) = @_; + Class::Load::load_class($formatter_class || die 'need class name'); + + my @new_args = ref $new_args eq 'ARRAY' ? @$new_args : $new_args; + if ($format_args) { + $format_args = [ $format_args ] unless ref $format_args eq 'ARRAY'; + } + + bless { + _CONTEXT => $context, + formatter => $formatter_class->new(@new_args), + format_args => $format_args || [], + }, $class; +} + +sub format { + my ($self, $date) = @_; + + my $fmt = $self->{formatter}; + my @args = @{$self->{format_args}}; + return $fmt->format_datetime($date, @args); +} + +1; diff --git a/t/test-site/src/common/base-feed.tt b/t/test-site/src/common/base-feed.tt index d91ec0e..9bc4ff7 100644 --- a/t/test-site/src/common/base-feed.tt +++ b/t/test-site/src/common/base-feed.tt @@ -1,4 +1,4 @@ -[% USE df = DateTime::Format('DateTime::Format::Strptime', +[% USE df = DateTimeFormat('DateTime::Format::Strptime', { pattern => '%FT%T%z', locale => 'en_US', time_zone => 'GMT' }) -%] -- cgit v1.2.3