Re: Formatting a date
Tim Pizey <[email protected]> Wed, 29 Mar 2006 01:16:05 +0100
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Organization | PanEris |
| Message-ID | <[email protected]> |
On Monday 27 March 2006 20:54, Endre St=F8lsvik wrote: > On Mon, 27 Mar 2006, Alex Twisleton-Wykeham-Fiennes wrote: > | On Mon 27 March 2006 11:28, Marc Palmer wrote: > | > On 27 Mar 2006, at 11:13, Alex Twisleton-Wykeham-Fiennes wrote: > | > > On Mon 27 March 2006 11:00, Marc Palmer wrote: > | > >> On 27 Mar 2006, at 02:47, Sven Schliesing wrote: > | > >>> That's exactly what I looked for. > | > >> > | > >> There's another, potentially cleaner way... > | > >> > | > >> ----------------- "mymacros.wmm": > | > >> > | > >> #macro formatDate($d) > | > >> $Text.formatDate($d, "dd.MM.yyyy, HH:mm") > | > >> #end > | > >> > | > >> ----------------- "yourtemplate.wmt": > | > >> > | > >> #include as macro "mymacros.wmm" > | > >> > | > >> #formatDate($createdAt) > | > > > | > > Just to jump in for a moment - this will create a new > | > > SimpleDateFormat object > | > > every single time that it is invoked. If you know that you are > | > > going to be > | > > formatting a lot of different dates with the same format then it is > | > > considerably more efficient to drop in a dedicated wrapper around > | > > an instance > | > > of SimpleDateFormat that gives you the format that you want as > | > > otherwise each > | > > time that you invoke it, it will have to parse your "dd.MM.yyyy, > | > > HH:mm" > | > > format string, build the internal representation and then format > | > > the Date > | > > which is relatively expensive. > | > > | > You're absolutely right, but that can be dealt with using a macro > | > plus a #bean to create a "static" shared instance of the formatter? > | > | I'll also look at making $Text.formatDate cache the SimpleTextFormat > | objects that it creates and run some profiling to see whether or not th= is > | is really an advantage... > > And where should this cache reside? In which context? Who's gonna clean > it? When? How? (And how do I reload my webapp in Tomcat?) > > Caches on every corner, under every rock, in every creek, and in other > unknown places, is the way to evil code. > > Regards, > Endre. My gut feel would be to agree with Endre, but what do i know.=20 Getting back to the OP's requirement.=20 Why are you putting a raw date into the context? Why does everyone think it would be neat to have model level code in the vi= ew=20 layer? We deal with dates in melati by formatting them before they hit the context= ,=20 by which I mean we have getters on our objects which return Strings, taking= =20 into account locale.=20 I have every confidence that these plugable tools will not slow me or webma= cro=20 down if I don't use them, but I cannot understand why anyone would use them= =2E=20 cheers Tim =2D-=20 Registered linux user #21337, http://counter.li.org. ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642