{-# LANGUAGE Safe #-}
{-# OPTIONS -fno-warn-orphans #-}
module Data.Time.LocalTime.Internal.LocalTime (
LocalTime (..),
addLocalTime,
diffLocalTime,
utcToLocalTime,
localTimeToUTC,
ut1ToLocalTime,
localTimeToUT1,
) where
import Control.DeepSeq
import Data.Data
import Data.Time.Calendar.Days
import Data.Time.Calendar.Gregorian
import Data.Time.Clock.Internal.NominalDiffTime
import Data.Time.Clock.Internal.UTCDiff
import Data.Time.Clock.Internal.UTCTime
import Data.Time.Clock.Internal.UniversalTime
import Data.Time.LocalTime.Internal.TimeOfDay
import Data.Time.LocalTime.Internal.TimeZone
data LocalTime = LocalTime
{ LocalTime -> Day
localDay :: Day
, LocalTime -> TimeOfDay
localTimeOfDay :: TimeOfDay
}
deriving (LocalTime -> LocalTime -> Bool
(LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool) -> Eq LocalTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LocalTime -> LocalTime -> Bool
== :: LocalTime -> LocalTime -> Bool
$c/= :: LocalTime -> LocalTime -> Bool
/= :: LocalTime -> LocalTime -> Bool
Eq, Eq LocalTime
Eq LocalTime =>
(LocalTime -> LocalTime -> Ordering)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> LocalTime)
-> (LocalTime -> LocalTime -> LocalTime)
-> Ord LocalTime
LocalTime -> LocalTime -> Bool
LocalTime -> LocalTime -> Ordering
LocalTime -> LocalTime -> LocalTime
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LocalTime -> LocalTime -> Ordering
compare :: LocalTime -> LocalTime -> Ordering
$c< :: LocalTime -> LocalTime -> Bool
< :: LocalTime -> LocalTime -> Bool
$c<= :: LocalTime -> LocalTime -> Bool
<= :: LocalTime -> LocalTime -> Bool
$c> :: LocalTime -> LocalTime -> Bool
> :: LocalTime -> LocalTime -> Bool
$c>= :: LocalTime -> LocalTime -> Bool
>= :: LocalTime -> LocalTime -> Bool
$cmax :: LocalTime -> LocalTime -> LocalTime
max :: LocalTime -> LocalTime -> LocalTime
$cmin :: LocalTime -> LocalTime -> LocalTime
min :: LocalTime -> LocalTime -> LocalTime
Ord, Typeable LocalTime
Typeable LocalTime =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LocalTime -> c LocalTime)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LocalTime)
-> (LocalTime -> Constr)
-> (LocalTime -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LocalTime))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LocalTime))
-> ((forall b. Data b => b -> b) -> LocalTime -> LocalTime)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r)
-> (forall u. (forall d. Data d => d -> u) -> LocalTime -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> LocalTime -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime)
-> Data LocalTime
LocalTime -> Constr
LocalTime -> DataType
(forall b. Data b => b -> b) -> LocalTime -> LocalTime
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> LocalTime -> u
forall u. (forall d. Data d => d -> u) -> LocalTime -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LocalTime
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LocalTime -> c LocalTime
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LocalTime)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LocalTime)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LocalTime -> c LocalTime
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LocalTime -> c LocalTime
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LocalTime
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LocalTime
$ctoConstr :: LocalTime -> Constr
toConstr :: LocalTime -> Constr
$cdataTypeOf :: LocalTime -> DataType
dataTypeOf :: LocalTime -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LocalTime)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LocalTime)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LocalTime)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LocalTime)
$cgmapT :: (forall b. Data b => b -> b) -> LocalTime -> LocalTime
gmapT :: (forall b. Data b => b -> b) -> LocalTime -> LocalTime
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LocalTime -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> LocalTime -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> LocalTime -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LocalTime -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> LocalTime -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LocalTime -> m LocalTime
Data, Typeable)
instance NFData LocalTime where
rnf :: LocalTime -> ()
rnf (LocalTime Day
d TimeOfDay
t) = Day -> ()
forall a. NFData a => a -> ()
rnf Day
d () -> () -> ()
forall a b. a -> b -> b
`seq` TimeOfDay -> ()
forall a. NFData a => a -> ()
rnf TimeOfDay
t () -> () -> ()
forall a b. a -> b -> b
`seq` ()
instance Show LocalTime where
show :: LocalTime -> String
show (LocalTime Day
d TimeOfDay
t) = (Day -> String
showGregorian Day
d) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (TimeOfDay -> String
forall a. Show a => a -> String
show TimeOfDay
t)
addLocalTime :: NominalDiffTime -> LocalTime -> LocalTime
addLocalTime :: NominalDiffTime -> LocalTime -> LocalTime
addLocalTime NominalDiffTime
x = TimeZone -> UTCTime -> LocalTime
utcToLocalTime TimeZone
utc (UTCTime -> LocalTime)
-> (LocalTime -> UTCTime) -> LocalTime -> LocalTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NominalDiffTime -> UTCTime -> UTCTime
addUTCTime NominalDiffTime
x (UTCTime -> UTCTime)
-> (LocalTime -> UTCTime) -> LocalTime -> UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> LocalTime -> UTCTime
localTimeToUTC TimeZone
utc
diffLocalTime :: LocalTime -> LocalTime -> NominalDiffTime
diffLocalTime :: LocalTime -> LocalTime -> NominalDiffTime
diffLocalTime LocalTime
a LocalTime
b = UTCTime -> UTCTime -> NominalDiffTime
diffUTCTime (TimeZone -> LocalTime -> UTCTime
localTimeToUTC TimeZone
utc LocalTime
a) (TimeZone -> LocalTime -> UTCTime
localTimeToUTC TimeZone
utc LocalTime
b)
utcToLocalTime :: TimeZone -> UTCTime -> LocalTime
utcToLocalTime :: TimeZone -> UTCTime -> LocalTime
utcToLocalTime TimeZone
tz (UTCTime Day
day DiffTime
dt) = Day -> TimeOfDay -> LocalTime
LocalTime (Integer -> Day -> Day
addDays Integer
i Day
day) TimeOfDay
tod
where
(Integer
i, TimeOfDay
tod) = TimeZone -> TimeOfDay -> (Integer, TimeOfDay)
utcToLocalTimeOfDay TimeZone
tz (DiffTime -> TimeOfDay
timeToTimeOfDay DiffTime
dt)
localTimeToUTC :: TimeZone -> LocalTime -> UTCTime
localTimeToUTC :: TimeZone -> LocalTime -> UTCTime
localTimeToUTC TimeZone
tz (LocalTime Day
day TimeOfDay
tod) = Day -> DiffTime -> UTCTime
UTCTime (Integer -> Day -> Day
addDays Integer
i Day
day) (TimeOfDay -> DiffTime
timeOfDayToTime TimeOfDay
todUTC)
where
(Integer
i, TimeOfDay
todUTC) = TimeZone -> TimeOfDay -> (Integer, TimeOfDay)
localToUTCTimeOfDay TimeZone
tz TimeOfDay
tod
ut1ToLocalTime :: Rational -> UniversalTime -> LocalTime
ut1ToLocalTime :: Rational -> UniversalTime -> LocalTime
ut1ToLocalTime Rational
long (ModJulianDate Rational
date) =
Day -> TimeOfDay -> LocalTime
LocalTime (Integer -> Day
ModifiedJulianDay Integer
localMJD) (Rational -> TimeOfDay
dayFractionToTimeOfDay Rational
localToDOffset)
where
localTime :: Rational
localTime = Rational
date Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
+ Rational
long Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Rational
360 :: Rational
localMJD :: Integer
localMJD = Rational -> Integer
forall b. Integral b => Rational -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor Rational
localTime
localToDOffset :: Rational
localToDOffset = Rational
localTime Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- (Integer -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
localMJD)
localTimeToUT1 :: Rational -> LocalTime -> UniversalTime
localTimeToUT1 :: Rational -> LocalTime -> UniversalTime
localTimeToUT1 Rational
long (LocalTime (ModifiedJulianDay Integer
localMJD) TimeOfDay
tod) =
Rational -> UniversalTime
ModJulianDate ((Integer -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
localMJD) Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
+ (TimeOfDay -> Rational
timeOfDayToDayFraction TimeOfDay
tod) Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- (Rational
long Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Rational
360))
instance Show UniversalTime where
show :: UniversalTime -> String
show UniversalTime
t = LocalTime -> String
forall a. Show a => a -> String
show (Rational -> UniversalTime -> LocalTime
ut1ToLocalTime Rational
0 UniversalTime
t)