Convert string to UTCTime type

I am writing a getSitemapR handler that uses the yesod-sitemap file to create a sitemap. The problem I am having is converting String to UTCTime as defined in Data.Time.Clock . The haddock documentation says that UTCTime is an instance of the Read class, so I'm trying. Here is 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 looked at my copy of Real World Haskell in chapter 20 on system programming, but does not cover UTCTime in it with code samples, I searched google with the term haskell Convert a String to UTCTime "without any results. I found the following Thread on the haskell mailing list- cafe, which will not work because SitemapLastMod does not accept Maybe UTCTime , I think I'm making a really stupid mistake here, but I'm not sure if anyone could point me in the right direction?

Thank you for your time and attention.

+6
source share
1 answer
 , sitemapLastMod = (read "2011-11-19 18:28:r52.607875 UTC")::UTCTime 

Lowercase r should not be there. Try

 , sitemapLastMod = (read "2011-11-19 18:28:52.607875 UTC")::UTCTime 
+7
source

Source: https://habr.com/ru/post/901956/


All Articles