-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Unix time parser/formatter and utilities
--   
--   Fast parser/formatter/utilities for Unix time
@package unix-time
@version 0.1.8

module Data.UnixTime

-- | Data structure for Unix time.
data UnixTime
UnixTime :: {-# UNPACK #-} !CTime -> {-# UNPACK #-} !Int32 -> UnixTime

-- | Seconds from 1st Jan 1970
utSeconds :: UnixTime -> {-# UNPACK #-} !CTime

-- | Micro seconds (i.e. 10^(-6))
utMicroSeconds :: UnixTime -> {-# UNPACK #-} !Int32

-- | Getting <a>UnixTime</a> from OS.
getUnixTime :: IO UnixTime

-- | Parsing <a>ByteString</a> to <a>UnixTime</a> interpreting as
--   localtime. This is a wrapper for strptime_l(). Many implementations of
--   strptime_l() do not support %Z and some implementations of
--   strptime_l() do not support %z, either.
parseUnixTime :: Format -> ByteString -> UnixTime

-- | Parsing <a>ByteString</a> to <a>UnixTime</a> interpreting as GMT. This
--   is a wrapper for strptime_l().
--   
--   <pre>
--   &gt;&gt;&gt; parseUnixTimeGMT webDateFormat "Thu, 01 Jan 1970 00:00:00 GMT"
--   UnixTime {utSeconds = 0, utMicroSeconds = 0}
--   </pre>
parseUnixTimeGMT :: Format -> ByteString -> UnixTime

-- | Formatting <a>UnixTime</a> to <a>ByteString</a> in local time. This is
--   a wrapper for strftime_l().
formatUnixTime :: Format -> UnixTime -> ByteString

-- | Formatting <a>UnixTime</a> to <a>ByteString</a> in GMT. This is a
--   wrapper for strftime_l().
--   
--   <pre>
--   &gt;&gt;&gt; formatUnixTimeGMT webDateFormat $ UnixTime 0 0
--   "Thu, 01 Jan 1970 00:00:00 GMT"
--   </pre>
formatUnixTimeGMT :: Format -> UnixTime -> ByteString

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

-- | Format for web (RFC 2616). The value is "%a, %d %b %Y %H:%M:%S GMT".
--   This should be used with <a>formatUnixTimeGMT</a> and
--   <a>parseUnixTimeGMT</a>.
webDateFormat :: Format

-- | Format for e-mail (RFC 5322). The value is "%a, %d %b %Y %H:%M:%S %z".
--   This should be used with <a>formatUnixTime</a> and
--   <a>parseUnixTime</a>.
mailDateFormat :: Format

-- | Data structure for UnixTime diff.
--   
--   <pre>
--   &gt;&gt;&gt; (3 :: UnixDiffTime) + 2
--   UnixDiffTime {udtSeconds = 5, udtMicroSecnods = 0}
--   
--   &gt;&gt;&gt; (2 :: UnixDiffTime) - 5
--   UnixDiffTime {udtSeconds = -3, udtMicroSecnods = 0}
--   
--   &gt;&gt;&gt; (3 :: UnixDiffTime) * 2
--   UnixDiffTime {udtSeconds = 6, udtMicroSecnods = 0}
--   </pre>
data UnixDiffTime
UnixDiffTime :: {-# UNPACK #-} !CTime -> {-# UNPACK #-} !Int32 -> UnixDiffTime

-- | Seconds from 1st Jan 1970
udtSeconds :: UnixDiffTime -> {-# UNPACK #-} !CTime

-- | Micro seconds (i.e. 10^(-6))
udtMicroSecnods :: UnixDiffTime -> {-# UNPACK #-} !Int32

-- | Calculating difference between two <a>UnixTime</a>.
--   
--   <pre>
--   &gt;&gt;&gt; UnixTime 100 2000 `diffUnixTime` UnixTime 98 2100
--   UnixDiffTime {udtSeconds = 1, udtMicroSecnods = 999900}
--   </pre>
diffUnixTime :: UnixTime -> UnixTime -> UnixDiffTime

-- | Adding difference to <a>UnixTime</a>.
--   
--   <pre>
--   &gt;&gt;&gt; UnixTime 100 2000 `addUnixDiffTime` microSecondsToUnixDiffTime (-1003000)
--   UnixTime {utSeconds = 98, utMicroSeconds = 999000}
--   </pre>
addUnixDiffTime :: UnixTime -> UnixDiffTime -> UnixTime

-- | Creating difference from seconds.
--   
--   <pre>
--   &gt;&gt;&gt; secondsToUnixDiffTime 100
--   UnixDiffTime {udtSeconds = 100, udtMicroSecnods = 0}
--   </pre>
secondsToUnixDiffTime :: Integral a => a -> UnixDiffTime

-- | Creating difference from micro seconds.
--   
--   <pre>
--   &gt;&gt;&gt; microSecondsToUnixDiffTime 12345678
--   UnixDiffTime {udtSeconds = 12, udtMicroSecnods = 345678}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; microSecondsToUnixDiffTime (-12345678)
--   UnixDiffTime {udtSeconds = -12, udtMicroSecnods = -345678}
--   </pre>
microSecondsToUnixDiffTime :: Integral a => a -> UnixDiffTime

-- | From <a>EpochTime</a> to <a>UnixTime</a> setting <a>utMicroSeconds</a>
--   to 0.
fromEpochTime :: EpochTime -> UnixTime

-- | From <a>UnixTime</a> to <a>EpochTime</a> ignoring
--   <a>utMicroSeconds</a>.
toEpochTime :: UnixTime -> EpochTime

-- | From <a>ClockTime</a> to <a>UnixTime</a>.
fromClockTime :: ClockTime -> UnixTime

-- | From <a>UnixTime</a> to <a>ClockTime</a>.
toClockTime :: UnixTime -> ClockTime
