{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module System.Log.FastLogger.Date
(
newTimeCache
, simpleTimeFormat
, simpleTimeFormat'
) where
import Control.AutoUpdate (mkAutoUpdate, defaultUpdateSettings, updateAction)
import System.Log.FastLogger.Types (TimeFormat, FormattedTime)
import Data.UnixTime (formatUnixTime, fromEpochTime)
import System.PosixCompat.Types (EpochTime)
import System.PosixCompat.Time (epochTime)
getTime :: IO EpochTime
getTime = epochTime
formatDate :: TimeFormat -> EpochTime -> IO FormattedTime
formatDate fmt = formatUnixTime fmt . fromEpochTime
newTimeCache :: TimeFormat -> IO (IO FormattedTime)
newTimeCache fmt = mkAutoUpdate defaultUpdateSettings{
updateAction = getTime >>= formatDate fmt
}
simpleTimeFormat :: TimeFormat
simpleTimeFormat = "%d/%b/%Y:%T %z"
simpleTimeFormat' :: TimeFormat
simpleTimeFormat' = "%d-%b-%Y %T"