Concerning Time.TimeDiff

Graham Klyne
Mon, 02 Jun 2003 09:22:15 +0100

Following a brief off-list exchange, Simon Marlow suggested I post some 
notes here concerning Time.diffClockTimes and Time.TimeDiff.  These arise 
from my thought that the current behaviour of the GHC library in 
(sometimes) returning a value with positive seconds and negative 
picoseconds values might be viewed as perverse.  I'm trying to go beyond a 
"what is technically correct" viewpoint to "what is useful"...

I understand there's some history here, of which I'm not properly aware, so 
if this is merely rehashing old ground, please ignore.


What's useful here?  In practice, I think one would want to be able to 
compare and display time intervals.  Maybe the easiest form for doing this 
(for a multi-component value like TimeDiff) would be a sign+magnitude 
representation.  But TimeDiff doesn't allow for that, so what other options?

(a) all components except the most significant are positive,
(b) all components the same sign

Either of these allows component-wise comparison, from left to right.  I 
think (a) is easiest to format.  Of all the options, having the 
least-significant component negative and the rest positive really seems 
perverse, as I can't see how to compare or format the value without 
examining all of the fields before I start.

BTW, I'm also dubious about the desirability of including months and years 
in a time-difference value, because of the variability of months;  whenever 
I've implemented this kind of thing in the past, I use 
days/hours/mins/secs/sub-secs to measure intervals (though even this is 


I think it would be helpful if the Haskell Report documentation of 
diffClockTimes [1] were a little more specific, to the point of stating 
which way round the subtraction is performed, and also would say something 
about how negative time-differences should be returned.

Currently says:
Function getClockTime returns the current time in its internal 
representation. The expression addToClockTime d t adds a time difference d 
and a clock time t to yield a new clock time. The difference d may be 
either positive or negative. The expression diffClockTimes t1 t2 returns 
the difference between two clock times t1 and t2 as a TimeDiff.


Time representation is something that is difficult to get absolutely right 
for all purposes, so if the overall design is up for reconsideration I 
think it's important to have some idea of the intended scope of use.  (Pat 
Hayes summarized some work on the complexity of these issues to a Semantic 
Web calendaring meeting [2][3].)



Graham Klyne
PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E