-- |
-- Module      : Network.Pusher.Internal.Util
-- Description : Various utility functions
-- Copyright   : (c) Will Sewell, 2016
-- Licence     : MIT
-- Maintainer  : me@willsewell.com
-- Stability   : stable
module Network.Pusher.Internal.Util
  ( show',
    getSystemTimeSeconds,
  )
where

import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.String (IsString, fromString)
import Data.Time.Clock.System (SystemTime (systemSeconds), getSystemTime)
import Data.Word (Word64)

-- | Generalised version of show.
show' :: (Show a, IsString b) => a -> b
show' :: a -> b
show' = String -> b
forall a. IsString a => String -> a
fromString (String -> b) -> (a -> String) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show

getSystemTimeSeconds :: MonadIO m => m Word64
getSystemTimeSeconds :: m Word64
getSystemTimeSeconds = do
  SystemTime
t <- IO SystemTime -> m SystemTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO SystemTime
getSystemTime
  Word64 -> m Word64
forall (m :: * -> *) a. Monad m => a -> m a
return (Word64 -> m Word64) -> Word64 -> m Word64
forall a b. (a -> b) -> a -> b
$ Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word64) -> Int64 -> Word64
forall a b. (a -> b) -> a -> b
$ SystemTime -> Int64
systemSeconds SystemTime
t