jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Dawson <tdaw...@wamnet.com>
Subject RE: datetime TAGlib -> FormatTag.java
Date Fri, 27 Apr 2001 12:11:40 GMT
I see where you're going with this...  a few comments.

> <i18n:formatDate value="<%= new Date() %>" style="short"/>
> 
> <i18n:formatDate value="<%= new Date() %>" pattern="yyyy.MMMMM.dd GGG
> hh:mm"/>

style and pattern are both used identically in MessageFormat

(from MessageFormat's javadoc)
 datetimeStyle := "short"
                  | "medium"
                  | "long"
                  | "full"
                  | dateFormatPattern

someone could just type pattern="short" and it would do the same thing as
style="short", so you wouldn't need both attributes, just one.  unless, of
course, you wanted the style attribute to validate the entries, while
pattern lets everything in.

if we're going with a formatDate, might as well have a formatTime attribute
too.

(from MessageFormat's javadoc)
 elementFormat := "time" { "," datetimeStyle }
                | "date" { "," datetimeStyle }
                | "number" { "," numberStyle }
                | "choice" { "," choiceStyle }

(as a side note, I don't think "choice" would make a lot of sense as its own
format tag, if you're doing that, should probably use a full message with
stuff from the i18n bundle)

> <i18n:formatNumber value="<%= 12345.1234  %>" 
> pattern="##,###,###.##"/>
> 
> <i18n:formatCurrency value="<%= 12345.1234 %>" 
> pattern="##,###,###.##"/>

formatCurrency doesn't actually work to have a pattern. currencies are
formatted according to locale-specific rules, so patterns don't make sense.
besides, MessageFormat sees a number as a number as a number, with pattern
and currency being peer options. you can't specify both.

(from MessageFormat's javadoc)
 numberStyle := "currency"
               | "percent"
               | "integer"
               | numberFormatPattern

So as I see it the custom format tags would look like this:

<i18n:formatDate value="<%= new Date() %>"
                 style="short"/>
<i18n:formatDate value="<%= new Date() %>"
                 pattern="yyyy.MMMMM.dd GGG hh:mm"/>
<i18n:formatTime value="<%= new Date() %>"
                 style="short"/>
<i18n:formatTime value="<%= new Date() %>"
                 pattern="yyyy.MMMMM.dd GGG hh:mm"/>
<i18n:formatNumber value="<%= 12345.1234  %>"
                   pattern="##,###,###.##"/>
<i18n:formatNumber value="<%= 12345.12  %>"
                   style="currency"/>

and what they would do is simply create a message format patterns based on
the argument.

as for the attributes themselves, should we go with just style, just
pattern, or both? I'd prefer just picking one, but I don't care which.
either way, it would be optional, because it's optional for MessageFormat &
it would just use a default.

one other attribute that might be optional is the value attribute for date.
I see a lot of people probably creating the current date - if we make the
value optional, it would use the current date.

<i18n:formatDate value="<%= new Date() %>" style="short"/>
is equivalent to
<i18n:formatDate style="short"/>

just a thought.

back to currency for a seciond -- when dealing with locales, currency gets
messy because although I may be displaying a page in japanese, if I have a
number whose value is in US Dollars, I'd better not use the japanese
locale's formatCurrency! perhaps currency SHOULD be a different tag, but not
allow a pattern to be provided, but instead a locale?  hmm...

------------------------------------------

one other thing to consider is whether this should be part if i18n. it
wouldn't strictly have to be, because you're not really using the bundle
that the i18n taglib chooses. it could be a completely separate taglib that
just uses whatever locale is listed by the request object as the preferred
locale.

however, I think it is a really good idea to make it part of i18n, because
if you are using i18n, you'd want these format tags to use the same locale
-- i18n doesn't necessarily use the preferred locale if a bundle isn't
available for it.

Tim


> -----Original Message-----
> From: James Strachan [mailto:james_strachan@yahoo.co.uk]
> Sent: Tuesday, April 24, 2001 8:21 AM
> To: taglibs-dev@jakarta.apache.org
> Subject: Re: datetime TAGlib -> FormatTag.java
> 
> 
> From: "Tim Dawson" <tdawson@wamnet.com>
> 
> 
> > I'd much rather see the above than a i18n:formatDate or 
> whatever, because
> at
> > least you provide some additional formatting, e.g. 
> {0,date,medium} vs.
> > {0,date,short}.
> 
> 
> I was thinking more of having additional formatting tags 
> explicitly for
> Date, Number and Currency which would then allow for the 
> explicit provision
> of either a style (short/medium/long) or an explicit 
> formatting pattern to
> be used if necessary. Since there is some cross over with existing
> functionality, I thought the i18n tag library might be a good 
> place to put
> the new tags.
> 
> Something along the lines of:-
> 
> <i18n:formatDate value="<%= new Date() %>" style="short"/>
> 
> <i18n:formatDate value="<%= new Date() %>" pattern="yyyy.MMMMM.dd GGG
> hh:mm"/>
> 
> <i18n:formatNumber value="<%= 12345.1234  %>" 
> pattern="##,###,###.##"/>
> 
> <i18n:formatCurrency value="<%= 12345.1234 %>" 
> pattern="##,###,###.##"/>
> 
> Similar parsing tags which take a String and create a Date / 
> Number could be
> done too.
> Just a thought...
> 
> James
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 

Mime
View raw message