{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE PatternSynonyms #-}
#endif
module Data.Thyme.Clock (
UTCTime
, utctDay, utctDayTime
, _utctDay, _utctDayTime
#if __GLASGOW_HASKELL__ >= 708
, pattern UTCTime
#endif
, mkUTCTime
, utcTime
, UTCView (..), _utcvDay, _utcvDayTime
, NominalDiffTime
, getCurrentTime
, DiffTime
, TimeDiff (..)
, toSeconds, fromSeconds
, toSeconds', fromSeconds'
, picoseconds
, UniversalTime
#if __GLASGOW_HASKELL__ >= 708
, pattern UniversalTime
#endif
, modJulianDate
, getModJulianDate
, mkModJulianDate
, secondsToDiffTime
, picosecondsToDiffTime
, unUTCTime
, addUTCTime
, diffUTCTime
, toMicroseconds
, fromMicroseconds
) where
import Prelude
import Control.Lens
import Data.AffineSpace
import Data.Int
import Data.Ratio ((%))
import Data.Thyme.Clock.Internal
import Data.Thyme.Clock.POSIX
getCurrentTime :: IO UTCTime
getCurrentTime :: IO UTCTime
getCurrentTime = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s t a b. AReview s t a b -> b -> t
review Iso' UTCTime POSIXTime
posixTime) IO POSIXTime
getPOSIXTime
{-# INLINE picoseconds #-}
picoseconds :: (TimeDiff t) => Iso' t Integer
picoseconds :: forall t. TimeDiff t => Iso' t Integer
picoseconds = forall t. TimeDiff t => Iso' t Int64
microseconds forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
(forall a. Num a => a -> a -> a
(*) Integer
1000000 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Integral a => a -> Integer
toInteger) (\ Integer
ps -> forall a b. (RealFrac a, Integral b) => a -> b
round (Integer
ps forall a. Integral a => a -> a -> Ratio a
% Integer
1000000))
{-# INLINE getModJulianDate #-}
getModJulianDate :: UniversalTime -> Rational
getModJulianDate :: UniversalTime -> Rational
getModJulianDate = forall a s. Getting a s a -> s -> a
view Iso' UniversalTime Rational
modJulianDate
{-# INLINE mkModJulianDate #-}
mkModJulianDate :: Rational -> UniversalTime
mkModJulianDate :: Rational -> UniversalTime
mkModJulianDate = forall s t a b. AReview s t a b -> b -> t
review Iso' UniversalTime Rational
modJulianDate
{-# INLINE secondsToDiffTime #-}
secondsToDiffTime :: Int64 -> DiffTime
secondsToDiffTime :: Int64 -> DiffTime
secondsToDiffTime = forall n t. (Real n, TimeDiff t) => n -> t
fromSeconds
{-# INLINE picosecondsToDiffTime #-}
picosecondsToDiffTime :: Integer -> DiffTime
picosecondsToDiffTime :: Integer -> DiffTime
picosecondsToDiffTime = forall s t a b. AReview s t a b -> b -> t
review forall t. TimeDiff t => Iso' t Integer
picoseconds
{-# INLINE unUTCTime #-}
unUTCTime :: UTCTime -> UTCView
unUTCTime :: UTCTime -> UTCView
unUTCTime = forall a s. Getting a s a -> s -> a
view Iso' UTCTime UTCView
utcTime
{-# INLINE addUTCTime #-}
addUTCTime :: NominalDiffTime -> UTCTime -> UTCTime
addUTCTime :: POSIXTime -> UTCTime -> UTCTime
addUTCTime = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall p. AffineSpace p => p -> Diff p -> p
(.+^)
{-# INLINE diffUTCTime #-}
diffUTCTime :: UTCTime -> UTCTime -> NominalDiffTime
diffUTCTime :: UTCTime -> UTCTime -> POSIXTime
diffUTCTime = forall p. AffineSpace p => p -> p -> Diff p
(.-.)
{-# INLINE toMicroseconds #-}
toMicroseconds :: (TimeDiff t) => t -> Int64
toMicroseconds :: forall t. TimeDiff t => t -> Int64
toMicroseconds = forall a s. Getting a s a -> s -> a
view forall t. TimeDiff t => Iso' t Int64
microseconds
{-# INLINE fromMicroseconds #-}
fromMicroseconds :: (TimeDiff t) => Int64 -> t
fromMicroseconds :: forall t. TimeDiff t => Int64 -> t
fromMicroseconds = forall s t a b. AReview s t a b -> b -> t
review forall t. TimeDiff t => Iso' t Int64
microseconds