module Data.Time.Clock.Scale
(
UniversalTime(..),
DiffTime,
secondsToDiffTime, picosecondsToDiffTime
) where
import Data.Ratio ((%))
import Data.Fixed
import Data.Typeable
newtype UniversalTime = ModJulianDate {getModJulianDate :: Rational} deriving (Eq,Ord)
instance Typeable UniversalTime where
typeOf _ = mkTyConApp (mkTyCon "Data.Time.Clock.Scale.UniversalTime") []
newtype DiffTime = MkDiffTime Pico deriving (Eq,Ord)
instance Typeable DiffTime where
typeOf _ = mkTyConApp (mkTyCon "Data.Time.Clock.Scale.DiffTime") []
instance Enum DiffTime where
succ (MkDiffTime a) = MkDiffTime (succ a)
pred (MkDiffTime a) = MkDiffTime (pred a)
toEnum = MkDiffTime . toEnum
fromEnum (MkDiffTime a) = fromEnum a
enumFrom (MkDiffTime a) = fmap MkDiffTime (enumFrom a)
enumFromThen (MkDiffTime a) (MkDiffTime b) = fmap MkDiffTime (enumFromThen a b)
enumFromTo (MkDiffTime a) (MkDiffTime b) = fmap MkDiffTime (enumFromTo a b)
enumFromThenTo (MkDiffTime a) (MkDiffTime b) (MkDiffTime c) = fmap MkDiffTime (enumFromThenTo a b c)
instance Show DiffTime where
show (MkDiffTime t) = (showFixed True t) ++ "s"
instance Num DiffTime where
(MkDiffTime a) + (MkDiffTime b) = MkDiffTime (a + b)
(MkDiffTime a) (MkDiffTime b) = MkDiffTime (a b)
(MkDiffTime a) * (MkDiffTime b) = MkDiffTime (a * b)
negate (MkDiffTime a) = MkDiffTime (negate a)
abs (MkDiffTime a) = MkDiffTime (abs a)
signum (MkDiffTime a) = MkDiffTime (signum a)
fromInteger i = MkDiffTime (fromInteger i)
instance Real DiffTime where
toRational (MkDiffTime a) = toRational a
instance Fractional DiffTime where
(MkDiffTime a) / (MkDiffTime b) = MkDiffTime (a / b)
recip (MkDiffTime a) = MkDiffTime (recip a)
fromRational r = MkDiffTime (fromRational r)
secondsToDiffTime :: Integer -> DiffTime
secondsToDiffTime = fromInteger
picosecondsToDiffTime :: Integer -> DiffTime
picosecondsToDiffTime x = fromRational (x % 1000000000000)