logo       

DateTime not working with TT: msg#00074

Subject: DateTime not working with TT
I'm having a problem getting access to DateTime object functions inside a template.

The code looks like this:

test.pl:

--------------------

use Template;
use Template::Plugin::DateTime;
my $template = Template->new({
    INCLUDE_PATH =>
"/tmp",
    PLUGIN_BASE =>
'Plugin',
    COMPILE_DIR =>
'/tmp',
    DEFAULT =>
'404.html',
});

my $output;

$template->process(
'test.html', $vars, \$output) or die $template->error();
print $output;

--------------------

test.html:

[% USE date = DateTime(today = 1) %]
Today is [% date.year %]/[% date.month %]/[% date.day %].
[% date.add(days => 32) %]
32 days from today is [% date.year %]/[% date.month %]/[% date.day %]

--------------------

The result is:

undef error - Cannot compare a datetime to a regular scalar at /usr/local/lib/perl5/site_perl/5.6.1/mach/DateTime.pm line 1255.

Basically, it looks like it's passing the time scalar instead of the object (it's doing a compare of values instead of a call to the year method. I can confirm this by looking at the input to the DateTime::_compare function is, which shows as "2004-10-14T00:00:00", the same thing I get if I create a new DateTime object and do "print $datetime_obj"

I've tried to get this working using the Template::Plugin::DateTime module (used above) and by passing the DateTime obj as a var into the TT - both attempts gave the same result.

As I said, it appears that this is TT not knowing that I want to call date as an obj not a hash or scalar (and the obj can be both).  OT: oddly, so can Time::Piece and that works as expected.

Has anyone gotten this working?

Vitals:

FreeBSD: 4.10
Perl: v5.6.1
TT: Template-Toolkit-2.13
Template-Plugin-DateTime-0.01
DateTime-0.21

Thanks!
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe