[commit: packages/time] format-widths,ghc,master,posix-perf,tasty: Use Word32 for ptNanoSeconds; replace normalizePosix with makePOSIXTime (c04bf45)

git at git.haskell.org git at git.haskell.org
Fri Apr 21 16:55:28 UTC 2017


Repository : ssh://git@git.haskell.org/time

On branches: format-widths,ghc,master,posix-perf,tasty
Link       : http://git.haskell.org/packages/time.git/commitdiff/c04bf45d01ecac8c150cf67097a8902846e383c0

>---------------------------------------------------------------

commit c04bf45d01ecac8c150cf67097a8902846e383c0
Author: Ashley Yakeley <ashley at yakeley.org>
Date:   Mon Dec 5 23:04:50 2016 -0800

    Use Word32 for ptNanoSeconds; replace normalizePosix with makePOSIXTime


>---------------------------------------------------------------

c04bf45d01ecac8c150cf67097a8902846e383c0
 lib/Data/Time/Clock/POSIX.hs | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/lib/Data/Time/Clock/POSIX.hs b/lib/Data/Time/Clock/POSIX.hs
index 68516cd..91a096a 100644
--- a/lib/Data/Time/Clock/POSIX.hs
+++ b/lib/Data/Time/Clock/POSIX.hs
@@ -2,20 +2,22 @@
 -- Most people won't need this module.
 module Data.Time.Clock.POSIX
 (
-    posixDayLength,POSIXTime(..),posixSecondsToUTCTime,utcTimeToPOSIXSeconds,getPOSIXTime,getCurrentTime
+    posixDayLength,POSIXTime,
+    makePOSIXTime,ptSeconds,ptNanoSeconds,
+    posixSecondsToUTCTime,utcTimeToPOSIXSeconds,getPOSIXTime,getCurrentTime
 ) where
 
 import Data.Time.Clock.UTC
 import Data.Time.Clock.Scale (picosecondsToDiffTime)
 import Data.Time.Calendar.Days
 import Data.Int (Int64)
+import Data.Word
 import Data.Fixed (divMod')
 import Control.DeepSeq
 
 #include "HsTimeConfig.h"
 
 #ifdef mingw32_HOST_OS
-import Data.Word (Word64)
 import System.Win32.Time
 #elif HAVE_CLOCK_GETTIME
 import Data.Time.Clock.CTimespec
@@ -31,36 +33,22 @@ import Foreign.C.Types (CLong(..))
 --
 data POSIXTime = POSIXTime
     { ptSeconds ::     {-# UNPACK #-} !Int64
-    , ptNanoSeconds :: {-# UNPACK #-} !Int64
-    }
+    , ptNanoSeconds :: {-# UNPACK #-} !Word32
+    } deriving (Eq,Ord)
 
-normalizePosix :: POSIXTime -> POSIXTime
-normalizePosix raw@(POSIXTime xs xn)
-    | xn < 0 || xn >= 1000000000 = POSIXTime (xs + q)  r
-    | otherwise                  = raw
+makePOSIXTime :: Int64 -> Word32 -> POSIXTime
+makePOSIXTime xs xn
+    | xn < 0 || xn >= 1000000000 = POSIXTime (xs + fromIntegral q)  r
+    | otherwise                  = POSIXTime xs xn
   where (q, r) = xn `divMod` 1000000000
 
-instance Eq POSIXTime where
-    rawx == rawy =
-        let POSIXTime xs xn = normalizePosix rawx
-            POSIXTime ys yn = normalizePosix rawy
-        in xs == ys && xn == yn
-
-instance Ord POSIXTime where
-    rawx `compare` rawy =
-        let POSIXTime xs xn = normalizePosix rawx
-            POSIXTime ys yn = normalizePosix rawy
-            os = compare xs ys
-        in if os == EQ then xn `compare` yn else os
-
 instance NFData POSIXTime where
     rnf a = a `seq` ()
 
 posixToUTCTime :: POSIXTime -> UTCTime
-posixToUTCTime raw =
-    let POSIXTime s ns = normalizePosix raw
-        (d, s') = s `divMod` posixDayLength
-        ps = s' * 1000000000000 + ns * 1000 -- 'Int64' can hold ps in one day
+posixToUTCTime (POSIXTime s ns) =
+    let (d, s') = s `divMod` posixDayLength
+        ps = s' * 1000000000000 + fromIntegral (ns * 1000) -- 'Int64' can hold ps in one day
     in UTCTime (addDays (fromIntegral d) unixEpochDay)
                (picosecondsToDiffTime (fromIntegral ps))
 



More information about the ghc-commits mailing list