Commits

Luke Plant committed 2d16c4c

Pulled out 'getTimestamp' function

Comments (0)

Files changed (2)

src/Blog/Forms.hs

 where
 
 import Blog.Formats (Format(..), getFormatter)
+import Blog.Utils (getTimestamp)
 import Control.Monad (liftM)
 import Data.Maybe (fromJust)
 import Ella.Forms.Widgets.TextInput (TextInput(..))
 import Ella.Forms.Widgets.Textarea  (Textarea(..))
 import Ella.GenUtils (exactParse)
 import Ella.Param (captureOrDefault, Param(..))
-import System.Posix.Time (epochTime)
-import System.Posix.Types
 import qualified Blog.Comment as Cm
 import qualified Blog.Post as P
 import qualified Data.Map as Map
     --             submit or if timedelta less than 10 seconds,
     --             emit validation error.
 
-      ts <- epochTime
+      ts <- getTimestamp
       let text = postedData "message" `captureOrDefault` ""
       let name = postedData "name" `captureOrDefault` ""
       let email = postedData "email" `captureOrDefault` ""
       return (Cm.Comment {
                       uid = undefined
                     , post_id = P.uid blogpost
-                    , timestamp = floor $ toRational ts
+                    , timestamp = ts
                     , name = name
                     , email = email
                     , text_raw = text

src/Blog/Utils.hs

 module Blog.Utils where
 
 import Data.Char
+import Control.Monad (liftM)
 import System.Environment(getArgs)
+import System.Posix.Time (epochTime)
+import System.Posix.Types
 import Text.Regex.Base
 import Text.Regex.PCRE
 import qualified Data.ByteString.Lazy.Char8 as BL
    | otherwise = (c : head rest) : tail rest
    where
        rest = split cs delim
+
+-- | Return current time as a UNIX timestamp
+getTimestamp :: IO Int
+getTimestamp = liftM (floor . toRational) epochTime