I18N Question re presenting time remaining

R

Rhino

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
 
T

Thomas Weidenfeller

Rhino said:
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
 
R

Rhino

Thomas Weidenfeller said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top