I'm writing a getSitemapR
handler that uses yesod-sitemap to generate a sitemap file. The issue I'm having is converting a String
into UTCTime
as defined in Data.Time.Clock
. The haddock documentation says that UTCTime
is an instance of the Read
typeclass, so that's what I'm trying. Here's my code.
module Handler.Root where
import Import
import Yesod.Goodies.Gravatar
import Data.Time.Format
import System.Locale
-- This is a handler function for the GET request method on the RootR
-- resource pattern. All of your resource patterns are defined in
-- config/routes
--
-- The majority of the code you will write in Yesod lives in these handler
-- functions. You can spread them across multiple files if you are so
-- inclined, or create a single monolithic file.
getRootR :: Handler RepHtml
getRootR = do
defaultLayout $ do
h2id <- lift newIdent
setTitle "Cloudrr homepage"
$(widgetFile "homepage")
gravatar :: Text -> String
gravatar email =
gravatarImg email go
where
go = GravatarOptions {
gSize = Just (Size 140)
, gDefault = Just (Identicon)
, gForceDefault = ForceDefault False
, gRating = Just (PG)
}
getSitemapR :: Handler RepXml
getSitemapR = do
sitemap [smo RootR]
where
smo = SitemapUrl SitemapR{
sitemapLoc = "http://www.cloudrr.me/sitemap.xml"
, sitemapLastMod = (read "2011-11-19 18:28:r52.607875 UTC")::UTCTime
, sitemapChangeFreq = Weekly
, priority = 0.7
}
I've looked through my copy of Real World Haskell in chapter 20 on systems programming, but it doesn't cover UTCTime
in it's code samples, I've searched google with the term 'haskell "Convert a String to UTCTime"' with no results. I found the following Thread in the haskell-cafe mailing list which won't work because SitemapLastMod
doesn't take a Maybe UTCTime
. I think I'm making a really stupid mistake here, but I'm not sure, could someone please point me in the right direction?
Thank you for your time and consideration.
, sitemapLastMod = (read "2011-11-19 18:28:r52.607875 UTC")::UTCTime
The lower case r
should not be there. Try
, sitemapLastMod = (read "2011-11-19 18:28:52.607875 UTC")::UTCTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With