You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Doug Breaux <do...@gmail.com> on 2012/08/14 23:20:30 UTC

How do I set a TimeZone for VelocityTools DateTool?

Both the VelocityTools Tools Usage Summary and the DateTool Javadoc seem 
to indicate a configuration mechanism for setting a TimeZone, but I 
simply can't discover what that is.

DateTool's timezone setter is protected, and I don't want repeatedly 
pass a TimeZone into the overloaded format() methods.

VelocityTools 2.0

(Also asked on StackOverflow if you want to answer there
http://stackoverflow.com/questions/11907365/how-do-i-set-a-timezone-for-velocitytools-datetool 
)

Doug

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


Re: How do I set a TimeZone for VelocityTools DateTool?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Doug,

On 9/12/12 5:22 PM, Doug Breaux wrote:
> On 9/12/2012 2:10 PM, Christopher Schultz wrote:
>> Doug,
>>
>> On 8/14/12 5:20 PM, Doug Breaux wrote:
>>> Both the VelocityTools Tools Usage Summary and the DateTool Javadoc seem
>>> to indicate a configuration mechanism for setting a TimeZone, but I
>>> simply can't discover what that is.
>>>
>>> DateTool's timezone setter is protected, and I don't want repeatedly
>>> pass a TimeZone into the overloaded format() methods.
>>
>> You might want to: your users might be in different TimeZones and you
>> don't want to force an arbitrary TimeZone (yours?) upon them, do you?
>>
>> -chris
> 
> Chris,
> 
> Reasonable point. However, in this case, all our users are in one
> TimeZone, a different one from our TimeZone.
> 
> However, even if I wanted to allow different TimeZones per user, I'd
> still probably want to set the TimeZone once per "execution" of a
> template and not have to explicitly reference it from each call inside
> that template. (Mind you, unless I needed to display items in multiple
> TimeZones.)

I suppose I was coming from a perspective of configuring the tool from
the toolbox. If you want to customize the TimeZone for the tool on a
given page, then you'd have to make the DateTool into a request-scoped
tool. But you still have to configure the toolbox globally and the
user's TimeZone isn't available at that time.

I suspect the decision to make setTimeZone protected was made so that an
application-scoped DateTool couldn't be corrupted by individual pages
attempting to set the TimeZone. DateTool itself is supposed to be
relatively stateless, and I agree with this architectural decision.

Yes, this means that it is slightly less convenient to use but it will
result in a more stable application.

> Thanks for making me think about those cases.
> 
> BTW, I got my answer at StackOverflow:
> http://stackoverflow.com/questions/11907365/how-do-i-set-a-timezone-for-velocitytools-datetool

I see you are using DateTool ina very limited context. If everything is
single-threaded (and especially if you already know the date format you
need), you can probably use SimpleDateFormat directly (which does allow
you to set the TimeZone directly) and not use DateTool at all.

Hope that helps,
-chris


Re: How do I set a TimeZone for VelocityTools DateTool?

Posted by Doug Breaux <br...@users.sourceforge.net>.
On 9/12/2012 2:10 PM, Christopher Schultz wrote:
> Doug,
>
> On 8/14/12 5:20 PM, Doug Breaux wrote:
>> Both the VelocityTools Tools Usage Summary and the DateTool Javadoc seem
>> to indicate a configuration mechanism for setting a TimeZone, but I
>> simply can't discover what that is.
>>
>> DateTool's timezone setter is protected, and I don't want repeatedly
>> pass a TimeZone into the overloaded format() methods.
>
> You might want to: your users might be in different TimeZones and you
> don't want to force an arbitrary TimeZone (yours?) upon them, do you?
>
> -chris

Chris,

Reasonable point. However, in this case, all our users are in one 
TimeZone, a different one from our TimeZone.

However, even if I wanted to allow different TimeZones per user, I'd 
still probably want to set the TimeZone once per "execution" of a 
template and not have to explicitly reference it from each call inside 
that template. (Mind you, unless I needed to display items in multiple 
TimeZones.)

Thanks for making me think about those cases.

BTW, I got my answer at StackOverflow:
http://stackoverflow.com/questions/11907365/how-do-i-set-a-timezone-for-velocitytools-datetool

--
Doug

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


Re: How do I set a TimeZone for VelocityTools DateTool?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Doug,

On 8/14/12 5:20 PM, Doug Breaux wrote:
> Both the VelocityTools Tools Usage Summary and the DateTool Javadoc seem
> to indicate a configuration mechanism for setting a TimeZone, but I
> simply can't discover what that is.
> 
> DateTool's timezone setter is protected, and I don't want repeatedly
> pass a TimeZone into the overloaded format() methods.

You might want to: your users might be in different TimeZones and you
don't want to force an arbitrary TimeZone (yours?) upon them, do you?

-chris


Re: How do I set a TimeZone for VelocityTools DateTool?

Posted by Claude Brisson <cl...@renegat.net>.
My answer on StackOverflow:

To pass configuration values to standard tools, you have to explicitly
list them in your WEB-INF/tools.xml file:

<?xml version="1.0"?>
<tools>
  <toolbox scope="application">
    <tool key="date"
          class="org.apache.velocity.tools.generic.DateTool"
          timezone="GMT+7"/>
    ...
  </toolbox>
  ...
</tools>
Please note that you can use the
org.apache.velocity.tools.generic.ComparisonDateTool for the same
purpose, which adds some nice date-time comparison features.


  Claude

On Tue, 14 Aug 2012 16:20:30 -0500
Doug Breaux <do...@gmail.com> wrote:

> Both the VelocityTools Tools Usage Summary and the DateTool Javadoc
> seem to indicate a configuration mechanism for setting a TimeZone,
> but I simply can't discover what that is.
> 
> DateTool's timezone setter is protected, and I don't want repeatedly 
> pass a TimeZone into the overloaded format() methods.
> 
> VelocityTools 2.0
> 
> (Also asked on StackOverflow if you want to answer there
> http://stackoverflow.com/questions/11907365/how-do-i-set-a-timezone-for-velocitytools-datetool 
> )
> 
> Doug
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 


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