velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "john mahan" <john.ma...@isg.com>
Subject Re: Velocity Date Calculations?
Date Mon, 08 Nov 2004 03:11:36 GMT
Nathan,

I have been able to use the DateTool in my context but not to calculate the
offset date
for display in  my example (which per your email is because that is not in
the DateTool).
I believe it will be useful if you can extend the capability  in the future
to allow the
Velocity Templates to haveDate manipulation and presentation capability
similar  to
JavaScript to avoid needing to use outside methods... but I understand there
is much to
do and other priorities exist. In the interim I'll be pleased to use what
exists and be happy
to use new things in the future.

THX.,
John Mahan
----- Original Message ----- 
From: "Nathan Bubna" <nathan@esha.com>
To: "Velocity Users List" <velocity-user@jakarta.apache.org>
Sent: Friday, November 05, 2004 11:30 AM
Subject: Re: Velocity Date Calculations?


> john mahan said:
> > Using Velocity Template I have tried a variety of DateTool
> > (and MathTool) coding approaches without success (getting NULL result).
>
> for everything you try?  are you sure you put them in the context?  what
is
> rendered when you do:
>
> $math.class or $date.class ?
>
> if that doesn't render the class names, then you haven't made those tools
> available to your context.  you can do so either by adding them directly:
>
> context.put("date", new DateTool())
>
> or if you are using the VelocityViewServlet, you can register them in your
> toolbox.xml:
>
> <tool>
>     <key>date</key>
>     <scope>application</scope>
>     <class>org.apache.velocity.tools.generic.DateTool</class>
> </tool>
>
> if you don't know what the above examples mean, you need to be reading the
> Velocity and/or VelocityTools documentation and perhaps checking out the
> examples as well.
>
> > The objective is to calculate a Date object comprised of current
> > date plus a variable number of days that is converted to a string for
> display;
> >
> > Here is an example of one approach I tried:
> >
> >
> >  ## -------- Set Min Date
> >
> >      #set ($minDays = 2)  ## Earliest Day valid from Today (0= Today)
> >      ## ------  Set Initial Calendar Date For Display
> >      #set ($minDaysMS = ($minDays * 1000 * 60 * 60 * 24))
> >      #set ($currDate = $date) ## Default Current System Date
> >      #set ($baseDate = $date.format('S',$currDate))
> >      #set ($minDateMS = ($baseDate + $minDaysMS))
>
> this won't work.  you can't add a string ($baseDate) to an integer
> ($minDaysMS) in VTL.
>
> >      #set ($minDateDisp = $date.toDate($minDateMS))
>
> actually, this step won't work either.  the toDate() methods don't
currently
> take integers, only Long instances.  i'm gonna change this now that i
think
> about it, it shouldn't hurt anything to accept integers as well.
>
> >      #set ($dateDisp = $date.format('M/d/yyyy',$minDateDisp))  ## Min
Date
> Short String
>
>
> hope this helps.
>
> Nathan Bubna
> nathan@esha.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message