I should mention, I have the sub in another package, you can take the "my
$class = shift;" off, if you don't.



On Fri, Jan 23, 2009 at 7:33 AM, Kelly Thompson <kalexthomp...@gmail.com>wrote:

> I have had to do this so often, I created a simple little sub that I pass
> to the template.
>
> sub fixDate {
>
> my $class = shift;
>
> my @it = split(/-/, shift);
> my @ti = split(/ /,$it[2]);
>
> my @time = split(/:/, $ti[1]);
> my $suffix = 'am';
>
> if($time[0] > 12){
> $time[0] -= 12;
> $suffix = 'pm';
> }
> elsif($time[0] == 00){
> $time[0] = 12;
> $suffix = 'am';
> }
>
> return "$it[1]/$ti[0]/$it[0] $time[0]:$time[1]$suffix CST";
> }
>
>
> Then in TT:
>
> [% fixDate(article.date) %]
>
>
> No sense even loading the Date module, unless you use it for other things
> too.
>
> You may want to change the "CST" to whatever you want. Or create a hook to
> return the right zone for the users timezone.
>
> I would also suggest Memoizing the function if it's to be used on list
> iterations.
>
> http://search.cpan.org/~mjd/Memoize-1.01/Memoize.pm<http://search.cpan.org/%7Emjd/Memoize-1.01/Memoize.pm>
>
>
>
>
> On Fri, Jan 23, 2009 at 5:26 AM, Dave Howorth 
> <dhowo...@mrc-lmb.cam.ac.uk>wrote:
>
>> David Stewart wrote:
>>  > "yyyy-mm-dd hh:mm:ss"
>>
>> > [% date.format('2000/12/21 4:20:36') %]
>>
>> > Anyone have any idea what might be going on here?
>>
>> '-' != '/' ?
>>
>> _______________________________________________
>> templates mailing list
>> templates@template-toolkit.org
>> http://mail.template-toolkit.org/mailman/listinfo/templates
>>
>
>
>
> --
> Kelly A. Thompson
> Marketing Consultant
> Midland Trail Scenic Highway Association
> 237 Capitol Street
> Charleston, West Virginia 25301
> p: 304.343.6001
> f:  304.344.2210
> www.midlandtrail.com
>
> Adventure begins at the exit ramp. Travel the Midland Trail.
>



-- 
Kelly A. Thompson
Marketing Consultant
Midland Trail Scenic Highway Association
237 Capitol Street
Charleston, West Virginia 25301
p: 304.343.6001
f:  304.344.2210
www.midlandtrail.com

Adventure begins at the exit ramp. Travel the Midland Trail.
_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to