* Mark Mills <[EMAIL PROTECTED]> [2002-08-20 18:18]:
> > 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?
I was thinking in the opposite direction: add a method that will parse
a string into a date, and then the regular Template::Plugin::Date
methods can operate on it.
[% time_t = date.parse("some string") %]
[% date.format(time_t, "%A, %b") %]
Also accepts Time::ParseDate options, like PREFER_PAST:
[% time_t = date.format("Tuesday", PREFER_PAST => 1) %]
Patch attached. I have no tests for it, though.
(darren)
--
A lot of people mistake a short memory for a clear conscience.
-- Doug Larson
--- Date.pm.orig Tue Aug 20 17:36:08 2002
+++ Date.pm Wed Aug 21 08:44:03 2002
@@ -57,6 +57,25 @@
return time();
}
+#------------------------------------------------------------------------
+# parse(str, %options)
+#
+# Attempts to parse a date, using Time::ParseDate. Returns a time_t,
+# suitable for passing to format(), or 0 if Time::ParseDate could be loaded.
+#------------------------------------------------------------------------
+sub parse {
+ my $self = shift;
+ my @args = @_;
+
+ push @args, %{ pop @args }
+ if ref $args[-1] eq 'HASH';
+
+ eval { require "Time/ParseDate.pm"; };
+ return scalar Time::ParseDate::parsedate(@args)
+ unless $@;
+
+ return 0;
+}
#------------------------------------------------------------------------
# format()