Re: Formatting a date

Alex Twisleton-Wykeham-Fiennes <[email protected]> Mon, 27 Mar 2006 22:27:07 +0100
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
On Mon 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?=20

Within the same class as the accessor.

> In which context?=20

The ClassLoader that loaded the accessor.

> Who's gonna clean =20
> it?=20

No-one.  It will cache at most the same number of unique SimpleDateFormats=
=20
that you create during the lifespan of your servlet.  This is assuming that=
=20
you never use a SimpleDateFormat more than once.   Any other case will almo=
st=20
definitely be considerably better (pending testing).

> When?=20

When the ClassLoader ditches the class definition and therefore by definiti=
on=20
the static variables.

> How? (And how do I reload my webapp in Tomcat?) =20

Same answer for both question:  same as you always did.

> Caches on every corner, under every rock, in every creek, and in other
> unknown places, is the way to evil code.

That's a fair enough assumption to make in certain contexts.  However, I'd =
be=20
really happy if you were to back up your viewpoint with some reasoned=20
arguments rather than your somewhat overzealous lashing out that seems to=20
accompany anyone's postings to the list.  This is supposed to be a communit=
y,=20
and people are doing things for nothing so if you are (somewhat) aggressive=
ly=20
negative about almost everything that people do (and I'm not just referring=
=20
to my stuff, I'm a *long* time lurker), then either people will stop=20
contributing or they will stop listening to what you have to say which woul=
d=20
be a shame because I'm sure that you have lots of constructive things to=20
contribute.

One of the reasons that I stuck around with the webmacro project for as lon=
g=20
as I have (not that I regret it for a minute) is that during the discussion=
s=20
with the apache project which led into the forking of webmacro and the=20
creation of Velocity, I felt that the webmacro community was the more order=
ed=20
and calm side of the argument (regardless of who was "right").  Lets try an=
d=20
keep it that way?

Alex


-------------------------------------------------------
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