[concurrency-interest] Small request regarding TimeUnit

Dawid Kurzyniec dawidk at mathcs.emory.edu
Tue Jan 16 17:07:52 EST 2007

Kasper Nielsen wrote:
> Dawid Kurzyniec wrote:
>> Kasper Nielsen wrote:
>>> Hi,
>>> Whenever I use TimeUnit and need to do any reporting in regards to 
>>> that. I often prefer outputting the actual unit in a short notation, 
>>> for example, ns instead of nanoseconds, µs instead of microseconds, ...
>>> I think it would a small but usefull addition (for some) to add some 
>>> kind of
>>> String getShortForm() method to TimeUnit.
>> I think MICROSECONDS might be problematic. Should it print u, or µ 
>> ?... I guess, depending on the context, people might want to have it 
>> either way.
>> D
> I would vote for µ, anyway should be a matter of a simple 
> .replace('µ','u') if people wants u instead

Actually, there is more questions. hours vs hrs, min vs mins vs m, etc. 
Personally, I think that this belongs to presentation layer, and should 
not be mixed with the concurrency API. Especially that the following is 
simple and efficient (version for the 1.4 backport):

private static ORDINAL_NSEC = TimeUnit.NANOSECONDS.ordinal();
private static ORDINAL_USEC = TimeUnit.MICROSECONDS.ordinal();

public static String unit2string(TimeUnit unit) {
   switch (unit.ordinal()) {
      case ORDINAL_NSEC: return "ns";
      case ORDINAL_USEC: return "us";


More information about the Concurrency-interest mailing list