module Data.UTC.Type.Local
( Local (..)
) where
import Data.Maybe
import Data.UTC.Class.Epoch
import Data.UTC.Class.IsTime
import Data.UTC.Type.Time
data Local time
= Local
{
offset :: Maybe Rational
, utc :: time
}
instance Eq t => Eq (Local t) where
(==) (Local _ a) (Local _ b)
= a == b
instance Ord t => Ord (Local t) where
compare (Local _ a) (Local _ b)
= compare a b
instance Epoch t => Epoch (Local t) where
epoch
= Local Nothing epoch
instance Functor Local where
fmap f (Local o t)
= Local o (f t)
instance Bounded t => Bounded (Local t) where
minBound = Local Nothing minBound
maxBound = Local Nothing maxBound
instance IsTime (Local Time) where
hour (Local Nothing t)
= hour t
hour (Local (Just 0) t)
= hour t
hour (Local (Just o) t)
= hour
$ fromMaybe undefined $ addSecondFractions o t
minute (Local Nothing t)
= minute t
minute (Local (Just 0) t)
= minute t
minute (Local (Just o) t)
= minute
$ fromMaybe undefined $ addSecondFractions o t
second (Local Nothing t)
= second t
second (Local (Just 0) t)
= second t
second (Local (Just o) t)
= second
$ fromMaybe undefined $ addSecondFractions o t
secondFraction (Local Nothing t)
= secondFraction t
secondFraction (Local (Just 0) t)
= secondFraction t
secondFraction (Local (Just o) t)
= secondFraction
$ fromMaybe undefined $ addSecondFractions o t
setHour h (Local o@Nothing t)
= Local o <$> setHour h t
setHour h (Local o@(Just 0) t)
= Local o <$> setHour h t
setHour h (Local o@(Just i) t)
= Local o <$> ( addSecondFractions i t >>= setHour h >>= addSecondFractions (negate i) )
setMinute h (Local o@Nothing t)
= Local o <$> setMinute h t
setMinute h (Local o@(Just 0) t)
= Local o <$> setMinute h t
setMinute h (Local o@(Just i) t)
= Local o <$> ( addSecondFractions i t >>= setMinute h >>= addSecondFractions (negate i) )
setSecond h (Local o@Nothing t)
= Local o <$> setSecond h t
setSecond h (Local o@(Just 0) t)
= Local o <$> setSecond h t
setSecond h (Local o@(Just i) t)
= Local o <$> ( addSecondFractions i t >>= setSecond h >>= addSecondFractions (negate i) )
setSecondFraction h (Local o@Nothing t)
= Local o <$> setSecondFraction h t
setSecondFraction h (Local o@(Just 0) t)
= Local o <$> setSecondFraction h t
setSecondFraction h (Local o@(Just i) t)
= Local o <$> ( addSecondFractions i t >>= setSecondFraction h >>= addSecondFractions (negate i) )