[英]Yesod Persistent - How to compare Day to UTCTime? (How to convert them?)
[英]Yesod: How to give UTCTime a toMarkup instance?
我在模型中有這個Haskell數據:
Vocabulary json
word Text
date UTCTime
deriving Show
我收到以下代碼錯誤:
getHomeR :: Handler Html
getHomeR = do
wordList <- runDB $ selectList [] [] :: HandlerT App IO [Entity Vocabulary]
defaultLayout $ do
setTitle "test"
[whamlet|
<ul>
$forall Entity wordid worditem <- wordList
<li>#{vocabularyDate worditem}
|]
錯誤是:
Could not deduce (blaze-markup-0.7.1.1:Text.Blaze.
ToMarkup
UTCTime)
arising from a use of ‘toHtml’
from the context: PersistEntity Vocabulary
我從這篇文章中讀到,我應該聲明UTCTime為ToMarkup的實例。 我應該如何以及在哪個文件中執行此操作?
我想你可以做類似的事情
import Data.Time.Format
getHomeR :: Handler Html
getHomeR = do
wordList <- runDB $ selectList [] [] :: HandlerT App IO [Entity Vocabulary]
defaultLayout $ do
setTitle "test"
[whamlet|
<ul>
$forall Entity wordid worditem <- wordList
<li>#{dateFormat $ vocabularyDate worditem}
|]
dateFormat :: UTCTime -> String
dateFormat = formatTime defaultTimeLocale "%F"
我對小村庄模板不太熟悉,因此您可能需要稍微調整一下此代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.