{-# LANGUAGE CPP #-}
{-# LANGUAGE UnicodeSyntax #-}
module System.Logger.Internal
( sshow
, formatIso8601
, formatIso8601Milli
, formatIso8601Micro
, timeSpecToUtc
) where
import Data.Monoid.Unicode
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Data.Time.Format
import Data.String
import Numeric.Natural
import Prelude.Unicode
import System.Clock
sshow
∷ (Show a, IsString b)
⇒ a
→ b
sshow = fromString ∘ show
{-# INLINE sshow #-}
formatIso8601Micro
∷ IsString a
⇒ TimeSpec
→ a
formatIso8601Micro = formatIso8601 6
formatIso8601Milli
∷ IsString a
⇒ TimeSpec
→ a
formatIso8601Milli = formatIso8601 3
formatIso8601
∷ IsString a
⇒ Natural
→ TimeSpec
→ a
formatIso8601 precision
= fromString
∘ (⊕ "Z")
∘ take (fromIntegral $ 20 + precision)
∘ (⊕ replicate (fromIntegral precision) '0')
∘ formatTime defaultTimeLocale ("%Y-%m-%dT%H:%M:%S%Q")
∘ timeSpecToUtc
timeSpecToUtc
∷ TimeSpec
→ UTCTime
timeSpecToUtc (TimeSpec s ns) =
posixSecondsToUTCTime (realToFrac s + realToFrac ns * 1e-9)