I have changed the date plugin so that it can handle
both Y:M:D H:M:S and H:M:S D:M:Y and Y:M:D/D:M:Y (alone)
Perhaps putting outside the parsing into a helper function
so that people can easily overwrite only this phase thru inheritance
(and not copy && paste unecessary things from the format method)
could be a solution:
sub format {
my $self = shift;
[...]
if ($time =~ /^\d+$/) {
[...]
}
else {
@date = @{$self->parseDate($time)}; ##the overwritable function
$time = &POSIX::mktime(@date);
}
[...]
return $datestr;
}
sub parseDate {
my $self = shift;
my $time = shift;
my @parts = split(/(?:\/| |:|-)/,$time);
if(scalar(@parts)==3) { # perhaps a simple Y:M:D or D:M:Y date
# if first elem==4 assume Y:M:D && reverse to get D:M:Y
@parts = reverse @parts if(length($parts[0])==4);
unshift @parts,("00","00","00"); # change to 00,00,00,D,M,Y
}
# if first elem==4 assume Y:M:D H:M:S
# then reverse to H:M:S D:M:Y
if(scalar(@parts)==6 && length($parts[0])==4) {
my @rev = reverse @parts[0..2];
@parts = @parts[3..5];
push @parts, @rev;
}
@parts = @parts[2,1,0,3..5];
return (undef, Template::Exception->new('date',
"bad time/date string: expectings {h:m:s} d:m:y or y:m:d {h:m:s} got:
'$time'"))
unless @parts >= 6 && defined $parts[5];
$parts[4] -= 1; # correct month number 1-12 to range 0-11
$parts[5] -= 1900; # convert absolute year to years since 1900
return [EMAIL PROTECTED];
}
+ perhaps :
format.in ='S:M:H-D:M:Y',
format.out ='actual system'
so that it can hande _some_ few extra format without subclassing.
This is a quick solution, sorry.
Somebody as perhaps done it before.
Anyway
Cyrille
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates