[Pkg-ganeti-devel] [ganeti] 48/165: Add a version of diffClockTimes working around ghc bug 2519
Apollon Oikonomopoulos
apoikos at moszumanska.debian.org
Tue Aug 11 13:53:12 UTC 2015
This is an automated email from the git hooks/post-receive script.
apoikos pushed a commit to branch master
in repository ganeti.
commit d7128d52cbbbf76ef7672e7ff164a145dafdd391
Author: Klaus Aehlig <aehlig at google.com>
Date: Thu Feb 19 13:17:41 2015 +0100
Add a version of diffClockTimes working around ghc bug 2519
While System.Time can in general work with is negative
or non-normalized time differences, it cannot work with
a negative pico-second component. This issue is known
for 7 years, see https://ghc.haskell.org/trac/ghc/ticket/2519,
so just work around it.
Signed-off-by: Klaus Aehlig <aehlig at google.com>
Reviewed-by: Helga Velroyen <helgav at google.com>
---
src/Ganeti/Utils.hs | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/Ganeti/Utils.hs b/src/Ganeti/Utils.hs
index 03e91e1..c2d1322 100644
--- a/src/Ganeti/Utils.hs
+++ b/src/Ganeti/Utils.hs
@@ -67,6 +67,7 @@ module Ganeti.Utils
, clockTimeToCTime
, clockTimeToUSec
, cTimeToClockTime
+ , diffClockTimes
, chompPrefix
, warn
, wrap
@@ -131,7 +132,8 @@ import System.Exit
import System.Posix.Files
import System.Posix.IO
import System.Posix.User
-import System.Time
+import System.Time (ClockTime(..), getClockTime, TimeDiff(..))
+import qualified System.Time as STime
-- * Debug functions
@@ -470,6 +472,17 @@ clockTimeToUSec (TOD ctime pico) =
cTimeToClockTime :: EpochTime -> ClockTime
cTimeToClockTime (CTime timet) = TOD (toInteger timet) 0
+-- | A version of `diffClockTimes` that works around ghc bug #2519.
+diffClockTimes :: ClockTime -> ClockTime -> TimeDiff
+diffClockTimes t1 t2 =
+ let delta = STime.diffClockTimes t1 t2
+ secondInPicoseconds = 1000000000000
+ in if tdPicosec delta < 0
+ then delta { tdSec = tdSec delta - 1
+ , tdPicosec = tdPicosec delta + secondInPicoseconds
+ }
+ else delta
+
{-| Strip a prefix from a string, allowing the last character of the prefix
(which is assumed to be a separator) to be absent from the string if the string
terminates there.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git
More information about the Pkg-ganeti-devel
mailing list