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

Reply via email to