module System.Logger.Internal
( sshow
, formatIso8601
, formatIso8601Milli
, formatIso8601Micro
, timeSpecToUtc
) where
#ifndef MIN_VERSION_time
#define MIN_VERSION_time(a,b,c) 1
#endif
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
#if !MIN_VERSION_time(1,5,0)
import System.Locale (defaultTimeLocale)
#endif
sshow
∷ (Show a, IsString b)
⇒ a
→ b
sshow = fromString ∘ show
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)