Opened 9 years ago

Closed 9 years ago

Last modified 5 years ago

#588 closed bug (fixed)

Exception: Time.toClockTime: picoseconds out of range

Reported by: anonymous Owned by:
Priority: normal Milestone: 6.4.2
Component: libraries/base Version: 6.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

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.
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--

Change History (5)

comment:1 Changed 9 years ago by dylex@…

  • Architecture set to Unknown
  • Component changed from GHCi to libraries/base
  • difficulty set to Easy (1 hr)
  • Operating System set to Unknown

I ran into this too. I think this patch fixes it (I presume that's why the
FIXME was there):

--- libraries/base/System/Time.hsc.orig 2006-03-09 20:25:14.000000000 -0800
+++ libraries/base/System/Time.hsc      2006-03-09 20:28:37.000000000 -0800
@@ -270,8 +270,8 @@
                      60 * toInteger min +
                      3600 * toInteger hour +
                      24 * 3600 * toInteger day
-         cal      = toUTCTime (TOD (c_sec + sec_diff) (c_psec + psec))
-                                                       -- FIXME! ^^^^
+         (d_sec, d_psec) = (c_psec + psec) `quotRem` 1000000000000
+         cal      = toUTCTime (TOD (c_sec + sec_diff + d_sec) d_psec)
           new_mon  = fromEnum (ctMonth cal) + r_mon 
          month' = fst tmp
          yr_diff = snd tmp

comment:2 Changed 9 years ago by simonmar

  • Milestone set to 6.4.2
  • Resolution set to fixed
  • Status changed from new to closed

comment:3 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:4 Changed 6 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:5 Changed 5 years ago by simonmar

  • difficulty changed from Easy (1 hr) to Easy (less than 1 hour)
Note: See TracTickets for help on using tickets.