[prev] [thread] [next] [Date index for 2004/12/03]
Hi there,
Been battling a bit with dates and was wondering if it would be OK to
allow [% USE date %] to be able to cope with 'D:M:Y' dates as well as
'H:M:S D:M:Y'
This doesn't feel like bloat (see patch) or esoteric feature creep. I
haven't found many other pleasant alternatives and this solves a simple
common case problem.
I haven't written tests & docs but will if it's accepted. It passes
current tests. I've added in an additional constraint that each element
of the array be numeric - this was needed for the 'some stupid date'
test which got through via the @date == 3 condition. (And it seems to
make sense anyway to have that constraint.)
--- lib/Template/Plugin/Date.pm.orig 2004-12-03 14:59:27.000000000 +0000
+++ lib/Template/Plugin/Date.pm 2004-12-03 15:17:53.000000000 +0000 @@ -101,7 +101,10 @@
# if $time is numeric, then we assume it's seconds since the
# epoch
- # otherwise, we try to parse it as a 'H:M:S D:M:Y' string
- @date = (split(/(?:\/| |:|-)/, $time))[2,1,0,3..5];
+ # otherwise, we try to parse it as either a 'H:M:S D:M:Y'
+ # or 'D:M:Y' string
+ @date = split m~[-/ :]~, $time;
+ unshift @date, 0,0,0 if @date == 3;
+ @date[0..2] = @date[2,1,0];
return (undef, Template::Exception->new('date',
"bad time/date string: expects 'h:m:s d:m:y' got: '$time'"))
- unless @date >= 6 && defined $date[5];
+ unless @date >= 6 && defined $date[5] && !grep /\D/, @date;
$date[4] -= 1; # correct month number 1-12 to range 0-11
Paul
--
Paul Makepeace .............................. http://paulm.com/inchoate/
"What is the closest thing to a man's heart? Time would go backwards."
-- http://paulm.com/toys/surrealism/
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
|
[Templates] Patch to Template::Plugin::Date
|
Generated at 08:55 on 15 Mar 2005 by mariachi v0.52