Questions regarding DT_TIME

5 messages Options
Embed this post
Permalink
Paul Cohen-4

Questions regarding DT_TIME

Reply Threaded More More options
Print post
Permalink
Hi,

I have implemented a very simple DT_STOPWATCH class for doing simple
timing stuff (ie. start, stop & elapsed_time). In that class I use the
feature DT_TIME.duration. To my surprise I occasionally get negative
seconds and milliseconds.

In DT_TIME there is the feature:

    duration (other: like Current): DT_TIME_DURATION is
            -- Duration between `other' and `Current'
        do
            Result := time_duration (other)
        end

I then realize that DT_TIME.duration uses DT_TIME.time_duration which does:

    create Result.make_precise (hour - other.hour, minute -
other.minute, second - other.second, millisecond - other.millisecond)

where Result & other are DT_TIME. I now realize that I must use
DT_TIME.canonical_duration to get the result I expect since it
calculates the difference (correctly) based on the milliseconds count
of both DT_TIME instances. My questions are:

   1. Why doesn't DT_TIME.duration use DT_TIME.canonical_duration?

   2. When & why does anyone want to use DT_TIME.time_duration in its
current implementation?

   3. DT_TIME.time_duration has a misleading name. Better is
DT_TIME.time_unit_differences or something like that which says what
it does.

   4. Is the Gobo project interested in my DT_STOPWATCH class?

I'm using:
  * Gobo 3.8
  * EiffelStudio: 6.2
  * On Linux/gcc

/Paul

--
Paul Cohen
www.seibostudios.se
mobile: +46 730 787 035
e-mail: [hidden email]

------------------------------------------------------------------------------
_______________________________________________
gobo-eiffel-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop
Eric Bezault

Re: Questions regarding DT_TIME

Reply Threaded More More options
Print post
Permalink
Paul Cohen wrote:

> I have implemented a very simple DT_STOPWATCH class for doing simple
> timing stuff (ie. start, stop & elapsed_time). In that class I use the
> feature DT_TIME.duration. To my surprise I occasionally get negative
> seconds and milliseconds.
>
> In DT_TIME there is the feature:
>
>     duration (other: like Current): DT_TIME_DURATION is
>             -- Duration between `other' and `Current'
>         do
>             Result := time_duration (other)
>         end
>
> I then realize that DT_TIME.duration uses DT_TIME.time_duration which does:
>
>     create Result.make_precise (hour - other.hour, minute -
> other.minute, second - other.second, millisecond - other.millisecond)
>
> where Result & other are DT_TIME. I now realize that I must use
> DT_TIME.canonical_duration to get the result I expect since it
> calculates the difference (correctly) based on the milliseconds count
> of both DT_TIME instances.

All that is explained in $GOBO/doc/time/absolute.html#time

> My questions are:
>
>    1. Why doesn't DT_TIME.duration use DT_TIME.canonical_duration?

DT_TIME.duration is just a quick way to compute the duration.
The result is correct. It's just that it is not canonical.
As you figured out, to get canonical result you can use
DT_TIME.canonical_duration, or call `set_canonical' on the
result of DT_TIME.duration.

>    2. When & why does anyone want to use DT_TIME.time_duration in its
> current implementation?

A program might want to compute several durations, add them together
and then compute the canonical form of the result instead of computing
the canonical form at each stage.

>    3. DT_TIME.time_duration has a misleading name. Better is
> DT_TIME.time_unit_differences or something like that which says what
> it does.

In fact `time_duration' is not meant to be used in DT_TIME.
You should use DT_TIME.duration instead. The usefulness of
`time_duration' comes in the descendant class DT_DATE_TIME.
It means the time part of the duration. In the same way
`date_duration' is the date part of the duration.

>    4. Is the Gobo project interested in my DT_STOPWATCH class?

Yes. But I'm just wondering why you use DT_TIME and not
DT_DATE_TIME. Don't you have problems when running it
around midnight?

--
Eric Bezault
mailto:[hidden email]
http://www.gobosoft.com

------------------------------------------------------------------------------
_______________________________________________
gobo-eiffel-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop
Paul Cohen-4

Re: Questions regarding DT_TIME

Reply Threaded More More options
Print post
Permalink
Hi Eric,

On Thu, Apr 2, 2009 at 12:30 PM, Eric Bezault <[hidden email]> wrote:
> All that is explained in $GOBO/doc/time/absolute.html#time

Oops! Sorry. Please accept my humble apology!

>> My questions are:
>>
>>   1. Why doesn't DT_TIME.duration use DT_TIME.canonical_duration?

As a client, without reading the contracts, I would still simply
assume "duration" had the semantics of "canonical_duration". But ok,
now I know why it works like it does.

>>   4. Is the Gobo project interested in my DT_STOPWATCH class?
>
> Yes. But I'm just wondering why you use DT_TIME and not
> DT_DATE_TIME. Don't you have problems when running it
> around midnight?

So far I've been timing seconds and milliseconds in command line
programs so it hasn't been a problem. But you are right of course.
I'll change that.

I've written small DS_TEST_CASE based test case for the class. Either
you give me write access to the SVN repository or I can send you a
small tarball with the code (2 classes and an ugly .ecf file).

/Paul

--
Paul Cohen
www.seibostudios.se
mobile: +46 730 787 035
e-mail: [hidden email]

------------------------------------------------------------------------------
_______________________________________________
gobo-eiffel-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop
Eric Bezault

Re: Questions regarding DT_TIME

Reply Threaded More More options
Print post
Permalink
Paul Cohen wrote:
>>>   1. Why doesn't DT_TIME.duration use DT_TIME.canonical_duration?
>
> As a client, without reading the contracts,

"Without reading the contracts"! What a strange thing to do ;-)

>>>   4. Is the Gobo project interested in my DT_STOPWATCH class?
>> Yes. But I'm just wondering why you use DT_TIME and not
>> DT_DATE_TIME. Don't you have problems when running it
>> around midnight?
>
> So far I've been timing seconds and milliseconds in command line
> programs so it hasn't been a problem. But you are right of course.
> I'll change that.
>
> I've written small DS_TEST_CASE based test case for the class. Either
> you give me write access to the SVN repository or I can send you a
> small tarball with the code (2 classes and an ugly .ecf file).

I can send me a small tarball.
Thanks.

--
Eric Bezault
mailto:[hidden email]
http://www.gobosoft.com

------------------------------------------------------------------------------
_______________________________________________
gobo-eiffel-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop
Eric Bezault

Re: Questions regarding DT_TIME

Reply Threaded More More options
Print post
Permalink
Paul Cohen wrote:
>>>>   4. Is the Gobo project interested in my DT_STOPWATCH class?

It's now in Gobo SVN repository.

--
Eric Bezault
mailto:[hidden email]
http://www.gobosoft.com

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
gobo-eiffel-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop