Re: How do I set a TimeZone for VelocityTools DateTool?
Christopher Schultz <[email protected]>
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <[email protected]> |
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
signature.asc
(application/pgp-signature, 304 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEUEARECAAYFAlBRRAEACgkQ9CaO5/Lv0PA/pQCY32QOt01EBk5uzDC28lh9pplQ NACfYXEly+f0Hun3Rdkb4t2W4UV4RmM= =Ags2 -----END PGP SIGNATURE-----