Time milliseconds

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Time milliseconds

Steve Alan Waring
Hi,

Could Time (class)>>readFrom: recognise $. as a valid separator between
seconds and milliseconds, and read the milliseconds as a real value?

This parses as one millisecond;
    (Time fromString: '00:00:00:1') milliseconds

This does not;
    (Time fromString: '00:00:00.001') milliseconds

The Locale time format string can not print milliseconds, but I see the
second format more commonly used, and it would be useful to be
able to parse it.

Thanks,
Steve
[hidden email]
http://www.dolphinharbor.org


Reply | Threaded
Open this post in threaded view
|

Re: Time milliseconds

Ian Bartholomew-13
Steve,

> Could Time (class)>>readFrom: recognise $. as a valid separator between
> seconds and milliseconds, and read the milliseconds as a real value?

As a workaround you could go through Duration (one of my goodies).

(DurationToText new convertFromRightToLeft: '00:00:00.1') milliseconds
    ==> 100

(DurationToText new convertFromRightToLeft: '00:00:00.01') milliseconds
    ==> 10

(DurationToText new convertFromRightToLeft: '00:00:00.001') milliseconds
    ==> 1

(DurationToText new convertFromRightToLeft: '00:00:00.0001') milliseconds
    ==> 0

You would also need to implement a Duration>>asTime or Time>>fromDuration
method that answers an instantiated Time but that won't be to difficult - I
probably should have implemented it myself.  You can also add a method that
answers the millisecond value to it's full precision (max 10e-6 of a second)
if needed.

NB: It doesn't work with the other format you mentioned - '00:00:00:123'
would be parsed as 123 seconds.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Time milliseconds

Blair McGlashan
In reply to this post by Steve Alan Waring
"Steve Waring" <[hidden email]> wrote in message
news:acvao8$slps9$[hidden email]...
> Hi,
>
> Could Time (class)>>readFrom: recognise $. as a valid separator between
> seconds and milliseconds, and read the milliseconds as a real value?

Sure. Recorded as #956 for the next patch.

Regards

Blair