Skip to content

Exception: Time.toClockTime: picoseconds out of range

Got the "picoseconds out of range" exception when using addToClockTime TimeDiff ClockTime from System.Time

If you evaluate test1 or test3 you will either get a result or an exception.[[BR]] If you evaluate test2 you'll see that the TimeDiff often has a picosecond field that results in values outside the [0..999999999999] range enforced by 'toClockTime' of Time.hsc, as called from 'addToClockTime' in Time.hsc.

--BEGIN CODE--
module Test where

import System.IO
import System.Time

testTD = TimeDiff {
    tdYear    = 0,
    tdMonth   = 0,
    tdDay     = 0,
    tdHour    = 0,
    tdMin     = 10,
    tdSec     = 0,
    tdPicosec = 0
    }

test1 t = do
    to <- tdUntil (addToClockTime testTD t) >>= return . tdToSeconds
    hPutStrLn stdout ("timeout is:" ++ show to)

test2 t = do
    td <- tdUntil (addToClockTime testTD t)-- >>= return . tdToSeconds
    hPutStrLn stdout ("timediff is: " ++ show td)

test3 t = do
    toct <- tdUntil (addToClockTime testTD t) >>= return . (\td -> addToClockTime td (TOD 0 0))
    hPutStrLn stdout ("timeout ct is" ++ show toct)

tdToSeconds :: TimeDiff -> Integer
tdToSeconds td = s where
    TOD s p = addToClockTime td (TOD 0 0)

tdUntil :: ClockTime -> IO TimeDiff
tdUntil ct = getClockTime >>= return . (diffClockTimes ct)
--END CODE--
Trac metadata
Trac field Value
Version 6.4.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information