{-# OPTIONS -fno-warn-unused-imports #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
#include "HsConfigure.h"
module Data.Time.Clock.UTC
(
UTCTime(..),NominalDiffTime
) where
import Control.DeepSeq
import Data.Time.Calendar.Days
import Data.Time.Clock.Scale
import Data.Fixed
import Data.Typeable
#if LANGUAGE_Rank2Types
import Data.Data
#endif
data UTCTime = UTCTime {
utctDay :: Day,
utctDayTime :: DiffTime
}
#if LANGUAGE_DeriveDataTypeable
#if LANGUAGE_Rank2Types
#if HAS_DataPico
deriving (Data, Typeable)
#endif
#endif
#endif
instance NFData UTCTime where
rnf (UTCTime d t) = d `deepseq` t `deepseq` ()
instance Eq UTCTime where
(UTCTime da ta) == (UTCTime db tb) = (da == db) && (ta == tb)
instance Ord UTCTime where
compare (UTCTime da ta) (UTCTime db tb) = case (compare da db) of
EQ -> compare ta tb
cmp -> cmp
newtype NominalDiffTime = MkNominalDiffTime Pico deriving (Eq,Ord
#if LANGUAGE_DeriveDataTypeable
#if LANGUAGE_Rank2Types
#if HAS_DataPico
,Data, Typeable
#endif
#endif
#endif
)
instance NFData NominalDiffTime where
rnf ndt = seq ndt ()
instance Enum NominalDiffTime where
succ (MkNominalDiffTime a) = MkNominalDiffTime (succ a)
pred (MkNominalDiffTime a) = MkNominalDiffTime (pred a)
toEnum = MkNominalDiffTime . toEnum
fromEnum (MkNominalDiffTime a) = fromEnum a
enumFrom (MkNominalDiffTime a) = fmap MkNominalDiffTime (enumFrom a)
enumFromThen (MkNominalDiffTime a) (MkNominalDiffTime b) = fmap MkNominalDiffTime (enumFromThen a b)
enumFromTo (MkNominalDiffTime a) (MkNominalDiffTime b) = fmap MkNominalDiffTime (enumFromTo a b)
enumFromThenTo (MkNominalDiffTime a) (MkNominalDiffTime b) (MkNominalDiffTime c) = fmap MkNominalDiffTime (enumFromThenTo a b c)
instance Show NominalDiffTime where
show (MkNominalDiffTime t) = (showFixed True t) ++ "s"
instance Num NominalDiffTime where
(MkNominalDiffTime a) + (MkNominalDiffTime b) = MkNominalDiffTime (a + b)
(MkNominalDiffTime a) - (MkNominalDiffTime b) = MkNominalDiffTime (a - b)
(MkNominalDiffTime a) * (MkNominalDiffTime b) = MkNominalDiffTime (a * b)
negate (MkNominalDiffTime a) = MkNominalDiffTime (negate a)
abs (MkNominalDiffTime a) = MkNominalDiffTime (abs a)
signum (MkNominalDiffTime a) = MkNominalDiffTime (signum a)
fromInteger i = MkNominalDiffTime (fromInteger i)
instance Real NominalDiffTime where
toRational (MkNominalDiffTime a) = toRational a
instance Fractional NominalDiffTime where
(MkNominalDiffTime a) / (MkNominalDiffTime b) = MkNominalDiffTime (a / b)
recip (MkNominalDiffTime a) = MkNominalDiffTime (recip a)
fromRational r = MkNominalDiffTime (fromRational r)
instance RealFrac NominalDiffTime where
properFraction (MkNominalDiffTime a) = (i,MkNominalDiffTime f) where
(i,f) = properFraction a
truncate (MkNominalDiffTime a) = truncate a
round (MkNominalDiffTime a) = round a
ceiling (MkNominalDiffTime a) = ceiling a
floor (MkNominalDiffTime a) = floor a
{-# RULES
"realToFrac/DiffTime->NominalDiffTime" realToFrac = \ dt -> MkNominalDiffTime (realToFrac dt)
"realToFrac/NominalDiffTime->DiffTime" realToFrac = \ (MkNominalDiffTime ps) -> realToFrac ps
"realToFrac/NominalDiffTime->Pico" realToFrac = \ (MkNominalDiffTime ps) -> ps
"realToFrac/Pico->NominalDiffTime" realToFrac = MkNominalDiffTime
#-}