Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > I18N Question re presenting time remaining

Reply
Thread Tools

I18N Question re presenting time remaining

 
 
Rhino
Guest
Posts: n/a
 
      02-10-2005
I am writing an application in which I want to present a value that
represents the time remaining on a task, expressed in hours, minutes, and
seconds. In English, this would typically be presented as follows:

The time remaining is 4:05:24 (hours:minutes:seconds).

[I plan to include a bracketed string like '(hours:minutes:seconds)',
translated to the appropriate language, for each locale that I support, just
to make sure no one mistakenly assumes I mean 4 minutes, 5 seconds, and 24
hundreds - or 4 days, 5 hours, and 24 minutes!]

However, I feel sure that other locales will use different characters (or
spaces) in place of the colons that we use in English in presenting this
information.

Does anyone know how I can determine what 'punctuation' (for want of a
better term) I should be using for each locale and, especially, what Java
methods will determine the appropriate punctuation for a given locale?

--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare


 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      02-11-2005
Rhino wrote:
> Does anyone know how I can determine what 'punctuation' (for want of a
> better term) I should be using for each locale and, especially, what Java
> methods will determine the appropriate punctuation for a given locale?


To the best of my knowledge, there is no (simple) way to get that
information in Java. You can get a particular time format via
DateFormat.getTimeInstance(SHORT). But, and that is a big *BUT*, this
time format is intended for wall clock time. E.g. in countries with a
12hour time format you will get a format which includes the am/pm string
in that locale. And that one is totally unusable for displaying the
remaining time.

Java gets the defaults for these DateFormat instances from some internal
resource bundle, which does not have a public API.

You could try to get some clues out of the format pattern from the
particular DateFormat instance, but that would be rather ugly hack.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      02-11-2005

"Thomas Weidenfeller" <(E-Mail Removed)> wrote in message
news:cuhsi7$d2n$(E-Mail Removed)...
> Rhino wrote:
> > Does anyone know how I can determine what 'punctuation' (for want of a
> > better term) I should be using for each locale and, especially, what

Java
> > methods will determine the appropriate punctuation for a given locale?

>
> To the best of my knowledge, there is no (simple) way to get that
> information in Java. You can get a particular time format via
> DateFormat.getTimeInstance(SHORT). But, and that is a big *BUT*, this
> time format is intended for wall clock time. E.g. in countries with a
> 12hour time format you will get a format which includes the am/pm string
> in that locale. And that one is totally unusable for displaying the
> remaining time.
>
> Java gets the defaults for these DateFormat instances from some internal
> resource bundle, which does not have a public API.
>
> You could try to get some clues out of the format pattern from the
> particular DateFormat instance, but that would be rather ugly hack.
>
> /Thomas


Thanks, Thomas, for confirming what I suspected.

I did something similar to what you suggested: I used a DateFormatter on an
arbitrary date that was set to 1:00 AM, then parsed the resulting formatted
string for the first character after '1' to see what the punctuation for
that locale was. As a safeguard, I checked to make sure that the character
was not a letter or digit: if it is, I return a blank instead of whatever
character I found by parsing. This approach seemed like it should be safe
for any presentation of a time that I can imagine but, of course, I don't
know the actual local formats for all of Java's different locales so I could
be wrong

In any case, the worst that will happen with this approach is that the time
remaining will be formatted a bit strangely in some locales, assuming I ever
support those locales in the first place.

Rhino


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista: "Calculating time remaining" takes long time on any fileaction. Even with all suggested KB patches installed Peter Computer Support 2 12-15-2007 12:57 AM
Presenting VOIP as an ISDN/BRI trunk newsgroups@djguk_spam.co.uk UK VOIP 5 08-11-2005 05:07 PM
presenting an alternative when browser can't handle unicode symbols Jim Higson HTML 2 08-23-2004 06:15 PM
What is DHCP remaining time? Murray Computer Support 12 01-07-2004 04:40 PM
Re: Panasonic & Pioneer DVD players - time remaining display and black level settings? SloPoke DVD Video 0 08-18-2003 01:40 PM



Advertisments