Re: Formatting a date

Keats Kirsch <[email protected]> Mon, 27 Mar 2006 11:36:06 -0500
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
>I'll also look at making $Text.formatDate cache the SimpleTextFormat objects 
>that it creates and run some profiling to see whether or not this is really 
>an advantage...
>  
>
Yes the formatDate() method was kind of a quick hack.  At one point I 
had written a DateTool, but I never got it clean enough to commit to CVS 
(and now I've lost it).  Perhaps I'll give it another whack.  It's 
actually fairly complicated, given all the different date formats and 
localization etc.  It would be nice if the tool could pick up the locale 
from the request, but then it would be Servlet specific.  But something 
simple would probably be useful for parsing and formatting dates. 

I'm thinking a factory that would produce date wrappers.  E.g.,

#set $dt = $DateFactory.parse("27-Mar-2006", "dd-MMM-yyyy")
#set $dt.Format.Short = "MM/dd/yyyy"
#set $dt.Format.Default = "dd-MMM-yyyy"

Default format: $dt                      ==> 27-Mar-2006
Short format: $dt.Format.Short   ==> 02/27/2006

#set $dt = $dt.addMonths(1)
New date: $dt    ==> 27-Apr-2006

etc.

Thoughts?

Keats

>A
>
>  
>
>>Of course then this offers little benefit, if not making things
>>worse, over using Keats' #bean approach...
>>
>>#formatDate($createdAt)
>>
>>vs.
>>
>>$sharedFormatter.format($createdAt)
>>
>>...and with my own caveats about using "directive" style macros I
>>think the latter, Keats' scenario is better.
>>
>>Ahhhh now I'm thinking in Spring terms, and changing the topic... hmm
>>it would be really nice if we could add some kind of context provider
>>that populates the context with all the beans from a Spring
>>BeanContext :)
>>
>>Cheers
>>
>>
>>
>>-------------------------------------------------------
>>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
>>_______________________________________________
>>Webmacro-user mailing list
>>[email protected]
>>https://lists.sourceforge.net/lists/listinfo/webmacro-user
>>    
>>
>
>
>-------------------------------------------------------
>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
>_______________________________________________
>Webmacro-user mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/webmacro-user
>
>  
>




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