From: Eric B. <er...@go...> - 2009-04-02 10:57:40
|
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:er...@go... http://www.gobosoft.com |