{-# LINE 1 "Data/UnixTime/Types.hsc" #-}
{-# LANGUAGE DeriveGeneric #-}

module Data.UnixTime.Types where

import Control.Applicative ((<$>), (<*>))
import Data.ByteString
import Data.ByteString.Char8 ()
import Data.Int

{-# LINE 12 "Data/UnixTime/Types.hsc" #-}
import Foreign.C.Types
import Foreign.Storable

{-# LINE 15 "Data/UnixTime/Types.hsc" #-}
import Data.Binary

{-# LINE 17 "Data/UnixTime/Types.hsc" #-}
import GHC.Generics



-- |
-- Data structure for Unix time.
--
-- Please note that this uses GHC-derived 'Eq' and 'Ord' instances.
-- Notably
--
-- >>> UnixTime 1 0 > UnixTime 0 999999999
-- True
--
-- You should instead use 'UnixDiffTime' along with its helpers such
-- as 'Data.UnixTime.microSecondsToUnixDiffTime' which will ensure
-- that such unusual values are never created.
data UnixTime = UnixTime {
    -- | Seconds from 1st Jan 1970
    UnixTime -> CTime
utSeconds :: {-# UNPACK #-} !CTime
    -- | Micro seconds (i.e. 10^(-6))
  , UnixTime -> Int32
utMicroSeconds :: {-# UNPACK #-} !Int32
  } deriving (UnixTime -> UnixTime -> Bool
(UnixTime -> UnixTime -> Bool)
-> (UnixTime -> UnixTime -> Bool) -> Eq UnixTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnixTime -> UnixTime -> Bool
== :: UnixTime -> UnixTime -> Bool
$c/= :: UnixTime -> UnixTime -> Bool
/= :: UnixTime -> UnixTime -> Bool
Eq,Eq UnixTime
Eq UnixTime =>
(UnixTime -> UnixTime -> Ordering)
-> (UnixTime -> UnixTime -> Bool)
-> (UnixTime -> UnixTime -> Bool)
-> (UnixTime -> UnixTime -> Bool)
-> (UnixTime -> UnixTime -> Bool)
-> (UnixTime -> UnixTime -> UnixTime)
-> (UnixTime -> UnixTime -> UnixTime)
-> Ord UnixTime
UnixTime -> UnixTime -> Bool
UnixTime -> UnixTime -> Ordering
UnixTime -> UnixTime -> UnixTime
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 :: UnixTime -> UnixTime -> Ordering
compare :: UnixTime -> UnixTime -> Ordering
$c< :: UnixTime -> UnixTime -> Bool
< :: UnixTime -> UnixTime -> Bool
$c<= :: UnixTime -> UnixTime -> Bool
<= :: UnixTime -> UnixTime -> Bool
$c> :: UnixTime -> UnixTime -> Bool
> :: UnixTime -> UnixTime -> Bool
$c>= :: UnixTime -> UnixTime -> Bool
>= :: UnixTime -> UnixTime -> Bool
$cmax :: UnixTime -> UnixTime -> UnixTime
max :: UnixTime -> UnixTime -> UnixTime
$cmin :: UnixTime -> UnixTime -> UnixTime
min :: UnixTime -> UnixTime -> UnixTime
Ord,Int -> UnixTime -> ShowS
[UnixTime] -> ShowS
UnixTime -> String
(Int -> UnixTime -> ShowS)
-> (UnixTime -> String) -> ([UnixTime] -> ShowS) -> Show UnixTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnixTime -> ShowS
showsPrec :: Int -> UnixTime -> ShowS
$cshow :: UnixTime -> String
show :: UnixTime -> String
$cshowList :: [UnixTime] -> ShowS
showList :: [UnixTime] -> ShowS
Show,(forall x. UnixTime -> Rep UnixTime x)
-> (forall x. Rep UnixTime x -> UnixTime) -> Generic UnixTime
forall x. Rep UnixTime x -> UnixTime
forall x. UnixTime -> Rep UnixTime x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UnixTime -> Rep UnixTime x
from :: forall x. UnixTime -> Rep UnixTime x
$cto :: forall x. Rep UnixTime x -> UnixTime
to :: forall x. Rep UnixTime x -> UnixTime
Generic)

instance Storable UnixTime where
    sizeOf :: UnixTime -> Int
sizeOf UnixTime
_    = ((Int
16))
{-# LINE 42 "Data/UnixTime/Types.hsc" #-}
    alignment _ = (8)
{-# LINE 43 "Data/UnixTime/Types.hsc" #-}

{-# LINE 67 "Data/UnixTime/Types.hsc" #-}
    peek :: Ptr UnixTime -> IO UnixTime
peek Ptr UnixTime
ptr    = CTime -> Int32 -> UnixTime
UnixTime
            (CTime -> Int32 -> UnixTime) -> IO CTime -> IO (Int32 -> UnixTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((\Ptr UnixTime
hsc_ptr -> Ptr UnixTime -> Int -> IO CTime
forall b. Ptr b -> Int -> IO CTime
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr UnixTime
hsc_ptr Int
0))  Ptr UnixTime
ptr
{-# LINE 69 "Data/UnixTime/Types.hsc" #-}
            IO (Int32 -> UnixTime) -> IO Int32 -> IO UnixTime
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((\Ptr UnixTime
hsc_ptr -> Ptr UnixTime -> Int -> IO Int32
forall b. Ptr b -> Int -> IO Int32
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr UnixTime
hsc_ptr Int
8)) Ptr UnixTime
ptr
{-# LINE 70 "Data/UnixTime/Types.hsc" #-}
    poke ptr ut = do
            ((\hsc_ptr -> pokeByteOff hsc_ptr 0))  ptr (utSeconds ut)
{-# LINE 72 "Data/UnixTime/Types.hsc" #-}
            ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr (utMicroSeconds ut)
{-# LINE 73 "Data/UnixTime/Types.hsc" #-}

{-# LINE 74 "Data/UnixTime/Types.hsc" #-}


{-# LINE 76 "Data/UnixTime/Types.hsc" #-}
instance Binary UnixTime where
        put (UnixTime (CTime sec) msec) = do
            put sec
            put msec
        get = UnixTime <$> (CTime `fmap` get) <*> get

{-# LINE 82 "Data/UnixTime/Types.hsc" #-}

-- |
-- Format of the strptime()/strftime() style.
type Format = ByteString

-- |
-- Data structure for UnixTime diff.
--
-- It is up to the user to ensure that @'udtMicroSeconds' < 1000000@.
-- Helpers such as 'Data.UnixTime.microSecondsToUnixDiffTime' can help
-- you to create valid values. For example, it's a mistake to use
-- 'Data.Text.addUnixDiffTime' with a value @UnixDiffTime 0 9999999@
-- as it will produce an incorrect value back. You should instead use
-- functions such as 'Data.UnixTime.microSecondsToUnixDiffTime' to
-- create values that are in-range. This avoids any gotchas when then
-- doing comparisons.
data UnixDiffTime = UnixDiffTime {
    -- | Seconds
    UnixDiffTime -> CTime
udtSeconds :: {-# UNPACK #-} !CTime
    -- | Micro seconds (i.e. 10^(-6))
  , UnixDiffTime -> Int32
udtMicroSeconds :: {-# UNPACK #-} !Int32
  } deriving (UnixDiffTime -> UnixDiffTime -> Bool
(UnixDiffTime -> UnixDiffTime -> Bool)
-> (UnixDiffTime -> UnixDiffTime -> Bool) -> Eq UnixDiffTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnixDiffTime -> UnixDiffTime -> Bool
== :: UnixDiffTime -> UnixDiffTime -> Bool
$c/= :: UnixDiffTime -> UnixDiffTime -> Bool
/= :: UnixDiffTime -> UnixDiffTime -> Bool
Eq,Eq UnixDiffTime
Eq UnixDiffTime =>
(UnixDiffTime -> UnixDiffTime -> Ordering)
-> (UnixDiffTime -> UnixDiffTime -> Bool)
-> (UnixDiffTime -> UnixDiffTime -> Bool)
-> (UnixDiffTime -> UnixDiffTime -> Bool)
-> (UnixDiffTime -> UnixDiffTime -> Bool)
-> (UnixDiffTime -> UnixDiffTime -> UnixDiffTime)
-> (UnixDiffTime -> UnixDiffTime -> UnixDiffTime)
-> Ord UnixDiffTime
UnixDiffTime -> UnixDiffTime -> Bool
UnixDiffTime -> UnixDiffTime -> Ordering
UnixDiffTime -> UnixDiffTime -> UnixDiffTime
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 :: UnixDiffTime -> UnixDiffTime -> Ordering
compare :: UnixDiffTime -> UnixDiffTime -> Ordering
$c< :: UnixDiffTime -> UnixDiffTime -> Bool
< :: UnixDiffTime -> UnixDiffTime -> Bool
$c<= :: UnixDiffTime -> UnixDiffTime -> Bool
<= :: UnixDiffTime -> UnixDiffTime -> Bool
$c> :: UnixDiffTime -> UnixDiffTime -> Bool
> :: UnixDiffTime -> UnixDiffTime -> Bool
$c>= :: UnixDiffTime -> UnixDiffTime -> Bool
>= :: UnixDiffTime -> UnixDiffTime -> Bool
$cmax :: UnixDiffTime -> UnixDiffTime -> UnixDiffTime
max :: UnixDiffTime -> UnixDiffTime -> UnixDiffTime
$cmin :: UnixDiffTime -> UnixDiffTime -> UnixDiffTime
min :: UnixDiffTime -> UnixDiffTime -> UnixDiffTime
Ord,Int -> UnixDiffTime -> ShowS
[UnixDiffTime] -> ShowS
UnixDiffTime -> String
(Int -> UnixDiffTime -> ShowS)
-> (UnixDiffTime -> String)
-> ([UnixDiffTime] -> ShowS)
-> Show UnixDiffTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnixDiffTime -> ShowS
showsPrec :: Int -> UnixDiffTime -> ShowS
$cshow :: UnixDiffTime -> String
show :: UnixDiffTime -> String
$cshowList :: [UnixDiffTime] -> ShowS
showList :: [UnixDiffTime] -> ShowS
Show)