Fantom

Login | Register

toStr in Duration

Xan
6 Jun 2012

Hi,

I have a 1180 ms duration and when I give a toStr it gives me obviously "1180ms". But I want to get "1second 180 ms" and if I have 61000 ms I want to display "1 min 1 second"

Is is possible to have it without not defining ad-hoc function?

Thanks, Xan.

andy
6 Jun 2012

Try toLocale

Xan
9 Jun 2012

It does not works. It returns "1180 ms" result too.

Xan.

StephenViles
10 Jun 2012

You could try porting one of the following from Ruby to Fantom:

You'll need to add code to handle milliseconds.

brian
11 Jun 2012

I really think Duration.toLocale will do what you want and it does proper localization. You have one specific example where it doesn't do exactly what you want, but that is because anything under 2sec is displayed in milliseconds. After that it starts rounding to the second. You should try it out with other values:

fansh> 1200ms.toLocale
1200ms
fansh> 2300ms.toLocale
2sec
fansh> 63sec.toLocale
1min 3sec
fansh> 123min.toLocale
2hr 3min
fansh> 27.2hr.toLocale
1day 3hr 12min

Xan
11 Jun 2012

Why under 2 sec this has this behaviour? Is it not logic?

Xan.

Login or Register to Reply

Back | All Topics