[commit: packages/time] master, wip/travis: Add secondsToDiffTime and picosecondsToDiffTime. (96ec994)

git at git.haskell.org git at git.haskell.org
Sat May 7 06:43:58 UTC 2016


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

On branches: master,wip/travis
Link       : http://git.haskell.org/packages/time.git/commitdiff/96ec99479c89cac13ac310b0b85536e6973c2af1

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

commit 96ec99479c89cac13ac310b0b85536e6973c2af1
Author: bjorn <bjorn at bringert.net>
Date:   Wed Nov 15 14:21:45 2006 -0800

    Add secondsToDiffTime and picosecondsToDiffTime.
    
    Rationale:
    As has come up on haskell-cafe
    (http://comments.gmane.org/gmane.comp.lang.haskell.cafe/15653), it
    takes a while to figure out how to make DiffTime values.
    
    secondsToDiffTime is not that important since it is just another name
    for fromInteger, but I suspect that it would be used a lot.  Using
    fromRational to create a DiffTime from a number of picoseconds is a
    bit of a hassle, so having a picosecondsToDiffTime would be useful.
    
    darcs-hash:20061115222145-6cdb2-4c0badc67fc5a5c1880c111902ee3e28ad793719


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

96ec99479c89cac13ac310b0b85536e6973c2af1
 Data/Time/Clock/Scale.hs | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Data/Time/Clock/Scale.hs b/Data/Time/Clock/Scale.hs
index b7bcf97..053c515 100644
--- a/Data/Time/Clock/Scale.hs
+++ b/Data/Time/Clock/Scale.hs
@@ -8,9 +8,11 @@ module Data.Time.Clock.Scale
 	UniversalTime(..),
 
 	-- * Absolute intervals
-	DiffTime
+	DiffTime,
+        secondsToDiffTime, picosecondsToDiffTime
 ) where
 
+import Data.Ratio ((%))
 import Data.Fixed
 
 -- | The Modified Julian Date is the day with the fraction of the day, measured from UT midnight.
@@ -55,3 +57,11 @@ instance Fractional DiffTime where
 	(MkDiffTime a) / (MkDiffTime b) = MkDiffTime (a / b)
 	recip (MkDiffTime a) = MkDiffTime (recip a)
 	fromRational r = MkDiffTime (fromRational r)
+
+-- | Create a 'DiffTime' which represents an integral number of seconds.
+secondsToDiffTime :: Integer -> DiffTime
+secondsToDiffTime = fromInteger
+
+-- | Create a 'DiffTime' from a number of picoseconds.
+picosecondsToDiffTime :: Integer -> DiffTime
+picosecondsToDiffTime x = fromRational (x % 1000000000000)



More information about the ghc-commits mailing list