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
Description: OpenPGP digital signature