Bug in Time module

2001-09-26 Thread Koen Claessen

Hi,

I discovered a bug in the Time module.  If I run the
following code snippet:

  main :: IO ()
  main =
do t0 - getClockTime
   system sleep 120
   t1 - getClockTime
   print (t1 `diffClockTimes` t0)

The TimeDiff value has a tdSec field greater than 59, and a
tdMin field of 0. I guess this is a bug.

I am running ghc-5.00.2 on Linux.

/Koen.

--
Koen Claessen http://www.cs.chalmers.se/~koen
phone:+46-31-772 5424  mailto:[EMAIL PROTECTED]
-
Chalmers University of Technology, Gothenburg, Sweden


___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs



Re: Bug in Time module

2001-09-26 Thread Michael Weber

On Wed, Sep 26, 2001 at 16:21:09 +0200, Koen Claessen wrote:
 I discovered a bug in the Time module.  If I run the
 following code snippet:

Just one? ;)

[...]
 The TimeDiff value has a tdSec field greater than 59, and a
 tdMin field of 0. I guess this is a bug.
 
 I am running ghc-5.00.2 on Linux.

Well, it's consistent with the comments in the code...

From ghc/lib/std/Time.hsc:
[...]
diffClockTimes  :: ClockTime - ClockTime - TimeDiff
-- diffClockTimes is meant to be the dual to `addToClockTime'.
-- If you want to have the TimeDiff properly splitted, use
-- `normalizeTimeDiff' on this function's result
--
-- CAVEAT: see comment of normalizeTimeDiff
diffClockTimes (TOD sa pa) (TOD sb pb) =
noTimeDiff{ tdSec = fromIntegral (sa - sb)
-- FIXME: can handle just 68 years...
  , tdPicosec = pa - pb
  }

normalizeTimeDiff :: TimeDiff - TimeDiff
-- FIXME: handle psecs properly
-- FIXME: ?should be called by formatTimeDiff automagically?
--
-- when applied to something coming out of `diffClockTimes', you loose
-- the duality to `addToClockTime', since a year does not always have
-- 365 days, etc.
--
-- apply this function as late as possible to prevent those rounding
-- errors
normalizeTimeDiff td =
[...]


The behaviour is arguable, but the Time module badly needs a rewrite,
anyway... there are still quite some more problems lurking in there...


Cheers,
Michael
-- 
() ASCII ribbon campaign |  Chair for Computer Science  II  | GPG: F65C68CD
/\ against HTML mail |   RWTH Aachen, Germany   | PGP: 1D0DD0B9
   SPITWADS ARE NOT FREE SPEECH
  -- Bart Simpson in 8F01

___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs



RE: Bug in Time module

2001-09-26 Thread Simon Marlow


 I discovered a bug in the Time module.  If I run the
 following code snippet:
 
   main :: IO ()
   main =
 do t0 - getClockTime
system sleep 120
t1 - getClockTime
print (t1 `diffClockTimes` t0)
 
 The TimeDiff value has a tdSec field greater than 59, and a
 tdMin field of 0. I guess this is a bug.

I'm not sure it's a bug - Haskell 98 doesn't require that the TimeDiff
value returned from diffClockTimes is normalised in any way, and it
can't be done in general of course because months and years have
different numbers of days, even minutes have different numbers of
seconds if leap seconds are taken into account.

In GHC there's an extension Time.normalizeTimeDiff which does the
obvious normalization (but in fact it assumes all months have 30 days,
so it looks pretty bogus to me).

Cheers,
Simon

___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs



RE: Bug in Time module

2001-09-26 Thread Koen Claessen


 | I'm not sure it's a bug - Haskell 98 doesn't require
 | that the TimeDiff value returned from diffClockTimes
 | is normalised in any way, and it can't be done in
 | general of course because months and years have
 | different numbers of days, even minutes have different
 | numbers of seconds if leap seconds are taken into
 | account.

You are absolutely right of course. Shouldn't this be
regarded as a bug in the Haskell'98 spec then? It is not
sure to me at all what a value of TimeDiff really means.

Maybe TimeDiff should only contain the fields: tdDay,
tdHour, tdMin, tdSec, and tdPicosec?

/Koen.


___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs