> > It would be incredible useful for the date plugin to have parsedate
> > functionality, wouldn't it?

How about adding Date::Manip the same way Date::Calc works in the "date" plugin?

Then:

[% dcdate = "2002-07-31T11:14:46+00:00" %]
[% USE date %]
[% manip = date.manip %]
[% manip.UnixDate(dcdate,"%d %b") +%]

Works all loverly.

Also you get pathological things like this to work: 
[% manip.UnixDate("Noon yesterday","%b %d, %y at %H:%M") %]

Since I mangled version 2.06 (don't ask, I've got TWO boxes with the newest, both 
unavailable) I'm just including the added lines. A sub and package ala 
Template::Plugin::Date::Calc, a snipette of docs, and a 2 line credit.

The code is entirely derivative so I don't think I could copyright it if I wanted... 
regardless, it is hereby Andy's. :)

+ sub manip {
+     my $self = shift;
+     eval {
+       require "Date/Manip.pm";
+     };
+     $self->throw("failed to load Date::Manip: $@")
+       if $@;
+     return Template::Plugin::Date::Manip->new('no context');
+ }
+
+ package Template::Plugin::Date::Manip;
+ use base qw( Template::Plugin );
+ use vars qw( $AUTOLOAD );
+
+ sub AUTOLOAD {
+     my $self = shift;
+     my $method = $AUTOLOAD;
+
+     $method =~ s/.*:://;
+     return if $method eq 'DESTROY';
+
+     my $sub = \&{"Date::Manip::$method"};
+     $self->throw("no such Date::Manip method: $method")
+       unless $sub;
+
+     &$sub(@_);
+ }
+

+ The manip() method can be used to create an interface to the Date::Manip
+ module (if installed on your system).
+
+     [% manip = date.manip %]
+     [% manip.UnixDate("Noon Yesterday","%Y %b %d %H:%M") %]
+

+
+ Mark D. Mills E<lt>[EMAIL PROTECTED]<gt> cloned Date::Manip from the
+ cute Date::Calc sub-plugin.

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates

Reply via email to