module Reactive.TimeStamp where
data TimeStamp d = TimeStamp {getTimeStamp :: !d} deriving (Show)
timeStampDelta :: Num d => TimeStamp d -> TimeStamp d -> d
timeStampDelta (TimeStamp d1) (TimeStamp d2) = d1 d2
shiftTimeStamp :: Num d => d -> TimeStamp d -> TimeStamp d
shiftTimeStamp d (TimeStamp d1) = TimeStamp (d1 + d)
instance (Eq d) => Eq (TimeStamp d) where
(==) (TimeStamp d1) (TimeStamp d2) = d1 == d2
instance (Ord d) => Ord (TimeStamp d) where
(<=) (TimeStamp d1) (TimeStamp d2) = d1 <= d2
data WakeUpOrder d = WakeUp (TimeStamp d) | NoWakeUp deriving (Show)
wakeToTime :: WakeUpOrder d -> Maybe (TimeStamp d)
wakeToTime (NoWakeUp) = Nothing
wakeToTime (WakeUp ts) = Just ts
instance (Eq d) => Eq (WakeUpOrder d) where
(==) w1 w2 = case (w1,w2) of
(NoWakeUp, NoWakeUp) -> True
(WakeUp d1,WakeUp d2) -> d1 == d2
_ -> False
instance (Ord d) => Ord (WakeUpOrder d) where
(<=) _ NoWakeUp = True
(<=) NoWakeUp _ = False
(<=) (WakeUp d1) (WakeUp d2) = d1 <= d2