Search code examples
haskelltimehaskell-snap-framework

Snap interface - getting the Time


I am using the Snap interface and I am wondering if there is a function ':: Request -> Time'. (Or CTime).

I would like to get the time when someone visits the webpage.


Solution

  • Request does not have any time in it (you can check this from source).

    But you can get current time while handling request:

    import Data.Time.Clock (getCurrentTime)
    import Data.Time.Format
    import qualified Data.Text as T
    
    someHandler :: Handler App App ()
    someHandler = do
      utcTime <- liftIO getCurentTime
      writeText $ T.pack $ formatTime undefined "%F %T" utcTime