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